@meterapp/vehicle-db 2.53.0 → 2.55.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 +33 -5
- package/dist/data.js +1 -1
- package/dist/identity-data.js +1 -1
- package/dist/identity.d.ts +43 -0
- package/dist/identity.js +45 -0
- package/dist/packages.d.ts +9 -0
- package/dist/packages.js +20 -0
- package/dist/resolve.js +16 -7
- package/package.json +9 -1
package/dist/identity.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface IdentityEvidence {
|
|
|
13
13
|
retrievedAt: string;
|
|
14
14
|
note: string;
|
|
15
15
|
}
|
|
16
|
+
/** The exterior parts an appearance package can change, a fixed list. */
|
|
17
|
+
export declare const EXTERIOR_DIFFERENCES: readonly ["grille", "front_bumper", "rear_bumper", "side_skirts", "wheels", "badges", "mirrors", "spoiler", "exhaust", "lamps", "trim_color"];
|
|
18
|
+
export type ExteriorDifference = typeof EXTERIOR_DIFFERENCES[number];
|
|
16
19
|
export interface VehicleIdentity extends IdentityScope {
|
|
17
20
|
id: string;
|
|
18
21
|
kind: IdentityKind;
|
|
@@ -33,6 +36,11 @@ export interface VehicleIdentity extends IdentityScope {
|
|
|
33
36
|
transmission?: string;
|
|
34
37
|
rawText: string;
|
|
35
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* On the visual identity of an appearance package (under a specification with `specification.trim`):
|
|
41
|
+
* the parts its evidence shows differ from the base car.
|
|
42
|
+
*/
|
|
43
|
+
exteriorDifferences?: ExteriorDifference[];
|
|
36
44
|
evidenceIds: string[];
|
|
37
45
|
}
|
|
38
46
|
export interface VehicleIdentityAlias extends IdentityScope {
|
|
@@ -53,6 +61,12 @@ export interface IdentityCatalogLink {
|
|
|
53
61
|
makeId: number;
|
|
54
62
|
modelId: number;
|
|
55
63
|
vehicleTypeId: number;
|
|
64
|
+
/**
|
|
65
|
+
* Absent: the identity describes the row. `offered-on`: the identity (an appearance package's
|
|
66
|
+
* specification) is an option on the row's vehicle; the row still describes the base car, so
|
|
67
|
+
* resolution ignores these links.
|
|
68
|
+
*/
|
|
69
|
+
relation?: "offered-on";
|
|
56
70
|
evidenceIds: string[];
|
|
57
71
|
}
|
|
58
72
|
export interface VisualCompatibility extends IdentityScope {
|
|
@@ -98,3 +112,32 @@ export declare function scopeMatches(scope: IdentityScope, context: ScopeContext
|
|
|
98
112
|
export declare function normalizeIdentityText(text: string): string;
|
|
99
113
|
/** Direct, directional facts only; no reverse or transitive inference. */
|
|
100
114
|
export declare function evaluateVisualCompatibility(rules: readonly VisualCompatibility[], requestedId: string, assetId: string, context: ScopeContext): "allow" | "deny" | "unknown";
|
|
115
|
+
/** An appearance package offered on a catalog vehicle: a specification identity and its exterior. */
|
|
116
|
+
export interface AppearancePackage {
|
|
117
|
+
/** The package name in lower-case kebab form ("F SPORT" → "f-sport"); unique per catalog vehicle and year. */
|
|
118
|
+
slug: string;
|
|
119
|
+
/** The maker's package name, `specification.trim`. */
|
|
120
|
+
name: string;
|
|
121
|
+
specificationId: string;
|
|
122
|
+
visualIdentityId: string;
|
|
123
|
+
exteriorDifferences: ExteriorDifference[];
|
|
124
|
+
years: number[];
|
|
125
|
+
markets?: string[];
|
|
126
|
+
yearBasis: YearBasis;
|
|
127
|
+
evidenceIds: string[];
|
|
128
|
+
}
|
|
129
|
+
export interface AppearancePackageQuery {
|
|
130
|
+
makeId: number;
|
|
131
|
+
modelId: number;
|
|
132
|
+
year: number;
|
|
133
|
+
market?: string;
|
|
134
|
+
}
|
|
135
|
+
/** The stable slug of a package name: lower-case kebab, accents and punctuation dropped. */
|
|
136
|
+
export declare function appearancePackageSlug(name: string): string;
|
|
137
|
+
/** The package's exterior: the visual child of a specification that lists its exterior differences. */
|
|
138
|
+
export declare function packageVisual(graph: Pick<IdentityGraph, "identities">, specificationId: string): VehicleIdentity | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* The appearance packages offered on a catalog vehicle in a year. A market-scoped package is returned
|
|
141
|
+
* only when `market` is given and in its scope; with no market, only packages without a market scope.
|
|
142
|
+
*/
|
|
143
|
+
export declare function listAppearancePackages(graph: IdentityGraph, query: AppearancePackageQuery): AppearancePackage[];
|
package/dist/identity.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EXTERIOR_DIFFERENCES = void 0;
|
|
3
4
|
exports.scopeMatches = scopeMatches;
|
|
4
5
|
exports.normalizeIdentityText = normalizeIdentityText;
|
|
5
6
|
exports.evaluateVisualCompatibility = evaluateVisualCompatibility;
|
|
7
|
+
exports.appearancePackageSlug = appearancePackageSlug;
|
|
8
|
+
exports.packageVisual = packageVisual;
|
|
9
|
+
exports.listAppearancePackages = listAppearancePackages;
|
|
10
|
+
/** The exterior parts an appearance package can change, a fixed list. */
|
|
11
|
+
exports.EXTERIOR_DIFFERENCES = ["grille", "front_bumper", "rear_bumper", "side_skirts", "wheels", "badges", "mirrors", "spoiler", "exhaust", "lamps", "trim_color"];
|
|
6
12
|
/** Missing context cannot satisfy a restricted scope. */
|
|
7
13
|
function scopeMatches(scope, context) {
|
|
8
14
|
return (!scope.years || (context.year !== undefined && scope.years.includes(context.year))) &&
|
|
@@ -23,3 +29,42 @@ function evaluateVisualCompatibility(rules, requestedId, assetId, context) {
|
|
|
23
29
|
return "deny";
|
|
24
30
|
return applicable.some(rule => rule.decision === "allow") ? "allow" : "unknown";
|
|
25
31
|
}
|
|
32
|
+
/** The stable slug of a package name: lower-case kebab, accents and punctuation dropped. */
|
|
33
|
+
function appearancePackageSlug(name) {
|
|
34
|
+
return name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\+/g, " plus ")
|
|
35
|
+
.split(/[^a-z0-9]+/).filter(Boolean).join("-");
|
|
36
|
+
}
|
|
37
|
+
/** The package's exterior: the visual child of a specification that lists its exterior differences. */
|
|
38
|
+
function packageVisual(graph, specificationId) {
|
|
39
|
+
return graph.identities.find(n => n.kind === "visual" && n.parentId === specificationId && n.exteriorDifferences?.length);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The appearance packages offered on a catalog vehicle in a year. A market-scoped package is returned
|
|
43
|
+
* only when `market` is given and in its scope; with no market, only packages without a market scope.
|
|
44
|
+
*/
|
|
45
|
+
function listAppearancePackages(graph, query) {
|
|
46
|
+
const { makeId, modelId, year, market } = query;
|
|
47
|
+
if (![makeId, modelId, year].every(Number.isInteger))
|
|
48
|
+
return [];
|
|
49
|
+
const nodes = new Map(graph.identities.map(n => [n.id, n]));
|
|
50
|
+
const inMarkets = (scope) => !scope.markets || (market !== undefined && scope.markets.includes(market));
|
|
51
|
+
const result = new Map();
|
|
52
|
+
for (const link of graph.catalogLinks) {
|
|
53
|
+
if (link.relation !== "offered-on" || link.makeId !== makeId || link.modelId !== modelId || link.year !== year || result.has(link.identityId))
|
|
54
|
+
continue;
|
|
55
|
+
const spec = nodes.get(link.identityId);
|
|
56
|
+
const visual = spec && packageVisual(graph, spec.id);
|
|
57
|
+
if (!spec?.specification?.trim || !visual || !spec.years || !spec.yearBasis)
|
|
58
|
+
continue;
|
|
59
|
+
if (!spec.years.includes(year) || (visual.years && !visual.years.includes(year)) || !inMarkets(spec) || !inMarkets(visual))
|
|
60
|
+
continue;
|
|
61
|
+
const markets = visual.markets ?? spec.markets;
|
|
62
|
+
result.set(spec.id, {
|
|
63
|
+
slug: appearancePackageSlug(spec.specification.trim), name: spec.specification.trim,
|
|
64
|
+
specificationId: spec.id, visualIdentityId: visual.id, exteriorDifferences: [...visual.exteriorDifferences],
|
|
65
|
+
years: [...spec.years], ...(markets ? { markets: [...markets] } : {}), yearBasis: spec.yearBasis,
|
|
66
|
+
evidenceIds: [...new Set([...spec.evidenceIds, ...visual.evidenceIds])],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return [...result.values()].sort((a, b) => a.slug.localeCompare(b.slug) || a.specificationId.localeCompare(b.specificationId));
|
|
70
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AppearancePackage, type AppearancePackageQuery } from "./identity";
|
|
2
|
+
export type { AppearancePackage, AppearancePackageQuery, ExteriorDifference } from "./identity";
|
|
3
|
+
export { EXTERIOR_DIFFERENCES, appearancePackageSlug } from "./identity";
|
|
4
|
+
/**
|
|
5
|
+
* The appearance packages (Lexus F SPORT, BMW M Sport…) offered on a catalog vehicle in a year, from the
|
|
6
|
+
* bundled identity graph. A market-scoped package is returned only when `market` is given and matches;
|
|
7
|
+
* with no market, only packages without a market scope.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAppearancePackages(query: AppearancePackageQuery): AppearancePackage[];
|
package/dist/packages.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.appearancePackageSlug = exports.EXTERIOR_DIFFERENCES = void 0;
|
|
7
|
+
exports.getAppearancePackages = getAppearancePackages;
|
|
8
|
+
const identity_data_1 = __importDefault(require("./identity-data"));
|
|
9
|
+
const identity_1 = require("./identity");
|
|
10
|
+
var identity_2 = require("./identity");
|
|
11
|
+
Object.defineProperty(exports, "EXTERIOR_DIFFERENCES", { enumerable: true, get: function () { return identity_2.EXTERIOR_DIFFERENCES; } });
|
|
12
|
+
Object.defineProperty(exports, "appearancePackageSlug", { enumerable: true, get: function () { return identity_2.appearancePackageSlug; } });
|
|
13
|
+
/**
|
|
14
|
+
* The appearance packages (Lexus F SPORT, BMW M Sport…) offered on a catalog vehicle in a year, from the
|
|
15
|
+
* bundled identity graph. A market-scoped package is returned only when `market` is given and matches;
|
|
16
|
+
* with no market, only packages without a market scope.
|
|
17
|
+
*/
|
|
18
|
+
function getAppearancePackages(query) {
|
|
19
|
+
return (0, identity_1.listAppearancePackages)(identity_data_1.default, query);
|
|
20
|
+
}
|
package/dist/resolve.js
CHANGED
|
@@ -13,6 +13,8 @@ const rank = { catalog: 0, line: 1, generation: 2, derivative: 3, specification:
|
|
|
13
13
|
/** Create an isolated resolver for a validated graph and catalog, including test fixtures. */
|
|
14
14
|
function createVehicleResolver(catalog, identities) {
|
|
15
15
|
const nodes = new Map(identities.identities.map(n => [n.id, n]));
|
|
16
|
+
// An appearance package is offered on a row that still describes the base car: its links never resolve the row.
|
|
17
|
+
const catalogLinks = identities.catalogLinks.filter(l => l.relation !== "offered-on");
|
|
16
18
|
const ancestry = (node) => {
|
|
17
19
|
const result = [node], seen = new Set([node.id]);
|
|
18
20
|
let parent = node.parentId ? nodes.get(node.parentId) : undefined;
|
|
@@ -23,6 +25,13 @@ function createVehicleResolver(catalog, identities) {
|
|
|
23
25
|
}
|
|
24
26
|
return result;
|
|
25
27
|
};
|
|
28
|
+
// An appearance package's specification and exterior answer only a request that reaches them directly:
|
|
29
|
+
// walking down from the base car never lands on a package.
|
|
30
|
+
const packageSpecs = new Set(identities.identities.filter(n => n.kind === "visual" && n.exteriorDifferences?.length && n.parentId).map(n => n.parentId));
|
|
31
|
+
const descends = (child, ancestor) => {
|
|
32
|
+
const chain = ancestry(child), at = chain.findIndex(p => p.id === ancestor.id);
|
|
33
|
+
return at >= 0 && !chain.slice(0, at).some(p => packageSpecs.has(p.id));
|
|
34
|
+
};
|
|
26
35
|
const makeNames = catalog.makes.map(m => ({ id: m.make_id, name: (0, identity_1.normalizeIdentityText)(m.make_name) })).sort((a, b) => b.name.length - a.name.length);
|
|
27
36
|
const byMake = new Map();
|
|
28
37
|
for (const r of catalog.models) {
|
|
@@ -42,7 +51,7 @@ function createVehicleResolver(catalog, identities) {
|
|
|
42
51
|
const linkedTo = (r) => {
|
|
43
52
|
if (!linkIndex) {
|
|
44
53
|
linkIndex = new Map();
|
|
45
|
-
for (const l of
|
|
54
|
+
for (const l of catalogLinks) {
|
|
46
55
|
const node = nodes.get(l.identityId);
|
|
47
56
|
if (!node)
|
|
48
57
|
continue;
|
|
@@ -91,9 +100,9 @@ function createVehicleResolver(catalog, identities) {
|
|
|
91
100
|
const scopeOk = (n) => ancestry(n).every(p => (0, identity_1.scopeMatches)(p, context));
|
|
92
101
|
const candidateOf = (n, from) => {
|
|
93
102
|
const chain = ancestry(n), lineage = Object.fromEntries(chain.map(p => [p.kind, p.id]));
|
|
94
|
-
const links =
|
|
103
|
+
const links = catalogLinks.filter(l => (l.identityId === n.id || (n.kind === "visual" && chain.some(p => p.id === l.identityId))) && (year === undefined || l.year === year));
|
|
95
104
|
const catalogSelections = from.filter(r => links.some(l => l.year === r[0] && l.makeId === r[1] && l.modelId === r[2] && l.vehicleTypeId === r[4])).map(select);
|
|
96
|
-
const visuals = identities.identities.filter(v => v.kind === "visual" &&
|
|
105
|
+
const visuals = identities.identities.filter(v => v.kind === "visual" && descends(v, n) && scopeOk(v));
|
|
97
106
|
return { identityId: n.id, depth: n.kind, lineage, catalogSelections, visualIdentityIds: visuals.map(v => v.id), evidenceIds: [...new Set(chain.flatMap(p => p.evidenceIds))] };
|
|
98
107
|
};
|
|
99
108
|
const allNamed = identities.identities.filter(n => n.makeId === makeId && (options.vehicleTypeId === undefined || options.vehicleTypeId === n.vehicleTypeId) && n.names.some(s => (0, identity_1.normalizeIdentityText)(s) === text));
|
|
@@ -108,7 +117,7 @@ function createVehicleResolver(catalog, identities) {
|
|
|
108
117
|
const requestedDepth = options.depth ?? "catalog";
|
|
109
118
|
// A line/generation can be completed only when all scope constraints leave one child.
|
|
110
119
|
if (requestedDepth !== "catalog") {
|
|
111
|
-
matching = matching.flatMap(n => rank[n.kind] >= rank[requestedDepth] ? [n] : identities.identities.filter(child => rank[child.kind] === rank[requestedDepth] &&
|
|
120
|
+
matching = matching.flatMap(n => rank[n.kind] >= rank[requestedDepth] ? [n] : identities.identities.filter(child => rank[child.kind] === rank[requestedDepth] && descends(child, n) && scopeOk(child)));
|
|
112
121
|
}
|
|
113
122
|
matching = [...new Map(matching.map(n => [n.id, n])).values()];
|
|
114
123
|
if (!matching.length)
|
|
@@ -119,7 +128,7 @@ function createVehicleResolver(catalog, identities) {
|
|
|
119
128
|
if (candidates.length !== 1)
|
|
120
129
|
return result("AMBIGUOUS", candidates);
|
|
121
130
|
if (requestedDepth === "catalog" && !candidates[0].catalogSelections.length) {
|
|
122
|
-
const knownLinks =
|
|
131
|
+
const knownLinks = catalogLinks.some(l => l.identityId === candidates[0].identityId);
|
|
123
132
|
return result(knownLinks && year !== undefined ? "YEAR_UNVERIFIED" : "KNOWN_DERIVATIVE_UNSUPPORTED", candidates);
|
|
124
133
|
}
|
|
125
134
|
return result("MATCHED", candidates);
|
|
@@ -155,14 +164,14 @@ function createVehicleResolver(catalog, identities) {
|
|
|
155
164
|
const verifiedGroups = [...groups.values()].map(rs => rs.filter(r => verified.includes(r))).filter(rs => rs.length);
|
|
156
165
|
const scoped = verifiedGroups.map(rs => {
|
|
157
166
|
const linked = [...new Set(rs.flatMap(inScope))];
|
|
158
|
-
const visuals = identities.identities.filter(v => v.kind === "visual" && scopeOk(v) &&
|
|
167
|
+
const visuals = identities.identities.filter(v => v.kind === "visual" && scopeOk(v) && linked.some(p => descends(v, p)));
|
|
159
168
|
return { ...flat(rs), visualIdentityIds: visuals.map(v => v.id), evidenceIds: [...new Set(linked.flatMap(n => ancestry(n)).flatMap(p => p.evidenceIds))] };
|
|
160
169
|
});
|
|
161
170
|
return result(scoped.length === 1 ? "MATCHED" : "AMBIGUOUS", scoped);
|
|
162
171
|
}
|
|
163
172
|
const linked = [...new Set(verified.flatMap(inScope))];
|
|
164
173
|
// A linked identity deeper than the request answers with its ancestor at that depth; a shallower one with its scoped children.
|
|
165
|
-
const deep = [...new Set(linked.flatMap(n => rank[n.kind] >= rank[depth] ? [ancestry(n).find(p => p.kind === depth) ?? n] : identities.identities.filter(child => rank[child.kind] === rank[depth] &&
|
|
174
|
+
const deep = [...new Set(linked.flatMap(n => rank[n.kind] >= rank[depth] ? [ancestry(n).find(p => p.kind === depth) ?? n] : identities.identities.filter(child => rank[child.kind] === rank[depth] && descends(child, n) && scopeOk(child))))];
|
|
166
175
|
if (!deep.length)
|
|
167
176
|
return result("GENERATION_UNRESOLVED", [...groups.values()].map(rs => rs.filter(r => verified.includes(r))).filter(rs => rs.length).map(flat));
|
|
168
177
|
// The selections are the verified rows that led to the identity, through itself, a descendant or an ancestor.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterapp/vehicle-db",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.55.0",
|
|
4
4
|
"description": "Offline international database for cars, motorcycles, trucks, buses, MPVs, and more",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"types": "./dist/identity.d.ts",
|
|
34
34
|
"require": "./dist/identity.js",
|
|
35
35
|
"default": "./dist/identity.js"
|
|
36
|
+
},
|
|
37
|
+
"./packages": {
|
|
38
|
+
"types": "./dist/packages.d.ts",
|
|
39
|
+
"require": "./dist/packages.js",
|
|
40
|
+
"default": "./dist/packages.js"
|
|
36
41
|
}
|
|
37
42
|
},
|
|
38
43
|
"typesVersions": {
|
|
@@ -45,6 +50,9 @@
|
|
|
45
50
|
],
|
|
46
51
|
"identity": [
|
|
47
52
|
"dist/identity.d.ts"
|
|
53
|
+
],
|
|
54
|
+
"packages": [
|
|
55
|
+
"dist/packages.d.ts"
|
|
48
56
|
]
|
|
49
57
|
}
|
|
50
58
|
},
|