Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(lhr): lhr-lite type declaration #4983

Merged
merged 6 commits into from
Apr 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions typings/lhr-lite.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* @license Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

declare global {
module LH {
/**
* The lightweight version of Lighthouse results.
*/
export interface ResultLite {
/** The URL that was supplied to Lighthouse and initially navigated to. */
requestedUrl: string;
/** The post-redirects URL that Lighthouse loaded. */
finalUrl: string;
/** The ISO-8601 timestamp of when the results were generated. */
fetchedAt: string;
/** The version of Lighthouse with which these results were generated. */
lighthouseVersion: string;
/** An object containing the results of the audits. */
audits: Record<string, ResultLite.Audit>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we don't have any references to what auditId really is how do you feel about aliases like type AuditId = string?

/** An object containing the top-level categories, their overall scores, and reference to member audits. */
categories: Record<string, ResultLite.Category>;
}

// ResultLite namespace
export module ResultLite {
export interface Category {
/** The human-friendly name of the category. */
title: string;
/** A description of what this category is about (e.g. these help you validate your PWA). */
description: string;
/** The overall score of the category, the weighted average of all its audits. */
score: number;
/** An array of references to all the audit members of this category. */
auditRefs: AuditRef[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

/** An optional description for manual audits within this category. */
manualDescription?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

}

/**
* A reference to an audit result, with weighting and grouping information
* for its place in this category.
*/
export interface AuditRef {
/** Matches a key in the top-level `audits` object. */
auditId: string;
/** The weight of the audit's score in the overall category score. */
weight: number;
}

export interface Audit {
/** The brief description of the audit. The text can change depending on if the audit passed or failed. */
title: string;
/** A more detailed description that describes why the audit is important and links to Lighthouse documentation on the audit; markdown links supported. */
description: string;
/** The scored value determined by the audit, in the range `0-1`, or null if `scoreDisplayMode` indicates not scored. */
score: number | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I'd prefer score?: number

/**
* A string identifying how the score should be interpreted:
* 'binary': pass/fail audit (0 and 1 are only possible scores).
* 'numeric': scores of 0-1 (map to displayed scores of 0-100).
* 'informative': the audit is an FYI only, and can't be interpreted as pass/fail. Score is null and should be ignored.
* 'notApplicable': the audit turned out to not apply to the page. Score is null and should be ignored.
* 'manual': The audit exists only to tell you to review something yourself. Score is null and should be ignored.
* 'error': There was an error while running the object (check `errorMessage` for details). Score is null and should be ignored.
*/
scoreDisplayMode: 'binary' | 'numeric' | 'informative' | 'notApplicable' | 'manual' | 'error';
/** An explanation of audit-related issues encountered on the test page. */
explanation?: string;
/** Extra information provided by some types of audits. */
details?: Audit.MetricDetails | Audit.OpportunityDetails;
/** Error message from any exception thrown while running this audit. */
errorMessage?: string;
}

export module Audit {
export interface MetricDetails {
type: 'metric';
/** The value of the metric expressed in milliseconds. */
timespanMs?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still 😬, but I think we mostly exhausted options. last-ditch effort anyone like ms timeMs timingMs more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i consider timespanMs/ms/timingMs to be equally 😬 and i'd be fine with any of those.

}

export interface OpportunityDetails {
type: 'opportunity';
wastedMs: number
wastedBytes?: number
headings: ColumnHeading[];
items: (WastedBytesDetailsItem | WastedTimeDetailsItem)[];
}

export interface ColumnHeading {
key: string;
label: string;
valueType: 'url' | 'timespanMs' | 'bytes';
}

export interface WastedBytesDetailsItem {
url: string;
wastedBytes?: number;
totalBytes?: number;
}

export interface WastedTimeDetailsItem {
url: string;
wastedMs: number;
totalBytes?: number;
}
}
}
}
}

// empty export to keep file a module
export {}