@renovatebot/osv-offline-db 4.1.1 → 4.2.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 +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/split-index.d.ts +44 -0
- package/dist/lib/split-index.js +45 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { OsvOfflineDb } from './lib/db.ts';
|
|
2
2
|
export { DatabaseIndexBuilder, type DatabaseRecord, getIndexFileName, } from './lib/db-index.ts';
|
|
3
3
|
export { Ecosystem, ecosystems } from './lib/ecosystem.ts';
|
|
4
|
+
export { type SplitEcosystem, type SplitFile, type SplitIndex, getSplitFileName, parseSplitIndex, splitIndexSchema, } from './lib/split-index.ts';
|
|
4
5
|
export * as Osv from './lib/osv.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { OsvOfflineDb } from "./lib/db.js";
|
|
2
2
|
export { DatabaseIndexBuilder, getIndexFileName, } from "./lib/db-index.js";
|
|
3
3
|
export { ecosystems } from "./lib/ecosystem.js";
|
|
4
|
+
export { getSplitFileName, parseSplitIndex, splitIndexSchema, } from "./lib/split-index.js";
|
|
4
5
|
export * as Osv from "./lib/osv.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Ecosystem } from './ecosystem.ts';
|
|
2
|
+
/** the version of the split index format, see {@link SplitIndex} */
|
|
3
|
+
export declare const splitIndexSchema = 2;
|
|
4
|
+
/**
|
|
5
|
+
* A compressed file of the split format.
|
|
6
|
+
*/
|
|
7
|
+
export interface SplitFile {
|
|
8
|
+
/** file name, relative to {@link SplitIndex.baseUrl} or the index URL */
|
|
9
|
+
readonly file: string;
|
|
10
|
+
/** SHA-256 of the compressed file, as hex */
|
|
11
|
+
readonly sha256: string;
|
|
12
|
+
/** size of the compressed file in bytes */
|
|
13
|
+
readonly size: number;
|
|
14
|
+
/** size of the decompressed file in bytes */
|
|
15
|
+
readonly uncompressedSize: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The files of an ecosystem: its database (`.nedb`) and its precomputed index (`.idx.json`), each compressed with zstd.
|
|
19
|
+
*/
|
|
20
|
+
export interface SplitEcosystem {
|
|
21
|
+
readonly database: SplitFile;
|
|
22
|
+
readonly index: SplitFile;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The `index.json` of the split format, which lists the current files of each ecosystem.
|
|
26
|
+
*/
|
|
27
|
+
export interface SplitIndex {
|
|
28
|
+
readonly schema: typeof splitIndexSchema;
|
|
29
|
+
/** when the files were generated, as ISO 8601 */
|
|
30
|
+
readonly generated: string;
|
|
31
|
+
/** base URL of the files; without it, they are relative to the index URL */
|
|
32
|
+
readonly baseUrl?: string;
|
|
33
|
+
readonly ecosystems: Partial<Record<Ecosystem, SplitEcosystem>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the file name of a compressed database or index of the split format, e.g. `npm-20261027120513.nedb.zst`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getSplitFileName(ecosystem: Ecosystem, kind: keyof SplitEcosystem, version: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Parses an `index.json` of the split format.
|
|
41
|
+
*
|
|
42
|
+
* @returns the index, or `null` when it isn't valid or has another schema version
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseSplitIndex(content: string): SplitIndex | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ecosystems } from "./ecosystem.js";
|
|
2
|
+
/** the version of the split index format, see {@link SplitIndex} */
|
|
3
|
+
export const splitIndexSchema = 2;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the file name of a compressed database or index of the split format, e.g. `npm-20261027120513.nedb.zst`.
|
|
6
|
+
*/
|
|
7
|
+
export function getSplitFileName(ecosystem, kind, version) {
|
|
8
|
+
const extension = kind === 'database' ? 'nedb' : 'idx.json';
|
|
9
|
+
return `${ecosystem.toLowerCase()}-${version}.${extension}.zst`;
|
|
10
|
+
}
|
|
11
|
+
function isSplitFile(value) {
|
|
12
|
+
const file = value;
|
|
13
|
+
return (typeof file?.file === 'string' &&
|
|
14
|
+
// a plain file name, not a path or URL
|
|
15
|
+
/^[\w.-]+$/.test(file.file) &&
|
|
16
|
+
typeof file.sha256 === 'string' &&
|
|
17
|
+
/^[0-9a-f]{64}$/.test(file.sha256) &&
|
|
18
|
+
Number.isSafeInteger(file.size) &&
|
|
19
|
+
Number.isSafeInteger(file.uncompressedSize));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses an `index.json` of the split format.
|
|
23
|
+
*
|
|
24
|
+
* @returns the index, or `null` when it isn't valid or has another schema version
|
|
25
|
+
*/
|
|
26
|
+
export function parseSplitIndex(content) {
|
|
27
|
+
let index;
|
|
28
|
+
try {
|
|
29
|
+
index = JSON.parse(content);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (index?.schema !== splitIndexSchema ||
|
|
35
|
+
typeof index.generated !== 'string' ||
|
|
36
|
+
(index.baseUrl !== undefined && typeof index.baseUrl !== 'string') ||
|
|
37
|
+
typeof index.ecosystems !== 'object' ||
|
|
38
|
+
index.ecosystems === null) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const valid = Object.entries(index.ecosystems).every(([ecosystem, files]) => ecosystems.includes(ecosystem) &&
|
|
42
|
+
isSplitFile(files?.database) &&
|
|
43
|
+
isSplitFile(files.index));
|
|
44
|
+
return valid ? index : null;
|
|
45
|
+
}
|