@meterapp/vehicle-db 2.2.0 → 2.4.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 +112 -84
- package/dist/data.d.ts +16 -1
- package/dist/data.js +2 -2
- package/dist/index.d.ts +22 -0
- package/dist/index.js +53 -5
- package/package.json +21 -8
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,21 @@ export interface VehicleType {
|
|
|
2
2
|
vehicleTypeId: number;
|
|
3
3
|
vehicleTypeName: string;
|
|
4
4
|
}
|
|
5
|
+
export interface DataSource {
|
|
6
|
+
sourceId: string;
|
|
7
|
+
sourceName: string;
|
|
8
|
+
sourceUrl: string;
|
|
9
|
+
license: string;
|
|
10
|
+
licenseUrl?: string;
|
|
11
|
+
region: string;
|
|
12
|
+
description: string;
|
|
13
|
+
retrievedAt: string;
|
|
14
|
+
vehicleTypeIds: number[];
|
|
15
|
+
yearFrom: number;
|
|
16
|
+
yearTo: number;
|
|
17
|
+
makeCount: number;
|
|
18
|
+
modelCount: number;
|
|
19
|
+
}
|
|
5
20
|
export interface Make {
|
|
6
21
|
makeId: number;
|
|
7
22
|
makeName: string;
|
|
@@ -13,20 +28,27 @@ export interface Model {
|
|
|
13
28
|
makeName: string;
|
|
14
29
|
vehicleTypeId: number;
|
|
15
30
|
vehicleTypeName: string;
|
|
31
|
+
sourceIds: string[];
|
|
16
32
|
}
|
|
17
33
|
export interface GetMakesOptions {
|
|
18
34
|
year?: number;
|
|
19
35
|
vehicleTypeId?: number;
|
|
36
|
+
sourceId?: string;
|
|
20
37
|
}
|
|
21
38
|
export interface GetModelsOptions {
|
|
22
39
|
year?: number;
|
|
23
40
|
vehicleTypeId?: number;
|
|
24
41
|
makeId?: number;
|
|
42
|
+
sourceId?: string;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* Returns all vehicle types in the database.
|
|
28
46
|
*/
|
|
29
47
|
export declare function getVehicleTypes(): VehicleType[];
|
|
48
|
+
/**
|
|
49
|
+
* Returns provenance and coverage metadata for every bundled source.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getDataSources(): DataSource[];
|
|
30
52
|
/**
|
|
31
53
|
* Returns makes, optionally filtered by year and/or vehicle type.
|
|
32
54
|
*/
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getVehicleTypes = getVehicleTypes;
|
|
7
|
+
exports.getDataSources = getDataSources;
|
|
7
8
|
exports.getMakes = getMakes;
|
|
8
9
|
exports.getModels = getModels;
|
|
9
10
|
exports.getAvailableYears = getAvailableYears;
|
|
@@ -13,6 +14,7 @@ const data_1 = __importDefault(require("./data"));
|
|
|
13
14
|
// ---------------------------------------------------------------------------
|
|
14
15
|
let _makeMap = null;
|
|
15
16
|
let _typeMap = null;
|
|
17
|
+
let _sourceMaskMap = null;
|
|
16
18
|
function getMakeMap() {
|
|
17
19
|
if (!_makeMap) {
|
|
18
20
|
_makeMap = new Map(data_1.default.makes.map((m) => [m.make_id, m.make_name]));
|
|
@@ -25,6 +27,20 @@ function getTypeMap() {
|
|
|
25
27
|
}
|
|
26
28
|
return _typeMap;
|
|
27
29
|
}
|
|
30
|
+
function getSourceMaskMap() {
|
|
31
|
+
if (!_sourceMaskMap) {
|
|
32
|
+
_sourceMaskMap = new Map(data_1.default.sources.map((source, index) => [source.source_id, 2 ** index]));
|
|
33
|
+
}
|
|
34
|
+
return _sourceMaskMap;
|
|
35
|
+
}
|
|
36
|
+
function getSourceIds(sourceMask) {
|
|
37
|
+
const sourceIds = [];
|
|
38
|
+
for (let index = 0; index < data_1.default.sources.length; index++) {
|
|
39
|
+
if ((sourceMask & 2 ** index) !== 0)
|
|
40
|
+
sourceIds.push(data_1.default.sources[index].source_id);
|
|
41
|
+
}
|
|
42
|
+
return sourceIds;
|
|
43
|
+
}
|
|
28
44
|
// ---------------------------------------------------------------------------
|
|
29
45
|
// Public API
|
|
30
46
|
// ---------------------------------------------------------------------------
|
|
@@ -37,26 +53,51 @@ function getVehicleTypes() {
|
|
|
37
53
|
vehicleTypeName: t.vehicle_type_name,
|
|
38
54
|
}));
|
|
39
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns provenance and coverage metadata for every bundled source.
|
|
58
|
+
*/
|
|
59
|
+
function getDataSources() {
|
|
60
|
+
return data_1.default.sources.map((source) => ({
|
|
61
|
+
sourceId: source.source_id,
|
|
62
|
+
sourceName: source.source_name,
|
|
63
|
+
sourceUrl: source.source_url,
|
|
64
|
+
license: source.license,
|
|
65
|
+
...(source.license_url ? { licenseUrl: source.license_url } : {}),
|
|
66
|
+
region: source.region,
|
|
67
|
+
description: source.description,
|
|
68
|
+
retrievedAt: source.retrieved_at,
|
|
69
|
+
vehicleTypeIds: [...source.vehicle_type_ids],
|
|
70
|
+
yearFrom: source.year_from,
|
|
71
|
+
yearTo: source.year_to,
|
|
72
|
+
makeCount: source.make_count,
|
|
73
|
+
modelCount: source.model_count,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
40
76
|
/**
|
|
41
77
|
* Returns makes, optionally filtered by year and/or vehicle type.
|
|
42
78
|
*/
|
|
43
79
|
function getMakes(options = {}) {
|
|
44
|
-
const { year, vehicleTypeId } = options;
|
|
45
|
-
if (year == null && vehicleTypeId == null) {
|
|
80
|
+
const { year, vehicleTypeId, sourceId } = options;
|
|
81
|
+
if (year == null && vehicleTypeId == null && sourceId == null) {
|
|
46
82
|
return data_1.default.makes.map((m) => ({ makeId: m.make_id, makeName: m.make_name }));
|
|
47
83
|
}
|
|
84
|
+
const sourceMask = sourceId == null ? undefined : getSourceMaskMap().get(sourceId);
|
|
85
|
+
if (sourceId != null && sourceMask == null)
|
|
86
|
+
return [];
|
|
48
87
|
const makeIds = new Set();
|
|
49
88
|
for (const m of data_1.default.models) {
|
|
50
89
|
if (year != null && m[0] !== year)
|
|
51
90
|
continue;
|
|
52
91
|
if (vehicleTypeId != null && m[4] !== vehicleTypeId)
|
|
53
92
|
continue;
|
|
93
|
+
if (sourceMask != null && (m[5] & sourceMask) === 0)
|
|
94
|
+
continue;
|
|
54
95
|
makeIds.add(m[1]);
|
|
55
96
|
}
|
|
56
97
|
const makeMap = getMakeMap();
|
|
57
98
|
return [...makeIds]
|
|
58
99
|
.map((id) => ({ makeId: id, makeName: makeMap.get(id) }))
|
|
59
|
-
.sort((a, b) => (a.makeName
|
|
100
|
+
.sort((a, b) => (a.makeName < b.makeName ? -1 : a.makeName > b.makeName ? 1 : 0));
|
|
60
101
|
}
|
|
61
102
|
/**
|
|
62
103
|
* Returns models, optionally filtered by year, vehicle type, and/or make.
|
|
@@ -64,7 +105,10 @@ function getMakes(options = {}) {
|
|
|
64
105
|
function getModels(options = {}) {
|
|
65
106
|
const makeMap = getMakeMap();
|
|
66
107
|
const typeMap = getTypeMap();
|
|
67
|
-
const { year, vehicleTypeId, makeId } = options;
|
|
108
|
+
const { year, vehicleTypeId, makeId, sourceId } = options;
|
|
109
|
+
const sourceMask = sourceId == null ? undefined : getSourceMaskMap().get(sourceId);
|
|
110
|
+
if (sourceId != null && sourceMask == null)
|
|
111
|
+
return [];
|
|
68
112
|
const results = [];
|
|
69
113
|
for (const m of data_1.default.models) {
|
|
70
114
|
if (year != null && m[0] !== year)
|
|
@@ -73,6 +117,8 @@ function getModels(options = {}) {
|
|
|
73
117
|
continue;
|
|
74
118
|
if (vehicleTypeId != null && m[4] !== vehicleTypeId)
|
|
75
119
|
continue;
|
|
120
|
+
if (sourceMask != null && (m[5] & sourceMask) === 0)
|
|
121
|
+
continue;
|
|
76
122
|
results.push({
|
|
77
123
|
modelId: m[2],
|
|
78
124
|
modelName: data_1.default.modelNames[m[3]],
|
|
@@ -80,9 +126,11 @@ function getModels(options = {}) {
|
|
|
80
126
|
makeName: makeMap.get(m[1]),
|
|
81
127
|
vehicleTypeId: m[4],
|
|
82
128
|
vehicleTypeName: typeMap.get(m[4]),
|
|
129
|
+
sourceIds: getSourceIds(m[5]),
|
|
83
130
|
});
|
|
84
131
|
}
|
|
85
|
-
return results.sort((a, b) => (a.modelName
|
|
132
|
+
return results.sort((a, b) => (a.modelName < b.modelName ? -1 : a.modelName > b.modelName ? 1 : 0) ||
|
|
133
|
+
a.vehicleTypeId - b.vehicleTypeId);
|
|
86
134
|
}
|
|
87
135
|
/**
|
|
88
136
|
* Get all available years in the database.
|
package/package.json
CHANGED
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterapp/vehicle-db",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Offline
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "Offline international vehicle makes/models database — zero dependencies",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/MeterApp/vehicle-db.git"
|
|
8
|
+
},
|
|
5
9
|
"main": "dist/index.js",
|
|
6
10
|
"types": "dist/index.d.ts",
|
|
7
11
|
"files": [
|
|
8
12
|
"dist"
|
|
9
13
|
],
|
|
10
14
|
"scripts": {
|
|
11
|
-
"build:db": "
|
|
15
|
+
"build:db": "npm run build:data",
|
|
16
|
+
"build:data": "tsx scripts/build-db.ts",
|
|
17
|
+
"refresh:nhtsa": "tsx scripts/import-nhtsa.ts",
|
|
18
|
+
"refresh:uk-dft": "tsx scripts/import-uk-dft.ts",
|
|
12
19
|
"build:ts": "tsc",
|
|
13
20
|
"build": "npm run build:ts",
|
|
21
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.scripts.json",
|
|
14
22
|
"prepublishOnly": "npm run build",
|
|
15
23
|
"test": "vitest run"
|
|
16
24
|
},
|
|
17
25
|
"keywords": [
|
|
18
26
|
"nhtsa",
|
|
27
|
+
"dvla",
|
|
19
28
|
"vehicles",
|
|
20
29
|
"makes",
|
|
21
30
|
"models",
|
|
31
|
+
"motorcycles",
|
|
32
|
+
"buses",
|
|
33
|
+
"international",
|
|
22
34
|
"offline"
|
|
23
35
|
],
|
|
24
36
|
"author": "",
|
|
25
37
|
"license": "ISC",
|
|
26
38
|
"type": "commonjs",
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
27
42
|
"devDependencies": {
|
|
28
|
-
"@types/
|
|
29
|
-
"
|
|
30
|
-
"better-sqlite3": "^12.6.2",
|
|
31
|
-
"tsx": "^4.21.0",
|
|
43
|
+
"@types/node": "^25.9.5",
|
|
44
|
+
"tsx": "^4.23.12",
|
|
32
45
|
"typescript": "^5.9.3",
|
|
33
|
-
"vitest": "^4.
|
|
46
|
+
"vitest": "^4.1.11"
|
|
34
47
|
}
|
|
35
48
|
}
|