@renovatebot/osv-offline-db 2.0.0 → 2.1.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/lib/db.d.ts CHANGED
@@ -4,7 +4,8 @@ export declare class OsvOfflineDb {
4
4
  static readonly rootDirectory: string;
5
5
  private db;
6
6
  private constructor();
7
- private initialize;
8
- static create(): Promise<OsvOfflineDb>;
7
+ private _load;
8
+ private _init;
9
+ static create(): OsvOfflineDb;
9
10
  query(ecosystem: Ecosystem, packageName: string): Promise<Osv.Vulnerability[]>;
10
11
  }
package/dist/lib/db.js CHANGED
@@ -9,26 +9,33 @@ const path_1 = __importDefault(require("path"));
9
9
  const nedb_1 = __importDefault(require("@seald-io/nedb"));
10
10
  const ecosystem_1 = require("./ecosystem");
11
11
  const purl_helper_1 = require("./purl-helper");
12
+ const debug_1 = __importDefault(require("debug"));
13
+ const logger = (0, debug_1.default)('osv-offline:db');
12
14
  class OsvOfflineDb {
13
15
  static rootDirectory = process.env.OSV_OFFLINE_ROOT_DIR ?? path_1.default.join((0, os_1.tmpdir)(), 'osv-offline');
14
16
  db = {};
15
17
  // eslint-disable-next-line @typescript-eslint/no-empty-function
16
18
  constructor() { }
17
- async initialize() {
18
- for (const ecosystem of ecosystem_1.ecosystems) {
19
- this.db[ecosystem] = new nedb_1.default({
20
- filename: path_1.default.join(OsvOfflineDb.rootDirectory, `${ecosystem.toLowerCase()}.nedb`),
21
- });
22
- await this.db[ecosystem].loadDatabaseAsync();
19
+ _load(ecosystem) {
20
+ return (this.db[ecosystem] ??= this._init(ecosystem));
21
+ }
22
+ async _init(ecosystem) {
23
+ if (!ecosystem_1.ecosystems.includes(ecosystem)) {
24
+ throw new Error(`Ecosystem not supported`);
23
25
  }
26
+ logger(`Initializing database for ecosystem: ${ecosystem}`);
27
+ const db = new nedb_1.default({
28
+ filename: path_1.default.join(OsvOfflineDb.rootDirectory, `${ecosystem.toLowerCase()}.nedb`),
29
+ });
30
+ await db.loadDatabaseAsync();
31
+ return db;
24
32
  }
25
- static async create() {
33
+ static create() {
26
34
  const osvOfflineDb = new OsvOfflineDb();
27
- await osvOfflineDb.initialize();
28
35
  return osvOfflineDb;
29
36
  }
30
37
  async query(ecosystem, packageName) {
31
- return await this.db[ecosystem].findAsync({
38
+ return await (await this._load(ecosystem)).findAsync({
32
39
  affected: {
33
40
  $elemMatch: {
34
41
  package: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renovatebot/osv-offline-db",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
@@ -13,14 +13,16 @@
13
13
  "url": "https://github.com/renovatebot/osv-offline.git"
14
14
  },
15
15
  "dependencies": {
16
- "@seald-io/nedb": "^4.1.2"
16
+ "@seald-io/nedb": "^4.1.2",
17
+ "debug": "^4.4.3"
17
18
  },
18
19
  "devDependencies": {
19
- "@tsconfig/node22": "22.0.4",
20
- "@tsconfig/strictest": "2.0.7",
20
+ "@tsconfig/node22": "22.0.5",
21
+ "@tsconfig/strictest": "2.0.8",
22
+ "@types/debug": "4.1.12",
21
23
  "@types/fs-extra": "11.0.4",
22
- "@types/node": "22.19.0",
23
- "fs-extra": "11.3.2"
24
+ "@types/node": "22.19.11",
25
+ "fs-extra": "11.3.3"
24
26
  },
25
27
  "engines": {
26
28
  "node": ">=22.12.0"