Skip to content

Commit 7a72385

Browse files
underootgithub-actions[bot]
authored andcommitted
Add private Style.getBOMObject method for tests
GitOrigin-RevId: 1a57b2e805cbd17868975c917e4b9dc983e96eb4
1 parent e730d17 commit 7a72385

4 files changed

Lines changed: 603 additions & 1 deletion

File tree

build/rollup_plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const plugins = ({mode, format, minified, production, test, bench, keepCl
3939
}),
4040
(production && !bench) ? strip({
4141
sourceMap: true,
42-
functions: ['PerformanceUtils.*', 'WorkerPerformanceUtils.*', 'Debug.*', 'DevTools.*'],
42+
functions: ['PerformanceUtils.*', 'WorkerPerformanceUtils.*', 'Debug.*', 'DevTools.*', 'StyleBOMUtils.*'],
4343
include: ['**/*.ts']
4444
}) : false,
4545
// eslint-disable-next-line @typescript-eslint/no-unsafe-call

src/style/style.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {loadIconset} from './load_iconset';
6868
import {ImageId} from '../style-spec/expression/types/image_id';
6969
import {ImageProvider} from '../render/image_provider';
7070
import IndoorManager from './indoor_manager';
71+
import {StyleBOMUtils} from './style_bom_utils';
7172

7273
import type {PropertyValidatorOptions} from '../style-spec/validate/validate_property';
7374
import type Tile from '../source/tile';
@@ -128,6 +129,9 @@ import type {StyleModelMap} from './style_mode';
128129
import type {TypedStyleLayer} from './style_layer/typed_style_layer';
129130
import type {LngLatLike} from '../geo/lng_lat';
130131
import type {RasterQueryParameters, RasterQueryResult} from '../source/raster_array_tile_source';
132+
import type {StyleBOM} from './style_bom_utils';
133+
134+
export type {StyleBOMEntry, StyleBOM} from './style_bom_utils';
131135

132136
export type QueryRenderedFeaturesParams = {
133137
layers?: string[];
@@ -4630,6 +4634,17 @@ class Style extends Evented<MapEvents> {
46304634
this.dispatcher.broadcast('clearCaches');
46314635
}
46324636

4637+
/**
4638+
* Returns the Bill of Materials (BOM) for this style, containing information
4639+
* about all styles and tilesets used by this style and its imports.
4640+
*
4641+
* @private
4642+
* @returns {StyleBOM} Array of BOM entries with style URLs, tileset URLs, and modified dates.
4643+
*/
4644+
getBOMObject(): StyleBOM {
4645+
return StyleBOMUtils.getBOMObject(this);
4646+
}
4647+
46334648
destroy() {
46344649
this._clearWorkerCaches();
46354650
this.fragments.forEach(fragment => {

src/style/style_bom_utils.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import type Style from './style';
2+
3+
/**
4+
* A single entry in the Style BOM (Bill of Materials).
5+
* Either contains a style URL or a tileset URL, along with an optional modified timestamp.
6+
* @private
7+
*/
8+
export type StyleBOMEntry = {
9+
style?: string;
10+
modified?: string | number;
11+
tileset?: string;
12+
};
13+
14+
/**
15+
* The Bill of Materials for a style, containing all styles and tilesets used.
16+
* @private
17+
*/
18+
export type StyleBOM = Array<StyleBOMEntry>;
19+
20+
/**
21+
* Utility namespace for Style BOM operations.
22+
* Calls to StyleBOMUtils.* are stripped from production builds.
23+
* @private
24+
*/
25+
export const StyleBOMUtils = {
26+
/**
27+
* Returns the Bill of Materials (BOM) for a style.
28+
* @private
29+
*/
30+
getBOMObject(style: Style): StyleBOM {
31+
const bom: StyleBOM = [];
32+
const visited = new Set<string>();
33+
const rootStyleGlobalId = style.globalId;
34+
35+
const processStyle = (s: Style) => {
36+
const globalId = s.globalId ? s.globalId : rootStyleGlobalId;
37+
const modified = s.stylesheet ? (s.stylesheet as {modified?: string}).modified : undefined;
38+
if (globalId && modified && !visited.has(globalId)) {
39+
visited.add(globalId);
40+
bom.push({
41+
style: globalId,
42+
modified: modified ? modified : null
43+
});
44+
}
45+
46+
for (const fragment of s.fragments) {
47+
processStyle(fragment.style);
48+
}
49+
50+
if (s.stylesheet && s.stylesheet.sources) {
51+
for (const sourceId in s.stylesheet.sources) {
52+
const source = s.stylesheet.sources[sourceId];
53+
if (source && 'url' in source && source.url) {
54+
const data = (source as unknown as {data?: {modified?: number, created: number}}).data;
55+
bom.push({
56+
tileset: source.url,
57+
modified: data ? data.modified || data.created : null
58+
});
59+
}
60+
}
61+
}
62+
};
63+
64+
processStyle(style);
65+
return bom;
66+
}
67+
};

0 commit comments

Comments
 (0)