Skip to content

Commit

Permalink
fix ts issue from test-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Feb 29, 2024
1 parent ad1a8c1 commit d82a880
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
vars: 'all',
args: 'after-used',
argsIgnorePattern: '(^reject$|^_+$)',
varsIgnorePattern: '(^_$|^LH$|^Lantern$)',
varsIgnorePattern: '(^_$|^LH$|^NetworkRequest$)',
}],
'no-cond-assign': 2,
'space-infix-ops': 2,
Expand Down
5 changes: 2 additions & 3 deletions core/lib/dependency-graph/network-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from './types.js';
import {BaseNode} from './base-node.js';
import {NetworkRequest} from './network-request.js';

class NetworkNode extends BaseNode {
/**
* @param {Lantern.NetworkRequest} networkRecord
* @param {NetworkRequest} networkRecord
*/
constructor(networkRecord) {
super(networkRecord.requestId);
Expand All @@ -37,7 +36,7 @@ class NetworkNode extends BaseNode {
}

/**
* @return {Lantern.NetworkRequest}
* @return {NetworkRequest}
*/
get record() {
return this._record;
Expand Down
12 changes: 6 additions & 6 deletions core/lib/dependency-graph/simulator/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../types.js';
import * as LH from '../../../../types/lh.js';
import {NetworkRequest} from '../network-request.js';
import {NetworkAnalyzer} from './network-analyzer.js';
import {TcpConnection} from './tcp-connection.js';

Expand All @@ -18,7 +18,7 @@ const CONNECTIONS_PER_ORIGIN = 6;

export class ConnectionPool {
/**
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @param {Required<LH.Gatherer.Simulation.Options>} options
*/
constructor(records, options) {
Expand All @@ -27,7 +27,7 @@ export class ConnectionPool {
this._records = records;
/** @type {Map<string, TcpConnection[]>} */
this._connectionsByOrigin = new Map();
/** @type {Map<Lantern.NetworkRequest, TcpConnection>} */
/** @type {Map<NetworkRequest, TcpConnection>} */
this._connectionsByRecord = new Map();
this._connectionsInUse = new Set();
this._connectionReusedByRequestId = NetworkAnalyzer.estimateIfConnectionWasReused(records, {
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ConnectionPool {
* If ignoreConnectionReused is true, acquire will consider all connections not in use as available.
* Otherwise, only connections that have matching "warmth" are considered available.
*
* @param {Lantern.NetworkRequest} record
* @param {NetworkRequest} record
* @param {{ignoreConnectionReused?: boolean}} options
* @return {?TcpConnection}
*/
Expand All @@ -151,7 +151,7 @@ export class ConnectionPool {
* Return the connection currently being used to fetch a record. If no connection
* currently being used for this record, an error will be thrown.
*
* @param {Lantern.NetworkRequest} record
* @param {NetworkRequest} record
* @return {TcpConnection}
*/
acquireActiveConnectionFromRecord(record) {
Expand All @@ -162,7 +162,7 @@ export class ConnectionPool {
}

/**
* @param {Lantern.NetworkRequest} record
* @param {NetworkRequest} record
*/
release(record) {
const connection = this._connectionsByRecord.get(record);
Expand Down
6 changes: 3 additions & 3 deletions core/lib/dependency-graph/simulator/dns-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../types.js';
import {NetworkRequest} from '../network-request.js';

// A DNS lookup will usually take ~1-2 roundtrips of connection latency plus the extra DNS routing time.
// Example: https://www.webpagetest.org/result/180703_3A_e33ec79747c002ed4d7bcbfc81462203/1/details/#waterfall_view_step1
Expand All @@ -25,7 +25,7 @@ class DNSCache {
}

/**
* @param {Lantern.NetworkRequest} request
* @param {NetworkRequest} request
* @param {{requestedAt: number, shouldUpdateCache: boolean}=} options
* @return {number}
*/
Expand All @@ -47,7 +47,7 @@ class DNSCache {
}

/**
* @param {Lantern.NetworkRequest} request
* @param {NetworkRequest} request
* @param {number} resolvedAt
*/
_updateCacheResolvedAtIfNeeded(request, resolvedAt) {
Expand Down
34 changes: 17 additions & 17 deletions core/lib/dependency-graph/simulator/network-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../types.js';
import {NetworkRequest} from '../network-request.js';
import UrlUtils from '../../url-utils.js';

const INITIAL_CWD = 14 * 1024;
Expand Down Expand Up @@ -32,8 +32,8 @@ class NetworkAnalyzer {
}

/**
* @param {Lantern.NetworkRequest[]} records
* @return {Map<string, Lantern.NetworkRequest[]>}
* @param {NetworkRequest[]} records
* @return {Map<string, NetworkRequest[]>}
*/
static groupByOrigin(records) {
const grouped = new Map();
Expand Down Expand Up @@ -88,10 +88,10 @@ class NetworkAnalyzer {
return summaryByKey;
}

/** @typedef {{record: Lantern.NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */
/** @typedef {{record: NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */

/**
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @param {(e: RequestInfo) => number | number[] | undefined} iteratee
* @return {Map<string, number[]>}
*/
Expand Down Expand Up @@ -250,7 +250,7 @@ class NetworkAnalyzer {
/**
* Given the RTT to each origin, estimates the observed server response times.
*
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @param {Map<string, number>} rttByOrigin
* @return {Map<string, number[]>}
*/
Expand All @@ -271,7 +271,7 @@ class NetworkAnalyzer {
}

/**
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @return {boolean}
*/
static canTrustConnectionInformation(records) {
Expand All @@ -291,7 +291,7 @@ class NetworkAnalyzer {
* Returns a map of requestId -> connectionReused, estimating the information if the information
* available in the records themselves appears untrustworthy.
*
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @param {{forceCoarseEstimates: boolean}} [options]
* @return {Map<string, boolean>}
*/
Expand Down Expand Up @@ -335,7 +335,7 @@ class NetworkAnalyzer {
* Attempts to use the most accurate information first and falls back to coarser estimates when it
* is unavailable.
*
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @param {RTTEstimateOptions} [options]
* @return {Map<string, Summary>}
*/
Expand Down Expand Up @@ -416,7 +416,7 @@ class NetworkAnalyzer {
* Estimates the server response time of each origin. RTT times can be passed in or will be
* estimated automatically if not provided.
*
* @param {Lantern.NetworkRequest[]} records
* @param {NetworkRequest[]} records
* @param {RTTEstimateOptions & {rttByOrigin?: Map<string, number>}} [options]
* @return {Map<string, Summary>}
*/
Expand All @@ -442,7 +442,7 @@ class NetworkAnalyzer {
* Excludes data URI, failed or otherwise incomplete, and cached requests.
* Returns Infinity if there were no analyzable network records.
*
* @param {Array<Lantern.NetworkRequest>} networkRecords
* @param {Array<NetworkRequest>} networkRecords
* @return {number}
*/
static estimateThroughput(networkRecords) {
Expand Down Expand Up @@ -495,9 +495,9 @@ class NetworkAnalyzer {
}

/**
* @param {Array<Lantern.NetworkRequest>} records
* @param {Array<NetworkRequest>} records
* @param {string} resourceUrl
* @return {Lantern.NetworkRequest|undefined}
* @return {NetworkRequest|undefined}
*/
static findResourceForUrl(records, resourceUrl) {
// equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first
Expand All @@ -508,9 +508,9 @@ class NetworkAnalyzer {
}

/**
* @param {Array<Lantern.NetworkRequest>} records
* @param {Array<NetworkRequest>} records
* @param {string} resourceUrl
* @return {Lantern.NetworkRequest|undefined}
* @return {NetworkRequest|undefined}
*/
static findLastDocumentForUrl(records, resourceUrl) {
// equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first
Expand All @@ -527,8 +527,8 @@ class NetworkAnalyzer {
* Resolves redirect chain given a main document.
* See: {@link NetworkAnalyzer.findLastDocumentForUrl}) for how to retrieve main document.
*
* @param {Lantern.NetworkRequest} request
* @return {Lantern.NetworkRequest}
* @param {NetworkRequest} request
* @return {NetworkRequest}
*/
static resolveRedirects(request) {
while (request.redirectDestination) request = request.redirectDestination;
Expand Down
6 changes: 3 additions & 3 deletions core/lib/dependency-graph/simulator/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import * as LH from '../../../../types/lh.js';
import * as Lantern from '../types.js';
import {NetworkRequest} from '../network-request.js';
import {BaseNode} from '../base-node.js';
import {TcpConnection} from './tcp-connection.js';
import {ConnectionPool} from './connection-pool.js';
Expand Down Expand Up @@ -102,7 +102,7 @@ class Simulator {
* @param {Node} graph
*/
_initializeConnectionPool(graph) {
/** @type {Lantern.NetworkRequest[]} */
/** @type {NetworkRequest[]} */
const records = [];
graph.getRootNode().traverse(node => {
if (node.type === BaseNode.TYPES.NETWORK) {
Expand Down Expand Up @@ -191,7 +191,7 @@ class Simulator {
}

/**
* @param {Lantern.NetworkRequest} record
* @param {NetworkRequest} record
* @return {?TcpConnection}
*/
_acquireConnection(record) {
Expand Down
10 changes: 3 additions & 7 deletions core/lib/dependency-graph/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export type NetworkRequest = LH.Artifacts.NetworkRequest;
export { NetworkRequest };
import { NetworkRequest } from './network-request.js';
//# sourceMappingURL=types.d.ts.map
7 changes: 0 additions & 7 deletions core/lib/dependency-graph/types.js

This file was deleted.

0 comments on commit d82a880

Please sign in to comment.