From ddf07c67144b24803898715d16634495068121cc Mon Sep 17 00:00:00 2001 From: William Chargin Date: Mon, 16 Sep 2019 19:22:35 -0700 Subject: [PATCH] Replace `PartialTimelineCredParams` with `$Shape` (#1379) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Flow provides a utility type for this purpose; there’s no need to implement, document, and keep it in sync ourselves: Test Plan: As written, `yarn flow` passes. Changing the definition of `params` on line 77 of `load.test.js` to add a key `foo: "wat"` or change the value of `weights` to `{hmm: "hmm"}` yield appropriate type errors. wchargin-branch: use-shape --- src/analysis/timeline/params.js | 21 ++------------------- src/analysis/timeline/timelineCred.js | 5 ++--- src/api/load.js | 4 ++-- src/api/load.test.js | 4 ++-- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/analysis/timeline/params.js b/src/analysis/timeline/params.js index 5213a88..653205e 100644 --- a/src/analysis/timeline/params.js +++ b/src/analysis/timeline/params.js @@ -35,17 +35,6 @@ export type TimelineCredParameters = {| export const DEFAULT_ALPHA = 0.05; export const DEFAULT_INTERVAL_DECAY = 0.5; -/** - * The PartialTimelineCredParameters are a version of TimelineCredParameters - * where every field has been marked optional, to make it convenient for API - * clients to override just the parameters they want to. - */ -export type PartialTimelineCredParameters = {| - +alpha?: number, - +intervalDecay?: number, - +weights?: Weights, -|}; - export type TimelineCredParametersJSON = {| +alpha: number, +intervalDecay: number, @@ -87,16 +76,10 @@ export function defaultParams(): TimelineCredParameters { } /** - * Promote PartialTimelineCredParameters to TimelineCredParameters. - * - * This takes PartialTimelineCredParameters and mixes them with the - * default parameters to provide a full TimelineCredParameters. - * - * End consumers of SourceCred will not need to depend on this; it's - * provided for implementation of SourceCred's APIs. + * Fill in default values for timeline cred parameters. */ export function partialParams( - partial: PartialTimelineCredParameters + partial: $Shape ): TimelineCredParameters { return {...defaultParams(), ...partial}; } diff --git a/src/analysis/timeline/timelineCred.js b/src/analysis/timeline/timelineCred.js index 537333c..97aab8f 100644 --- a/src/analysis/timeline/timelineCred.js +++ b/src/analysis/timeline/timelineCred.js @@ -21,7 +21,6 @@ import { paramsToJSON, paramsFromJSON, type TimelineCredParametersJSON, - type PartialTimelineCredParameters, partialParams, defaultParams, } from "./params"; @@ -88,7 +87,7 @@ export class TimelineCred { * This returns a new TimelineCred; it does not modify the existing one. */ async reanalyze( - newParams: PartialTimelineCredParameters + newParams: $Shape ): Promise { return await TimelineCred.compute({ graph: this._graph, @@ -227,7 +226,7 @@ export class TimelineCred { static async compute(opts: {| graph: Graph, - params?: PartialTimelineCredParameters, + params?: $Shape, plugins: $ReadOnlyArray, |}): Promise { const {graph, params, plugins} = opts; diff --git a/src/api/load.js b/src/api/load.js index 18e1d08..f36d4f9 100644 --- a/src/api/load.js +++ b/src/api/load.js @@ -8,7 +8,7 @@ import {Graph} from "../core/graph"; import {loadGraph} from "../plugins/github/loadGraph"; import {TimelineCred} from "../analysis/timeline/timelineCred"; import {defaultParams, partialParams} from "../analysis/timeline/params"; -import {type PartialTimelineCredParameters} from "../analysis/timeline/params"; +import {type TimelineCredParameters} from "../analysis/timeline/params"; import {type Project} from "../core/project"; import {setupProjectDirectory} from "../core/project_io"; @@ -18,7 +18,7 @@ import * as NullUtil from "../util/null"; export type LoadOptions = {| +project: Project, - +params: ?PartialTimelineCredParameters, + +params: ?$Shape, +plugins: $ReadOnlyArray, +sourcecredDirectory: string, +githubToken: string | null, diff --git a/src/api/load.test.js b/src/api/load.test.js index 92a2b53..66dfb14 100644 --- a/src/api/load.test.js +++ b/src/api/load.test.js @@ -20,7 +20,7 @@ import {node} from "../core/graphTestUtil"; import {TestTaskReporter} from "../util/taskReporter"; import {load, type LoadOptions} from "./load"; import { - type PartialTimelineCredParameters, + type TimelineCredParameters, partialParams, } from "../analysis/timeline/params"; @@ -74,7 +74,7 @@ describe("api/load", () => { // Tweaks the weights so that we can ensure we aren't overriding with default weights weights.nodeManualWeights.set(NodeAddress.empty, 33); // Deep freeze will freeze the weights, too - const params: PartialTimelineCredParameters = {weights}; + const params: $Shape = {weights}; const plugins = deepFreeze([]); const example = () => { const sourcecredDirectory = tmp.dirSync().name;