@renovatebot/osv-offline-db 4.4.0 → 4.5.0
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/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/lib/db-index.js +2 -7
- package/dist/lib/db.js +17 -17
- package/dist/lib/logger.d.ts +8 -0
- package/dist/lib/logger.js +36 -0
- package/package.json +9 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { OsvOfflineDb } from './lib/db.ts';
|
|
2
|
-
export { DatabaseIndexBuilder, type DatabaseRecord, getIndexFileName
|
|
2
|
+
export { DatabaseIndexBuilder, type DatabaseRecord, getIndexFileName } from './lib/db-index.ts';
|
|
3
3
|
export { Ecosystem, ecosystems } from './lib/ecosystem.ts';
|
|
4
|
+
export { createLogger } from './lib/logger.ts';
|
|
4
5
|
export { type SplitEcosystem, type SplitFile, type SplitIndex, getSplitFileName, parseSplitIndex, splitIndexSchema, } from './lib/split-index.ts';
|
|
5
6
|
export * as Osv from './lib/osv.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { OsvOfflineDb } from "./lib/db.js";
|
|
2
|
-
export { DatabaseIndexBuilder, getIndexFileName
|
|
2
|
+
export { DatabaseIndexBuilder, getIndexFileName } from "./lib/db-index.js";
|
|
3
3
|
export { ecosystems } from "./lib/ecosystem.js";
|
|
4
|
+
export { createLogger } from "./lib/logger.js";
|
|
4
5
|
export { getSplitFileName, parseSplitIndex, splitIndexSchema, } from "./lib/split-index.js";
|
|
5
6
|
export * as Osv from "./lib/osv.js";
|
package/dist/lib/db-index.js
CHANGED
|
@@ -41,10 +41,7 @@ export class DatabaseIndexBuilder {
|
|
|
41
41
|
...(this.last && { last: this.last }),
|
|
42
42
|
packages: Object.fromEntries(Array.from(this.index, ([name, pointers]) => [
|
|
43
43
|
name,
|
|
44
|
-
pointers.map(({ offset, length }) => [
|
|
45
|
-
offset,
|
|
46
|
-
length,
|
|
47
|
-
]),
|
|
44
|
+
pointers.map(({ offset, length }) => [offset, length]),
|
|
48
45
|
])),
|
|
49
46
|
};
|
|
50
47
|
return JSON.stringify(file);
|
|
@@ -63,9 +60,7 @@ export function parseIndex(content, size) {
|
|
|
63
60
|
catch {
|
|
64
61
|
return null;
|
|
65
62
|
}
|
|
66
|
-
if (file?.size !== size ||
|
|
67
|
-
typeof file.packages !== 'object' ||
|
|
68
|
-
file.packages === null) {
|
|
63
|
+
if (file?.size !== size || typeof file.packages !== 'object' || file.packages === null) {
|
|
69
64
|
return null;
|
|
70
65
|
}
|
|
71
66
|
const index = new Map(Object.entries(file.packages).map(([name, pointers]) => [
|
package/dist/lib/db.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { readFile, stat } from 'node:fs/promises';
|
|
2
1
|
import { closeSync, createReadStream, read as fsRead, openSync } from 'node:fs';
|
|
3
|
-
import {
|
|
4
|
-
import path from 'node:path';
|
|
2
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
5
3
|
import { tmpdir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
6
5
|
import readline from 'node:readline';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
7
|
import { DatabaseIndexBuilder, getIndexFileName, parseIndex, } from "./db-index.js";
|
|
8
|
+
import { createLogger } from "./logger.js";
|
|
8
9
|
import { packageToPurl } from "./purl-helper.js";
|
|
9
|
-
|
|
10
|
-
const logger = debug('osv-offline:db');
|
|
10
|
+
const logger = createLogger('osv-offline:db');
|
|
11
11
|
const readAsync = promisify(fsRead);
|
|
12
12
|
export class OsvOfflineDb {
|
|
13
13
|
disposed = false;
|
|
@@ -19,7 +19,7 @@ export class OsvOfflineDb {
|
|
|
19
19
|
if (this.disposed) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
logger('Databases are not disposed! Please explicitly dispose.');
|
|
22
|
+
logger.warn('Databases are not disposed! Please explicitly dispose.');
|
|
23
23
|
this[Symbol.dispose]();
|
|
24
24
|
};
|
|
25
25
|
constructor() {
|
|
@@ -35,7 +35,7 @@ export class OsvOfflineDb {
|
|
|
35
35
|
return (this._db[ecosystem] ??= this._init(ecosystem));
|
|
36
36
|
}
|
|
37
37
|
if (fileStat?.mtimeMs !== cached.mtime) {
|
|
38
|
-
logger(fileStat
|
|
38
|
+
logger.debug(fileStat
|
|
39
39
|
? `File changed for ecosystem '${ecosystem}', reloading ...`
|
|
40
40
|
: `File removed for ecosystem '${ecosystem}', unloading ...`);
|
|
41
41
|
// Delete references before unloading to prevent concurrent callers from picking up stale data
|
|
@@ -47,14 +47,14 @@ export class OsvOfflineDb {
|
|
|
47
47
|
return (this._db[ecosystem] ??= this._init(ecosystem));
|
|
48
48
|
}
|
|
49
49
|
async _init(ecosystem) {
|
|
50
|
-
logger(`Initializing ecosystem '${ecosystem}' ...`);
|
|
50
|
+
logger.trace(`Initializing ecosystem '${ecosystem}' ...`);
|
|
51
51
|
const ac = new AbortController();
|
|
52
52
|
this._pendingAcs.add(ac);
|
|
53
53
|
try {
|
|
54
54
|
const filePath = path.join(OsvOfflineDb.rootDirectory, `${ecosystem.toLowerCase()}.nedb`);
|
|
55
55
|
const fileStat = await stat(filePath).catch(() => null);
|
|
56
56
|
if (!fileStat) {
|
|
57
|
-
logger(`Missing data for ecosystem '${ecosystem}'`);
|
|
57
|
+
logger.debug(`Missing data for ecosystem '${ecosystem}'`);
|
|
58
58
|
delete this._db[ecosystem];
|
|
59
59
|
return null;
|
|
60
60
|
}
|
|
@@ -66,20 +66,20 @@ export class OsvOfflineDb {
|
|
|
66
66
|
};
|
|
67
67
|
const index = await this._loadIndex(ecosystem, data, fileStat.size);
|
|
68
68
|
if (index) {
|
|
69
|
-
logger(`Using precomputed index for ecosystem '${ecosystem}'`);
|
|
69
|
+
logger.trace(`Using precomputed index for ecosystem '${ecosystem}'`);
|
|
70
70
|
data.index = index;
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
73
|
await this._buildIndex(ac, data);
|
|
74
74
|
}
|
|
75
75
|
if (ac.signal.aborted) {
|
|
76
|
-
logger(`Initializing ecosystem '${ecosystem}' aborted.`);
|
|
76
|
+
logger.debug(`Initializing ecosystem '${ecosystem}' aborted.`);
|
|
77
77
|
delete this._db[ecosystem];
|
|
78
78
|
this._unload(data);
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
81
|
this._data[ecosystem] = data;
|
|
82
|
-
logger(`Initializing ecosystem '${ecosystem}' done.`);
|
|
82
|
+
logger.trace(`Initializing ecosystem '${ecosystem}' done.`);
|
|
83
83
|
return data;
|
|
84
84
|
}
|
|
85
85
|
finally {
|
|
@@ -96,7 +96,7 @@ export class OsvOfflineDb {
|
|
|
96
96
|
}
|
|
97
97
|
const parsed = parseIndex(content, size);
|
|
98
98
|
if (!parsed || !(await this._isLastRecord(data, parsed.last))) {
|
|
99
|
-
logger(`Ignoring outdated index for ecosystem '${ecosystem}'`);
|
|
99
|
+
logger.debug(`Ignoring outdated index for ecosystem '${ecosystem}'`);
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
102
|
return parsed.index;
|
|
@@ -156,19 +156,19 @@ export class OsvOfflineDb {
|
|
|
156
156
|
return [];
|
|
157
157
|
}
|
|
158
158
|
const advisories = await Promise.all(pointers.map((pointer) => this._readRecord(data, pointer)));
|
|
159
|
-
if (this.disposed)
|
|
159
|
+
if (this.disposed) {
|
|
160
160
|
return [];
|
|
161
|
+
}
|
|
161
162
|
const targetPurl = packageToPurl(ecosystem, packageName);
|
|
162
163
|
return advisories.filter((vuln) => vuln.affected?.some((a) => a.package?.name === packageName &&
|
|
163
|
-
(a.package.ecosystem === ecosystem ||
|
|
164
|
-
a.package.ecosystem.startsWith(`${ecosystem}:`)) &&
|
|
164
|
+
(a.package.ecosystem === ecosystem || a.package.ecosystem.startsWith(`${ecosystem}:`)) &&
|
|
165
165
|
a.package.purl === targetPurl));
|
|
166
166
|
}
|
|
167
167
|
[Symbol.dispose]() {
|
|
168
168
|
if (this.disposed) {
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
-
logger(`Disposing databases ...`);
|
|
171
|
+
logger.trace(`Disposing databases ...`);
|
|
172
172
|
this.disposed = true;
|
|
173
173
|
process.off('exit', this._exitHandler);
|
|
174
174
|
for (const ac of this._pendingAcs) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Logger } from '@containerbase/base';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a logger which logs to the logger set by `configure` of `@containerbase/base` with messages prefixed by
|
|
4
|
+
* `OSV:`, or to `debug` with the given namespace when none is set.
|
|
5
|
+
*
|
|
6
|
+
* @param namespace the `debug` namespace
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLogger(namespace: string): Logger;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getLogger, isConfigured } from '@containerbase/base';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
/** Prefixes the messages to the configured logger, eg. for Renovate's `logLevelRemap`. */
|
|
4
|
+
const prefix = 'OSV:';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a logger which logs to the logger set by `configure` of `@containerbase/base` with messages prefixed by
|
|
7
|
+
* `OSV:`, or to `debug` with the given namespace when none is set.
|
|
8
|
+
*
|
|
9
|
+
* @param namespace the `debug` namespace
|
|
10
|
+
*/
|
|
11
|
+
export function createLogger(namespace) {
|
|
12
|
+
const fallback = debug(namespace);
|
|
13
|
+
const log = (level) => (metaOrMsg, msg) => {
|
|
14
|
+
if (typeof metaOrMsg === 'string') {
|
|
15
|
+
if (isConfigured()) {
|
|
16
|
+
getLogger()[level](`${prefix} ${metaOrMsg}`);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
fallback(metaOrMsg);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if (isConfigured()) {
|
|
23
|
+
getLogger()[level](metaOrMsg, msg === undefined ? prefix : `${prefix} ${msg}`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
fallback('%s %O', msg ?? '', metaOrMsg);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
trace: log('trace'),
|
|
31
|
+
debug: log('debug'),
|
|
32
|
+
info: log('info'),
|
|
33
|
+
warn: log('warn'),
|
|
34
|
+
error: log('error'),
|
|
35
|
+
};
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renovatebot/osv-offline-db",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"main": "dist/index.js",
|
|
3
|
+
"version": "4.5.0",
|
|
5
4
|
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
5
|
"repository": {
|
|
11
6
|
"type": "git",
|
|
12
7
|
"url": "https://github.com/renovatebot/osv-offline.git"
|
|
13
8
|
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@containerbase/base": "^14.58.0",
|
|
15
16
|
"debug": "^4.4.3"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
"@types/debug": "4.1.13",
|
|
21
22
|
"@types/fs-extra": "11.0.4",
|
|
22
23
|
"@types/node": "24.19.2",
|
|
23
|
-
"fs-extra": "11.4.1"
|
|
24
|
+
"fs-extra": "11.4.1",
|
|
25
|
+
"vitest": "4.1.12"
|
|
24
26
|
},
|
|
25
27
|
"engines": {
|
|
26
28
|
"node": ">=24.11.0",
|