Rocky_Mountain_Vending/.pnpm-store/v10/files/0b/a38ad9ce42f11028cb8ea976c9d2e919891c6a0cd8646246083859a37b0bb504e68308cdcf6a6522615ff4732874377b1e9a56a1345246315f6c50da127e72
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

100 lines
3.4 KiB
Text

/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {TraceProcessor} from '../../lib/tracehouse/trace-processor.js';
import {ProcessedTrace} from '../processed-trace.js';
import {ProcessedNavigation} from '../processed-navigation.js';
import {NetworkRecords} from '../network-records.js';
/**
* @fileOverview Encapsulates logic for choosing the correct metric computation method based on the
* specified throttling settings, supporting simulated and observed metric types.
*
* To implement a fully supported metric:
* - Override the computeObservedMetric method with the observed-mode implementation.
* - Override the computeSimulatedMetric method with the simulated-mode implementation (which
* may call another computed artifact with the name LanternMyMetricName).
*/
class Metric {
constructor() {}
/**
* Narrows the metric computation data to the input so child metric requests can be cached.
*
* @param {LH.Artifacts.MetricComputationData} data
* @return {LH.Artifacts.MetricComputationDataInput}
*/
static getMetricComputationInput(data) {
return {
trace: data.trace,
devtoolsLog: data.devtoolsLog,
gatherContext: data.gatherContext,
settings: data.settings,
URL: data.URL,
SourceMaps: data.SourceMaps,
simulator: null,
};
}
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric|LH.Artifacts.Metric>}
*/
static computeSimulatedMetric(data, context) { // eslint-disable-line no-unused-vars
throw new Error('Unimplemented');
}
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.Metric>}
*/
static computeObservedMetric(data, context) { // eslint-disable-line no-unused-vars
throw new Error('Unimplemented');
}
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric|LH.Artifacts.Metric>}
*/
static async compute_(data, context) {
const {trace, devtoolsLog, settings, gatherContext} = data;
if (!trace || !devtoolsLog || !settings) {
throw new Error('Did not provide necessary metric computation data');
}
const processedTrace = await ProcessedTrace.request(trace, context);
const processedNavigation = gatherContext.gatherMode === 'timespan' ?
undefined : await ProcessedNavigation.request(trace, context);
const augmentedData = Object.assign({
networkRecords: await NetworkRecords.request(devtoolsLog, context),
gatherContext,
processedTrace,
processedNavigation,
}, data);
TraceProcessor.assertHasToplevelEvents(augmentedData.processedTrace.mainThreadEvents);
switch (settings.throttlingMethod) {
case 'simulate':
if (gatherContext.gatherMode !== 'navigation') {
throw new Error(`${gatherContext.gatherMode} does not support throttlingMethod simulate`);
}
return this.computeSimulatedMetric(augmentedData, context);
case 'provided':
case 'devtools':
return this.computeObservedMetric(augmentedData, context);
default:
throw new TypeError(`Unrecognized throttling method: ${settings.throttlingMethod}`);
}
}
}
export default Metric;