@renovatebot/osv-offline 1.2.12 → 1.3.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/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Package version](https://img.shields.io/npm/v/@renovatebot/osv-offline?style=for-the-badge)](https://www.npmjs.com/package/@renovatebot/osv-offline)
4
4
  [![Build status](https://img.shields.io/github/actions/workflow/status/renovatebot/osv-offline/build.yml?branch=main&style=for-the-badge)](https://github.com/renovatebot/osv-offline/actions/workflows/build.yml)
5
5
  [![MIT license](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](./LICENSE)
6
- ![Stability experimental](https://img.shields.io/badge/stability-experimental-orange.svg?style=for-the-badge)
7
6
 
8
7
  ## License
9
8
 
@@ -1 +1,2 @@
1
- export declare function tryDownloadDb(): Promise<boolean>;
1
+ import { Result } from './types';
2
+ export declare function tryDownloadDb(): Promise<Result>;
@@ -14,6 +14,7 @@ const osv_offline_db_1 = require("@renovatebot/osv-offline-db");
14
14
  const path_1 = __importDefault(require("path"));
15
15
  const luxon_1 = require("luxon");
16
16
  const adm_zip_1 = __importDefault(require("adm-zip"));
17
+ const types_1 = require("./types");
17
18
  const pipeline = (0, util_1.promisify)(stream_1.Stream.pipeline);
18
19
  const baseParameters = {
19
20
  owner: 'renovatebot',
@@ -31,9 +32,12 @@ async function tryDownloadDb() {
31
32
  }
32
33
  if (stats !== undefined &&
33
34
  luxon_1.DateTime.utc().diff(luxon_1.DateTime.fromJSDate(stats.mtime)).as('days') < 1) {
34
- return true;
35
+ return (0, types_1.success)();
35
36
  }
36
- const octokitOptions = { auth: process.env['GITHUB_COM_TOKEN'], request: { fetch: node_fetch_1.default } };
37
+ const octokitOptions = {
38
+ auth: process.env['GITHUB_COM_TOKEN'],
39
+ request: { fetch: node_fetch_1.default },
40
+ };
37
41
  let latestRelease = null;
38
42
  try {
39
43
  latestRelease = (await new rest_1.Octokit(octokitOptions).repos.listReleases({
@@ -41,12 +45,12 @@ async function tryDownloadDb() {
41
45
  })).data[0];
42
46
  }
43
47
  catch (err) {
44
- return false;
48
+ return (0, types_1.failure)(err);
45
49
  }
46
50
  const asset = latestRelease?.assets.find((asset) => asset.name === 'osv-offline.zip');
47
51
  // if local database is the same size as remote database, don't download again
48
52
  if (asset?.size === stats?.size) {
49
- return true;
53
+ return (0, types_1.success)();
50
54
  }
51
55
  if (asset !== undefined) {
52
56
  // only download databases if local databases are missing or remote is newer
@@ -59,9 +63,9 @@ async function tryDownloadDb() {
59
63
  zip.extractAllTo(osv_offline_db_1.OsvOfflineDb.rootDirectory);
60
64
  }
61
65
  catch (err) {
62
- return false;
66
+ return (0, types_1.failure)(err);
63
67
  }
64
68
  }
65
- return true;
69
+ return (0, types_1.success)();
66
70
  }
67
71
  exports.tryDownloadDb = tryDownloadDb;
@@ -11,9 +11,9 @@ class OsvOffline {
11
11
  * Asynchronous code required as part of class instantiation
12
12
  */
13
13
  async initialize() {
14
- const success = await (0, download_1.tryDownloadDb)();
15
- if (!success) {
16
- throw new Error();
14
+ const result = await (0, download_1.tryDownloadDb)();
15
+ if (!result.success) {
16
+ throw result.error;
17
17
  }
18
18
  this.osvOfflineDb = await osv_offline_db_1.OsvOfflineDb.create();
19
19
  }
@@ -0,0 +1,11 @@
1
+ type Success = {
2
+ success: true;
3
+ };
4
+ type Failure = {
5
+ success: false;
6
+ error: Error;
7
+ };
8
+ export type Result = Success | Failure;
9
+ export declare function success(): Success;
10
+ export declare function failure(error: Error): Failure;
11
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.failure = exports.success = void 0;
4
+ function success() {
5
+ return { success: true };
6
+ }
7
+ exports.success = success;
8
+ function failure(error) {
9
+ return { success: false, error };
10
+ }
11
+ exports.failure = failure;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renovatebot/osv-offline",
3
- "version": "1.2.12",
3
+ "version": "1.3.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@renovatebot/osv-offline-db": "1.4.0",
12
- "@octokit/rest": "^19.0.11",
12
+ "@octokit/rest": "^19.0.13",
13
13
  "adm-zip": "~0.5.10",
14
14
  "fs-extra": "^11.1.1",
15
15
  "got": "^11.8.6",
@@ -20,10 +20,10 @@
20
20
  "@types/adm-zip": "0.5.0",
21
21
  "@types/fs-extra": "11.0.1",
22
22
  "@types/luxon": "3.3.0",
23
- "@types/node": "18.16.13",
23
+ "@types/node": "18.16.16",
24
24
  "@types/node-fetch": "2.6.4",
25
25
  "prettier": "2.8.8",
26
26
  "ts-node": "10.9.1",
27
- "typescript": "5.0.4"
27
+ "typescript": "5.1.3"
28
28
  }
29
29
  }