Rename "AppAdapter" -> "ExplorerAdapter" (#1052)
There are two kinds of plugin adapters: adapters for doing cred analysis, called "analysis adapters", and adapters for the cred explorer, which are confusingly called "app adapters". This commit decreases the confusion by renaming app adapters to explorer adapters across the codebase. In a future commit, I will add documentation to the adapter interfaces so that it is clearer to a newcomer to the codebase why these interfaces exist. Thanks to @BrianLitwin, who asked a question during [office hours] that surfaced this issue. [office hours]: https://github.com/sourcecred/mission/issues/12 Test plan: `yarn test` passes, suggests that this rename went off without a hitch. Code review as a sanity check. Also: grepping for `AppAdapter` returns 0 results: ``` $ git grep AppAdapter | wc -l 0 ``` Note: After producing this commit, I can confirm that the word "adapter" starts to look like utter gibberish after you type it often enough.
This commit is contained in:
parent
2d8a25afc8
commit
e92f247305
|
@ -19,7 +19,7 @@ import {
|
||||||
type StateTransitionMachineInterface,
|
type StateTransitionMachineInterface,
|
||||||
initialState,
|
initialState,
|
||||||
} from "./state";
|
} from "./state";
|
||||||
import {StaticAdapterSet} from "./adapters/adapterSet";
|
import {StaticExplorerAdapterSet} from "./adapters/explorerAdapterSet";
|
||||||
|
|
||||||
const credOverviewUrl =
|
const credOverviewUrl =
|
||||||
"https://discuss.sourcecred.io/t/a-gentle-introduction-to-cred/20";
|
"https://discuss.sourcecred.io/t/a-gentle-introduction-to-cred/20";
|
||||||
|
@ -28,7 +28,7 @@ const feedbackUrl =
|
||||||
|
|
||||||
export class AppPage extends React.Component<{|
|
export class AppPage extends React.Component<{|
|
||||||
+assets: Assets,
|
+assets: Assets,
|
||||||
+adapters: StaticAdapterSet,
|
+adapters: StaticExplorerAdapterSet,
|
||||||
+repoId: RepoId,
|
+repoId: RepoId,
|
||||||
|}> {
|
|}> {
|
||||||
static _LOCAL_STORE = new CheckedLocalStore(
|
static _LOCAL_STORE = new CheckedLocalStore(
|
||||||
|
@ -54,7 +54,7 @@ export class AppPage extends React.Component<{|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
+assets: Assets,
|
+assets: Assets,
|
||||||
+localStore: LocalStore,
|
+localStore: LocalStore,
|
||||||
+adapters: StaticAdapterSet,
|
+adapters: StaticExplorerAdapterSet,
|
||||||
+repoId: RepoId,
|
+repoId: RepoId,
|
||||||
|};
|
|};
|
||||||
type State = {|
|
type State = {|
|
||||||
|
|
|
@ -7,8 +7,11 @@ import {Graph} from "../core/graph";
|
||||||
import {makeRepoId} from "../core/repoId";
|
import {makeRepoId} from "../core/repoId";
|
||||||
import {Assets} from "../webutil/assets";
|
import {Assets} from "../webutil/assets";
|
||||||
import testLocalStore from "../webutil/testLocalStore";
|
import testLocalStore from "../webutil/testLocalStore";
|
||||||
import {DynamicAdapterSet, StaticAdapterSet} from "./adapters/adapterSet";
|
import {
|
||||||
import {FactorioStaticAdapter} from "../plugins/demo/appAdapter";
|
DynamicExplorerAdapterSet,
|
||||||
|
StaticExplorerAdapterSet,
|
||||||
|
} from "./adapters/explorerAdapterSet";
|
||||||
|
import {FactorioStaticAdapter} from "../plugins/demo/explorerAdapter";
|
||||||
import {defaultWeightsForAdapter} from "./weights/weights";
|
import {defaultWeightsForAdapter} from "./weights/weights";
|
||||||
|
|
||||||
import {PagerankTable} from "./pagerankTable/Table";
|
import {PagerankTable} from "./pagerankTable/Table";
|
||||||
|
@ -37,7 +40,7 @@ describe("explorer/App", () => {
|
||||||
const el = shallow(
|
const el = shallow(
|
||||||
<App
|
<App
|
||||||
assets={new Assets("/foo/")}
|
assets={new Assets("/foo/")}
|
||||||
adapters={new StaticAdapterSet([])}
|
adapters={new StaticExplorerAdapterSet([])}
|
||||||
localStore={localStore}
|
localStore={localStore}
|
||||||
repoId={makeRepoId("foo", "bar")}
|
repoId={makeRepoId("foo", "bar")}
|
||||||
/>
|
/>
|
||||||
|
@ -56,7 +59,10 @@ describe("explorer/App", () => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const emptyAdapters = new DynamicAdapterSet(new StaticAdapterSet([]), []);
|
const emptyAdapters = new DynamicExplorerAdapterSet(
|
||||||
|
new StaticExplorerAdapterSet([]),
|
||||||
|
[]
|
||||||
|
);
|
||||||
const exampleStates = {
|
const exampleStates = {
|
||||||
readyToLoadGraph: (loadingState) => {
|
readyToLoadGraph: (loadingState) => {
|
||||||
return () => ({
|
return () => ({
|
||||||
|
|
|
@ -6,13 +6,13 @@ import type {Assets} from "../../webutil/assets";
|
||||||
import type {RepoId} from "../../core/repoId";
|
import type {RepoId} from "../../core/repoId";
|
||||||
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
||||||
|
|
||||||
export interface StaticAppAdapter {
|
export interface StaticExplorerAdapter {
|
||||||
declaration(): PluginDeclaration;
|
declaration(): PluginDeclaration;
|
||||||
load(assets: Assets, repoId: RepoId): Promise<DynamicAppAdapter>;
|
load(assets: Assets, repoId: RepoId): Promise<DynamicExplorerAdapter>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DynamicAppAdapter {
|
export interface DynamicExplorerAdapter {
|
||||||
graph(): Graph;
|
graph(): Graph;
|
||||||
nodeDescription(NodeAddressT): ReactNode;
|
nodeDescription(NodeAddressT): ReactNode;
|
||||||
static (): StaticAppAdapter;
|
static (): StaticExplorerAdapter;
|
||||||
}
|
}
|
|
@ -5,19 +5,22 @@ import {NodeTrie, EdgeTrie} from "../../core/trie";
|
||||||
import type {Assets} from "../../webutil/assets";
|
import type {Assets} from "../../webutil/assets";
|
||||||
import type {RepoId} from "../../core/repoId";
|
import type {RepoId} from "../../core/repoId";
|
||||||
|
|
||||||
import type {StaticAppAdapter, DynamicAppAdapter} from "./appAdapter";
|
import type {
|
||||||
|
StaticExplorerAdapter,
|
||||||
|
DynamicExplorerAdapter,
|
||||||
|
} from "./explorerAdapter";
|
||||||
import type {EdgeType, NodeType} from "../../analysis/types";
|
import type {EdgeType, NodeType} from "../../analysis/types";
|
||||||
|
|
||||||
import {FallbackStaticAdapter} from "./fallbackAdapter";
|
import {FallbackStaticAdapter} from "./fallbackAdapter";
|
||||||
|
|
||||||
export class StaticAdapterSet {
|
export class StaticExplorerAdapterSet {
|
||||||
_adapters: $ReadOnlyArray<StaticAppAdapter>;
|
_adapters: $ReadOnlyArray<StaticExplorerAdapter>;
|
||||||
_adapterNodeTrie: NodeTrie<StaticAppAdapter>;
|
_adapterNodeTrie: NodeTrie<StaticExplorerAdapter>;
|
||||||
_adapterEdgeTrie: EdgeTrie<StaticAppAdapter>;
|
_adapterEdgeTrie: EdgeTrie<StaticExplorerAdapter>;
|
||||||
_typeNodeTrie: NodeTrie<NodeType>;
|
_typeNodeTrie: NodeTrie<NodeType>;
|
||||||
_typeEdgeTrie: EdgeTrie<EdgeType>;
|
_typeEdgeTrie: EdgeTrie<EdgeType>;
|
||||||
|
|
||||||
constructor(adapters: $ReadOnlyArray<StaticAppAdapter>): void {
|
constructor(adapters: $ReadOnlyArray<StaticExplorerAdapter>): void {
|
||||||
this._adapters = [new FallbackStaticAdapter(), ...adapters];
|
this._adapters = [new FallbackStaticAdapter(), ...adapters];
|
||||||
this._adapterNodeTrie = new NodeTrie();
|
this._adapterNodeTrie = new NodeTrie();
|
||||||
this._adapterEdgeTrie = new EdgeTrie();
|
this._adapterEdgeTrie = new EdgeTrie();
|
||||||
|
@ -37,7 +40,7 @@ export class StaticAdapterSet {
|
||||||
this.edgeTypes().forEach((t) => this._typeEdgeTrie.add(t.prefix, t));
|
this.edgeTypes().forEach((t) => this._typeEdgeTrie.add(t.prefix, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
adapters(): $ReadOnlyArray<StaticAppAdapter> {
|
adapters(): $ReadOnlyArray<StaticExplorerAdapter> {
|
||||||
return this._adapters;
|
return this._adapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,11 +52,11 @@ export class StaticAdapterSet {
|
||||||
return [].concat(...this._adapters.map((x) => x.declaration().edgeTypes));
|
return [].concat(...this._adapters.map((x) => x.declaration().edgeTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
adapterMatchingNode(x: NodeAddressT): StaticAppAdapter {
|
adapterMatchingNode(x: NodeAddressT): StaticExplorerAdapter {
|
||||||
return this._adapterNodeTrie.getLast(x);
|
return this._adapterNodeTrie.getLast(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
adapterMatchingEdge(x: EdgeAddressT): StaticAppAdapter {
|
adapterMatchingEdge(x: EdgeAddressT): StaticExplorerAdapter {
|
||||||
return this._adapterEdgeTrie.getLast(x);
|
return this._adapterEdgeTrie.getLast(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,24 +68,24 @@ export class StaticAdapterSet {
|
||||||
return this._typeEdgeTrie.getLast(x);
|
return this._typeEdgeTrie.getLast(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
load(assets: Assets, repoId: RepoId): Promise<DynamicAdapterSet> {
|
load(assets: Assets, repoId: RepoId): Promise<DynamicExplorerAdapterSet> {
|
||||||
return Promise.all(this._adapters.map((a) => a.load(assets, repoId))).then(
|
return Promise.all(this._adapters.map((a) => a.load(assets, repoId))).then(
|
||||||
(adapters) => new DynamicAdapterSet(this, adapters)
|
(adapters) => new DynamicExplorerAdapterSet(this, adapters)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DynamicAdapterSet {
|
export class DynamicExplorerAdapterSet {
|
||||||
_adapters: $ReadOnlyArray<DynamicAppAdapter>;
|
_adapters: $ReadOnlyArray<DynamicExplorerAdapter>;
|
||||||
_staticAdapterSet: StaticAdapterSet;
|
_staticExplorerAdapterSet: StaticExplorerAdapterSet;
|
||||||
_adapterNodeTrie: NodeTrie<DynamicAppAdapter>;
|
_adapterNodeTrie: NodeTrie<DynamicExplorerAdapter>;
|
||||||
_adapterEdgeTrie: EdgeTrie<DynamicAppAdapter>;
|
_adapterEdgeTrie: EdgeTrie<DynamicExplorerAdapter>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
staticAdapterSet: StaticAdapterSet,
|
staticExplorerAdapterSet: StaticExplorerAdapterSet,
|
||||||
adapters: $ReadOnlyArray<DynamicAppAdapter>
|
adapters: $ReadOnlyArray<DynamicExplorerAdapter>
|
||||||
): void {
|
): void {
|
||||||
this._staticAdapterSet = staticAdapterSet;
|
this._staticExplorerAdapterSet = staticExplorerAdapterSet;
|
||||||
this._adapters = adapters;
|
this._adapters = adapters;
|
||||||
this._adapterNodeTrie = new NodeTrie();
|
this._adapterNodeTrie = new NodeTrie();
|
||||||
this._adapterEdgeTrie = new EdgeTrie();
|
this._adapterEdgeTrie = new EdgeTrie();
|
||||||
|
@ -92,15 +95,15 @@ export class DynamicAdapterSet {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
adapterMatchingNode(x: NodeAddressT): DynamicAppAdapter {
|
adapterMatchingNode(x: NodeAddressT): DynamicExplorerAdapter {
|
||||||
return this._adapterNodeTrie.getLast(x);
|
return this._adapterNodeTrie.getLast(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
adapterMatchingEdge(x: EdgeAddressT): DynamicAppAdapter {
|
adapterMatchingEdge(x: EdgeAddressT): DynamicExplorerAdapter {
|
||||||
return this._adapterEdgeTrie.getLast(x);
|
return this._adapterEdgeTrie.getLast(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
adapters(): $ReadOnlyArray<DynamicAppAdapter> {
|
adapters(): $ReadOnlyArray<DynamicExplorerAdapter> {
|
||||||
return this._adapters;
|
return this._adapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +112,6 @@ export class DynamicAdapterSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
static() {
|
static() {
|
||||||
return this._staticAdapterSet;
|
return this._staticExplorerAdapterSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {NodeAddress, EdgeAddress, Graph} from "../../core/graph";
|
import {NodeAddress, EdgeAddress, Graph} from "../../core/graph";
|
||||||
import {FactorioStaticAdapter} from "../../plugins/demo/appAdapter";
|
import {FactorioStaticAdapter} from "../../plugins/demo/explorerAdapter";
|
||||||
import {StaticAdapterSet} from "./adapterSet";
|
import {StaticExplorerAdapterSet} from "./explorerAdapterSet";
|
||||||
import {FallbackStaticAdapter} from "./fallbackAdapter";
|
import {FallbackStaticAdapter} from "./fallbackAdapter";
|
||||||
import {
|
import {
|
||||||
FALLBACK_NAME,
|
FALLBACK_NAME,
|
||||||
|
@ -12,17 +12,17 @@ import {
|
||||||
import {Assets} from "../../webutil/assets";
|
import {Assets} from "../../webutil/assets";
|
||||||
import {makeRepoId} from "../../core/repoId";
|
import {makeRepoId} from "../../core/repoId";
|
||||||
|
|
||||||
describe("explorer/adapters/adapterSet", () => {
|
describe("explorer/adapters/explorerAdapterSet", () => {
|
||||||
describe("StaticAdapterSet", () => {
|
describe("StaticExplorerAdapterSet", () => {
|
||||||
function example() {
|
function example() {
|
||||||
const x = new FactorioStaticAdapter();
|
const x = new FactorioStaticAdapter();
|
||||||
const fallback = new FallbackStaticAdapter();
|
const fallback = new FallbackStaticAdapter();
|
||||||
const sas = new StaticAdapterSet([x]);
|
const sas = new StaticExplorerAdapterSet([x]);
|
||||||
return {x, fallback, sas};
|
return {x, fallback, sas};
|
||||||
}
|
}
|
||||||
it("errors if two plugins have the same name", () => {
|
it("errors if two plugins have the same name", () => {
|
||||||
const x = new FactorioStaticAdapter();
|
const x = new FactorioStaticAdapter();
|
||||||
const shouldError = () => new StaticAdapterSet([x, x]);
|
const shouldError = () => new StaticExplorerAdapterSet([x, x]);
|
||||||
expect(shouldError).toThrowError("Multiple plugins with name");
|
expect(shouldError).toThrowError("Multiple plugins with name");
|
||||||
});
|
});
|
||||||
it("always includes the fallback plugin", () => {
|
it("always includes the fallback plugin", () => {
|
||||||
|
@ -101,7 +101,7 @@ describe("explorer/adapters/adapterSet", () => {
|
||||||
);
|
);
|
||||||
expect(type).toBe(fallbackEdgeType);
|
expect(type).toBe(fallbackEdgeType);
|
||||||
});
|
});
|
||||||
it("loads a dynamicAdapterSet", async () => {
|
it("loads a dynamicExplorerAdapterSet", async () => {
|
||||||
const {x, sas} = example();
|
const {x, sas} = example();
|
||||||
x.loadingMock = jest.fn().mockResolvedValue();
|
x.loadingMock = jest.fn().mockResolvedValue();
|
||||||
expect(x.loadingMock).toHaveBeenCalledTimes(0);
|
expect(x.loadingMock).toHaveBeenCalledTimes(0);
|
||||||
|
@ -116,17 +116,17 @@ describe("explorer/adapters/adapterSet", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("DynamicAdapterSet", () => {
|
describe("DynamicExplorerAdapterSet", () => {
|
||||||
async function example() {
|
async function example() {
|
||||||
const x = new FactorioStaticAdapter();
|
const x = new FactorioStaticAdapter();
|
||||||
const sas = new StaticAdapterSet([x]);
|
const sas = new StaticExplorerAdapterSet([x]);
|
||||||
const das = await sas.load(
|
const das = await sas.load(
|
||||||
new Assets("/my/gateway/"),
|
new Assets("/my/gateway/"),
|
||||||
makeRepoId("foo", "bar")
|
makeRepoId("foo", "bar")
|
||||||
);
|
);
|
||||||
return {x, sas, das};
|
return {x, sas, das};
|
||||||
}
|
}
|
||||||
it("allows retrieval of the original StaticAdapterSet", async () => {
|
it("allows retrieval of the original StaticExplorerAdapterSet", async () => {
|
||||||
const {sas, das} = await example();
|
const {sas, das} = await example();
|
||||||
expect(das.static()).toBe(sas);
|
expect(das.static()).toBe(sas);
|
||||||
});
|
});
|
|
@ -1,12 +1,15 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {fallbackDeclaration} from "../../analysis/fallbackDeclaration";
|
import {fallbackDeclaration} from "../../analysis/fallbackDeclaration";
|
||||||
import type {StaticAppAdapter, DynamicAppAdapter} from "./appAdapter";
|
import type {
|
||||||
|
StaticExplorerAdapter,
|
||||||
|
DynamicExplorerAdapter,
|
||||||
|
} from "./explorerAdapter";
|
||||||
import {Assets} from "../../webutil/assets";
|
import {Assets} from "../../webutil/assets";
|
||||||
import {type RepoId} from "../../core/repoId";
|
import {type RepoId} from "../../core/repoId";
|
||||||
import {Graph, NodeAddress, type NodeAddressT} from "../../core/graph";
|
import {Graph, NodeAddress, type NodeAddressT} from "../../core/graph";
|
||||||
|
|
||||||
export class FallbackStaticAdapter implements StaticAppAdapter {
|
export class FallbackStaticAdapter implements StaticExplorerAdapter {
|
||||||
declaration() {
|
declaration() {
|
||||||
return fallbackDeclaration;
|
return fallbackDeclaration;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +19,7 @@ export class FallbackStaticAdapter implements StaticAppAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FallbackDynamicAdapter implements DynamicAppAdapter {
|
export class FallbackDynamicAdapter implements DynamicExplorerAdapter {
|
||||||
graph() {
|
graph() {
|
||||||
return new Graph();
|
return new Graph();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import * as NullUtil from "../../util/null";
|
||||||
import type {NodeAddressT} from "../../core/graph";
|
import type {NodeAddressT} from "../../core/graph";
|
||||||
import type {Connection} from "../../core/attribution/graphToMarkovChain";
|
import type {Connection} from "../../core/attribution/graphToMarkovChain";
|
||||||
import type {ScoredConnection} from "../../analysis/pagerankNodeDecomposition";
|
import type {ScoredConnection} from "../../analysis/pagerankNodeDecomposition";
|
||||||
import {DynamicAdapterSet} from "../adapters/adapterSet";
|
import {DynamicExplorerAdapterSet} from "../adapters/explorerAdapterSet";
|
||||||
import {TableRow} from "./TableRow";
|
import {TableRow} from "./TableRow";
|
||||||
import {NodeRow} from "./Node";
|
import {NodeRow} from "./Node";
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ export class ConnectionRow extends React.PureComponent<ConnectionRowProps> {
|
||||||
|
|
||||||
export class ConnectionView extends React.PureComponent<{|
|
export class ConnectionView extends React.PureComponent<{|
|
||||||
+connection: Connection,
|
+connection: Connection,
|
||||||
+adapters: DynamicAdapterSet,
|
+adapters: DynamicExplorerAdapterSet,
|
||||||
|}> {
|
|}> {
|
||||||
render() {
|
render() {
|
||||||
const {connection, adapters} = this.props;
|
const {connection, adapters} = this.props;
|
||||||
|
|
|
@ -6,8 +6,8 @@ import * as NullUtil from "../../util/null";
|
||||||
|
|
||||||
import {type NodeAddressT, NodeAddress} from "../../core/graph";
|
import {type NodeAddressT, NodeAddress} from "../../core/graph";
|
||||||
import type {PagerankNodeDecomposition} from "../../analysis/pagerankNodeDecomposition";
|
import type {PagerankNodeDecomposition} from "../../analysis/pagerankNodeDecomposition";
|
||||||
import {DynamicAdapterSet} from "../adapters/adapterSet";
|
import {DynamicExplorerAdapterSet} from "../adapters/explorerAdapterSet";
|
||||||
import type {DynamicAppAdapter} from "../adapters/appAdapter";
|
import type {DynamicExplorerAdapter} from "../adapters/explorerAdapter";
|
||||||
import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration";
|
import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration";
|
||||||
import type {WeightedTypes} from "../../analysis/weights";
|
import type {WeightedTypes} from "../../analysis/weights";
|
||||||
import {WeightConfig} from "../weights/WeightConfig";
|
import {WeightConfig} from "../weights/WeightConfig";
|
||||||
|
@ -16,7 +16,7 @@ import {NodeRowList} from "./Node";
|
||||||
|
|
||||||
type PagerankTableProps = {|
|
type PagerankTableProps = {|
|
||||||
+pnd: PagerankNodeDecomposition,
|
+pnd: PagerankNodeDecomposition,
|
||||||
+adapters: DynamicAdapterSet,
|
+adapters: DynamicExplorerAdapterSet,
|
||||||
+weightedTypes: WeightedTypes,
|
+weightedTypes: WeightedTypes,
|
||||||
+onWeightedTypesChange: (WeightedTypes) => void,
|
+onWeightedTypesChange: (WeightedTypes) => void,
|
||||||
+maxEntriesPerList: number,
|
+maxEntriesPerList: number,
|
||||||
|
@ -92,7 +92,7 @@ export class PagerankTable extends React.PureComponent<
|
||||||
throw new Error("Impossible.");
|
throw new Error("Impossible.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function optionGroup(adapter: DynamicAppAdapter) {
|
function optionGroup(adapter: DynamicExplorerAdapter) {
|
||||||
const header = (
|
const header = (
|
||||||
<option
|
<option
|
||||||
key={adapter.static().declaration().nodePrefix}
|
key={adapter.static().declaration().nodePrefix}
|
||||||
|
@ -124,7 +124,7 @@ export class PagerankTable extends React.PureComponent<
|
||||||
<option value={NodeAddress.empty}>Show all</option>
|
<option value={NodeAddress.empty}>Show all</option>
|
||||||
{sortBy(
|
{sortBy(
|
||||||
adapters.adapters(),
|
adapters.adapters(),
|
||||||
(a: DynamicAppAdapter) => a.static().declaration().name
|
(a: DynamicExplorerAdapter) => a.static().declaration().name
|
||||||
)
|
)
|
||||||
.filter((a) => a.static().declaration().name !== FALLBACK_NAME)
|
.filter((a) => a.static().declaration().name !== FALLBACK_NAME)
|
||||||
.map(optionGroup)}
|
.map(optionGroup)}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {example, COLUMNS} from "./sharedTestUtils";
|
||||||
import {NodeRowList} from "./Node";
|
import {NodeRowList} from "./Node";
|
||||||
import {WeightConfig} from "../weights/WeightConfig";
|
import {WeightConfig} from "../weights/WeightConfig";
|
||||||
import {defaultWeightsForAdapter} from "../weights/weights";
|
import {defaultWeightsForAdapter} from "../weights/weights";
|
||||||
import {FactorioStaticAdapter} from "../../plugins/demo/appAdapter";
|
import {FactorioStaticAdapter} from "../../plugins/demo/explorerAdapter";
|
||||||
|
|
||||||
require("../../webutil/testUtil").configureEnzyme();
|
require("../../webutil/testUtil").configureEnzyme();
|
||||||
describe("explorer/pagerankTable/Table", () => {
|
describe("explorer/pagerankTable/Table", () => {
|
||||||
|
|
|
@ -7,13 +7,13 @@ import {
|
||||||
NodeAddress,
|
NodeAddress,
|
||||||
} from "../../core/graph";
|
} from "../../core/graph";
|
||||||
|
|
||||||
import {DynamicAdapterSet} from "../adapters/adapterSet";
|
import {DynamicExplorerAdapterSet} from "../adapters/explorerAdapterSet";
|
||||||
|
|
||||||
import type {PagerankNodeDecomposition} from "../../analysis/pagerankNodeDecomposition";
|
import type {PagerankNodeDecomposition} from "../../analysis/pagerankNodeDecomposition";
|
||||||
|
|
||||||
export function nodeDescription(
|
export function nodeDescription(
|
||||||
address: NodeAddressT,
|
address: NodeAddressT,
|
||||||
adapters: DynamicAdapterSet
|
adapters: DynamicExplorerAdapterSet
|
||||||
): ReactNode {
|
): ReactNode {
|
||||||
const adapter = adapters.adapterMatchingNode(address);
|
const adapter = adapters.adapterMatchingNode(address);
|
||||||
try {
|
try {
|
||||||
|
@ -28,7 +28,7 @@ export function nodeDescription(
|
||||||
export function edgeVerb(
|
export function edgeVerb(
|
||||||
address: EdgeAddressT,
|
address: EdgeAddressT,
|
||||||
direction: "FORWARD" | "BACKWARD",
|
direction: "FORWARD" | "BACKWARD",
|
||||||
adapters: DynamicAdapterSet
|
adapters: DynamicExplorerAdapterSet
|
||||||
): string {
|
): string {
|
||||||
const edgeType = adapters.static().typeMatchingEdge(address);
|
const edgeType = adapters.static().typeMatchingEdge(address);
|
||||||
return direction === "FORWARD" ? edgeType.forwardName : edgeType.backwardName;
|
return direction === "FORWARD" ? edgeType.forwardName : edgeType.backwardName;
|
||||||
|
@ -36,7 +36,7 @@ export function edgeVerb(
|
||||||
|
|
||||||
export type SharedProps = {|
|
export type SharedProps = {|
|
||||||
+pnd: PagerankNodeDecomposition,
|
+pnd: PagerankNodeDecomposition,
|
||||||
+adapters: DynamicAdapterSet,
|
+adapters: DynamicExplorerAdapterSet,
|
||||||
+maxEntriesPerList: number,
|
+maxEntriesPerList: number,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
import {pagerank} from "../../analysis/pagerank";
|
import {pagerank} from "../../analysis/pagerank";
|
||||||
import {defaultWeightsForAdapterSet} from "../weights/weights";
|
import {defaultWeightsForAdapterSet} from "../weights/weights";
|
||||||
import {dynamicAdapterSet} from "../../plugins/demo/appAdapter";
|
import {dynamicExplorerAdapterSet} from "../../plugins/demo/explorerAdapter";
|
||||||
|
|
||||||
export const COLUMNS = () => ["Description", "", "Cred"];
|
export const COLUMNS = () => ["Description", "", "Cred"];
|
||||||
|
|
||||||
export async function example() {
|
export async function example() {
|
||||||
const adapters = await dynamicAdapterSet();
|
const adapters = await dynamicExplorerAdapterSet();
|
||||||
const weightedTypes = defaultWeightsForAdapterSet(adapters.static());
|
const weightedTypes = defaultWeightsForAdapterSet(adapters.static());
|
||||||
const graph = adapters.graph();
|
const graph = adapters.graph();
|
||||||
const pnd = await pagerank(graph, (_unused_Edge) => ({
|
const pnd = await pagerank(graph, (_unused_Edge) => ({
|
||||||
|
|
|
@ -12,7 +12,10 @@ import {
|
||||||
pagerank,
|
pagerank,
|
||||||
} from "../analysis/pagerank";
|
} from "../analysis/pagerank";
|
||||||
|
|
||||||
import {StaticAdapterSet, DynamicAdapterSet} from "./adapters/adapterSet";
|
import {
|
||||||
|
StaticExplorerAdapterSet,
|
||||||
|
DynamicExplorerAdapterSet,
|
||||||
|
} from "./adapters/explorerAdapterSet";
|
||||||
import type {WeightedTypes} from "../analysis/weights";
|
import type {WeightedTypes} from "../analysis/weights";
|
||||||
import {weightsToEdgeEvaluator} from "../analysis/weightsToEdgeEvaluator";
|
import {weightsToEdgeEvaluator} from "../analysis/weightsToEdgeEvaluator";
|
||||||
|
|
||||||
|
@ -67,11 +70,11 @@ export function createStateTransitionMachine(
|
||||||
|
|
||||||
// Exported for testing purposes.
|
// Exported for testing purposes.
|
||||||
export interface StateTransitionMachineInterface {
|
export interface StateTransitionMachineInterface {
|
||||||
+loadGraph: (Assets, StaticAdapterSet) => Promise<boolean>;
|
+loadGraph: (Assets, StaticExplorerAdapterSet) => Promise<boolean>;
|
||||||
+runPagerank: (WeightedTypes, NodeAddressT) => Promise<void>;
|
+runPagerank: (WeightedTypes, NodeAddressT) => Promise<void>;
|
||||||
+loadGraphAndRunPagerank: (
|
+loadGraphAndRunPagerank: (
|
||||||
Assets,
|
Assets,
|
||||||
StaticAdapterSet,
|
StaticExplorerAdapterSet,
|
||||||
WeightedTypes,
|
WeightedTypes,
|
||||||
NodeAddressT
|
NodeAddressT
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
@ -85,7 +88,7 @@ export class StateTransitionMachine implements StateTransitionMachineInterface {
|
||||||
setState: (AppState) => void;
|
setState: (AppState) => void;
|
||||||
loadGraphWithAdapters: (
|
loadGraphWithAdapters: (
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
adapters: StaticAdapterSet,
|
adapters: StaticExplorerAdapterSet,
|
||||||
repoId: RepoId
|
repoId: RepoId
|
||||||
) => Promise<GraphWithAdapters>;
|
) => Promise<GraphWithAdapters>;
|
||||||
pagerank: (
|
pagerank: (
|
||||||
|
@ -99,7 +102,7 @@ export class StateTransitionMachine implements StateTransitionMachineInterface {
|
||||||
setState: (AppState) => void,
|
setState: (AppState) => void,
|
||||||
loadGraphWithAdapters: (
|
loadGraphWithAdapters: (
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
adapters: StaticAdapterSet,
|
adapters: StaticExplorerAdapterSet,
|
||||||
repoId: RepoId
|
repoId: RepoId
|
||||||
) => Promise<GraphWithAdapters>,
|
) => Promise<GraphWithAdapters>,
|
||||||
pagerank: (
|
pagerank: (
|
||||||
|
@ -117,7 +120,7 @@ export class StateTransitionMachine implements StateTransitionMachineInterface {
|
||||||
/** Loads the graph, reports whether it was successful */
|
/** Loads the graph, reports whether it was successful */
|
||||||
async loadGraph(
|
async loadGraph(
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
adapters: StaticAdapterSet
|
adapters: StaticExplorerAdapterSet
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const state = this.getState();
|
const state = this.getState();
|
||||||
if (state.type !== "READY_TO_LOAD_GRAPH") {
|
if (state.type !== "READY_TO_LOAD_GRAPH") {
|
||||||
|
@ -202,7 +205,7 @@ export class StateTransitionMachine implements StateTransitionMachineInterface {
|
||||||
|
|
||||||
async loadGraphAndRunPagerank(
|
async loadGraphAndRunPagerank(
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
adapters: StaticAdapterSet,
|
adapters: StaticExplorerAdapterSet,
|
||||||
weightedTypes: WeightedTypes,
|
weightedTypes: WeightedTypes,
|
||||||
totalScoreNodePrefix: NodeAddressT
|
totalScoreNodePrefix: NodeAddressT
|
||||||
) {
|
) {
|
||||||
|
@ -227,11 +230,11 @@ export class StateTransitionMachine implements StateTransitionMachineInterface {
|
||||||
|
|
||||||
export type GraphWithAdapters = {|
|
export type GraphWithAdapters = {|
|
||||||
+graph: Graph,
|
+graph: Graph,
|
||||||
+adapters: DynamicAdapterSet,
|
+adapters: DynamicExplorerAdapterSet,
|
||||||
|};
|
|};
|
||||||
export async function loadGraphWithAdapters(
|
export async function loadGraphWithAdapters(
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
adapters: StaticAdapterSet,
|
adapters: StaticExplorerAdapterSet,
|
||||||
repoId: RepoId
|
repoId: RepoId
|
||||||
): Promise<GraphWithAdapters> {
|
): Promise<GraphWithAdapters> {
|
||||||
const dynamicAdapters = await adapters.load(assets, repoId);
|
const dynamicAdapters = await adapters.load(assets, repoId);
|
||||||
|
|
|
@ -12,12 +12,15 @@ import {makeRepoId, type RepoId} from "../core/repoId";
|
||||||
import {type EdgeEvaluator} from "../analysis/pagerank";
|
import {type EdgeEvaluator} from "../analysis/pagerank";
|
||||||
import type {WeightedTypes} from "../analysis/weights";
|
import type {WeightedTypes} from "../analysis/weights";
|
||||||
import {defaultWeightsForAdapterSet} from "./weights/weights";
|
import {defaultWeightsForAdapterSet} from "./weights/weights";
|
||||||
import {StaticAdapterSet, DynamicAdapterSet} from "./adapters/adapterSet";
|
import {
|
||||||
|
StaticExplorerAdapterSet,
|
||||||
|
DynamicExplorerAdapterSet,
|
||||||
|
} from "./adapters/explorerAdapterSet";
|
||||||
import type {
|
import type {
|
||||||
PagerankNodeDecomposition,
|
PagerankNodeDecomposition,
|
||||||
PagerankOptions,
|
PagerankOptions,
|
||||||
} from "../analysis/pagerank";
|
} from "../analysis/pagerank";
|
||||||
import {staticAdapterSet} from "../plugins/demo/appAdapter";
|
import {staticExplorerAdapterSet} from "../plugins/demo/explorerAdapter";
|
||||||
|
|
||||||
describe("explorer/state", () => {
|
describe("explorer/state", () => {
|
||||||
function example(startingState: AppState) {
|
function example(startingState: AppState) {
|
||||||
|
@ -28,7 +31,7 @@ describe("explorer/state", () => {
|
||||||
};
|
};
|
||||||
const loadGraphMock: (
|
const loadGraphMock: (
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
adapters: StaticAdapterSet,
|
adapters: StaticExplorerAdapterSet,
|
||||||
repoId: RepoId
|
repoId: RepoId
|
||||||
) => Promise<GraphWithAdapters> = jest.fn();
|
) => Promise<GraphWithAdapters> = jest.fn();
|
||||||
const pagerankMock: (
|
const pagerankMock: (
|
||||||
|
@ -69,12 +72,15 @@ describe("explorer/state", () => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function weightedTypes(): WeightedTypes {
|
function weightedTypes(): WeightedTypes {
|
||||||
return defaultWeightsForAdapterSet(staticAdapterSet());
|
return defaultWeightsForAdapterSet(staticExplorerAdapterSet());
|
||||||
}
|
}
|
||||||
function graphWithAdapters(): GraphWithAdapters {
|
function graphWithAdapters(): GraphWithAdapters {
|
||||||
return {
|
return {
|
||||||
graph: new Graph(),
|
graph: new Graph(),
|
||||||
adapters: new DynamicAdapterSet(new StaticAdapterSet([]), []),
|
adapters: new DynamicExplorerAdapterSet(
|
||||||
|
new StaticExplorerAdapterSet([]),
|
||||||
|
[]
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function pagerankNodeDecomposition() {
|
function pagerankNodeDecomposition() {
|
||||||
|
@ -90,7 +96,10 @@ describe("explorer/state", () => {
|
||||||
for (const b of badStates) {
|
for (const b of badStates) {
|
||||||
const {stm} = example(b);
|
const {stm} = example(b);
|
||||||
await expect(
|
await expect(
|
||||||
stm.loadGraph(new Assets("/my/gateway/"), new StaticAdapterSet([]))
|
stm.loadGraph(
|
||||||
|
new Assets("/my/gateway/"),
|
||||||
|
new StaticExplorerAdapterSet([])
|
||||||
|
)
|
||||||
).rejects.toThrow("incorrect state");
|
).rejects.toThrow("incorrect state");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -98,7 +107,7 @@ describe("explorer/state", () => {
|
||||||
const {stm, loadGraphMock} = example(readyToLoadGraph());
|
const {stm, loadGraphMock} = example(readyToLoadGraph());
|
||||||
expect(loadGraphMock).toHaveBeenCalledTimes(0);
|
expect(loadGraphMock).toHaveBeenCalledTimes(0);
|
||||||
const assets = new Assets("/my/gateway/");
|
const assets = new Assets("/my/gateway/");
|
||||||
const adapters = new StaticAdapterSet([]);
|
const adapters = new StaticExplorerAdapterSet([]);
|
||||||
stm.loadGraph(assets, adapters);
|
stm.loadGraph(assets, adapters);
|
||||||
expect(loadGraphMock).toHaveBeenCalledTimes(1);
|
expect(loadGraphMock).toHaveBeenCalledTimes(1);
|
||||||
expect(loadGraphMock).toHaveBeenCalledWith(
|
expect(loadGraphMock).toHaveBeenCalledWith(
|
||||||
|
@ -110,7 +119,10 @@ describe("explorer/state", () => {
|
||||||
it("immediately sets loading status", () => {
|
it("immediately sets loading status", () => {
|
||||||
const {getState, stm} = example(readyToLoadGraph());
|
const {getState, stm} = example(readyToLoadGraph());
|
||||||
expect(loading(getState())).toBe("NOT_LOADING");
|
expect(loading(getState())).toBe("NOT_LOADING");
|
||||||
stm.loadGraph(new Assets("/my/gateway/"), new StaticAdapterSet([]));
|
stm.loadGraph(
|
||||||
|
new Assets("/my/gateway/"),
|
||||||
|
new StaticExplorerAdapterSet([])
|
||||||
|
);
|
||||||
expect(loading(getState())).toBe("LOADING");
|
expect(loading(getState())).toBe("LOADING");
|
||||||
expect(getState().type).toBe("READY_TO_LOAD_GRAPH");
|
expect(getState().type).toBe("READY_TO_LOAD_GRAPH");
|
||||||
});
|
});
|
||||||
|
@ -120,7 +132,7 @@ describe("explorer/state", () => {
|
||||||
loadGraphMock.mockResolvedValue(gwa);
|
loadGraphMock.mockResolvedValue(gwa);
|
||||||
const succeeded = await stm.loadGraph(
|
const succeeded = await stm.loadGraph(
|
||||||
new Assets("/my/gateway/"),
|
new Assets("/my/gateway/"),
|
||||||
new StaticAdapterSet([])
|
new StaticExplorerAdapterSet([])
|
||||||
);
|
);
|
||||||
expect(succeeded).toBe(true);
|
expect(succeeded).toBe(true);
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -139,7 +151,7 @@ describe("explorer/state", () => {
|
||||||
loadGraphMock.mockRejectedValue(error);
|
loadGraphMock.mockRejectedValue(error);
|
||||||
const succeeded = await stm.loadGraph(
|
const succeeded = await stm.loadGraph(
|
||||||
new Assets("/my/gateway/"),
|
new Assets("/my/gateway/"),
|
||||||
new StaticAdapterSet([])
|
new StaticExplorerAdapterSet([])
|
||||||
);
|
);
|
||||||
expect(succeeded).toBe(false);
|
expect(succeeded).toBe(false);
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -208,7 +220,7 @@ describe("explorer/state", () => {
|
||||||
(stm: any).runPagerank = jest.fn();
|
(stm: any).runPagerank = jest.fn();
|
||||||
stm.loadGraph.mockResolvedValue(true);
|
stm.loadGraph.mockResolvedValue(true);
|
||||||
const assets = new Assets("/gateway/");
|
const assets = new Assets("/gateway/");
|
||||||
const adapters = new StaticAdapterSet([]);
|
const adapters = new StaticExplorerAdapterSet([]);
|
||||||
const prefix = NodeAddress.fromParts(["bar"]);
|
const prefix = NodeAddress.fromParts(["bar"]);
|
||||||
const wt = weightedTypes();
|
const wt = weightedTypes();
|
||||||
await stm.loadGraphAndRunPagerank(assets, adapters, wt, prefix);
|
await stm.loadGraphAndRunPagerank(assets, adapters, wt, prefix);
|
||||||
|
@ -223,7 +235,7 @@ describe("explorer/state", () => {
|
||||||
(stm: any).runPagerank = jest.fn();
|
(stm: any).runPagerank = jest.fn();
|
||||||
stm.loadGraph.mockResolvedValue(false);
|
stm.loadGraph.mockResolvedValue(false);
|
||||||
const assets = new Assets("/gateway/");
|
const assets = new Assets("/gateway/");
|
||||||
const adapters = new StaticAdapterSet([]);
|
const adapters = new StaticExplorerAdapterSet([]);
|
||||||
const prefix = NodeAddress.fromParts(["bar"]);
|
const prefix = NodeAddress.fromParts(["bar"]);
|
||||||
await stm.loadGraphAndRunPagerank(
|
await stm.loadGraphAndRunPagerank(
|
||||||
assets,
|
assets,
|
||||||
|
@ -242,7 +254,7 @@ describe("explorer/state", () => {
|
||||||
const wt = weightedTypes();
|
const wt = weightedTypes();
|
||||||
await stm.loadGraphAndRunPagerank(
|
await stm.loadGraphAndRunPagerank(
|
||||||
new Assets("/gateway/"),
|
new Assets("/gateway/"),
|
||||||
new StaticAdapterSet([]),
|
new StaticExplorerAdapterSet([]),
|
||||||
wt,
|
wt,
|
||||||
prefix
|
prefix
|
||||||
);
|
);
|
||||||
|
@ -258,7 +270,7 @@ describe("explorer/state", () => {
|
||||||
const wt = weightedTypes();
|
const wt = weightedTypes();
|
||||||
await stm.loadGraphAndRunPagerank(
|
await stm.loadGraphAndRunPagerank(
|
||||||
new Assets("/gateway/"),
|
new Assets("/gateway/"),
|
||||||
new StaticAdapterSet([]),
|
new StaticExplorerAdapterSet([]),
|
||||||
wt,
|
wt,
|
||||||
prefix
|
prefix
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import deepEqual from "lodash.isequal";
|
||||||
import * as MapUtil from "../../util/map";
|
import * as MapUtil from "../../util/map";
|
||||||
import {NodeTypeConfig} from "./NodeTypeConfig";
|
import {NodeTypeConfig} from "./NodeTypeConfig";
|
||||||
import {EdgeTypeConfig} from "./EdgeTypeConfig";
|
import {EdgeTypeConfig} from "./EdgeTypeConfig";
|
||||||
import {StaticAppAdapter} from "../adapters/appAdapter";
|
import {StaticExplorerAdapter} from "../adapters/explorerAdapter";
|
||||||
import {styledVariable} from "./EdgeTypeConfig";
|
import {styledVariable} from "./EdgeTypeConfig";
|
||||||
import type {
|
import type {
|
||||||
WeightedTypes,
|
WeightedTypes,
|
||||||
|
@ -14,7 +14,7 @@ import type {
|
||||||
} from "../../analysis/weights";
|
} from "../../analysis/weights";
|
||||||
|
|
||||||
export type Props = {|
|
export type Props = {|
|
||||||
+adapter: StaticAppAdapter,
|
+adapter: StaticExplorerAdapter,
|
||||||
+onChange: (WeightedTypes) => void,
|
+onChange: (WeightedTypes) => void,
|
||||||
+weightedTypes: WeightedTypes,
|
+weightedTypes: WeightedTypes,
|
||||||
|};
|
|};
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
inserterNodeType,
|
inserterNodeType,
|
||||||
assemblesEdgeType,
|
assemblesEdgeType,
|
||||||
} from "../../plugins/demo/declaration";
|
} from "../../plugins/demo/declaration";
|
||||||
import {FactorioStaticAdapter} from "../../plugins/demo/appAdapter";
|
import {FactorioStaticAdapter} from "../../plugins/demo/explorerAdapter";
|
||||||
import {
|
import {
|
||||||
fallbackNodeType,
|
fallbackNodeType,
|
||||||
fallbackEdgeType,
|
fallbackEdgeType,
|
||||||
|
|
|
@ -4,13 +4,13 @@ import React, {type Node as ReactNode} from "react";
|
||||||
import * as NullUtil from "../../util/null";
|
import * as NullUtil from "../../util/null";
|
||||||
import * as MapUtil from "../../util/map";
|
import * as MapUtil from "../../util/map";
|
||||||
|
|
||||||
import type {StaticAdapterSet} from "../adapters/adapterSet";
|
import type {StaticExplorerAdapterSet} from "../adapters/explorerAdapterSet";
|
||||||
import type {WeightedTypes} from "../../analysis/weights";
|
import type {WeightedTypes} from "../../analysis/weights";
|
||||||
import {PluginWeightConfig} from "./PluginWeightConfig";
|
import {PluginWeightConfig} from "./PluginWeightConfig";
|
||||||
import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration";
|
import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration";
|
||||||
|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
+adapters: StaticAdapterSet,
|
+adapters: StaticExplorerAdapterSet,
|
||||||
+weightedTypes: WeightedTypes,
|
+weightedTypes: WeightedTypes,
|
||||||
+onChange: (WeightedTypes) => void,
|
+onChange: (WeightedTypes) => void,
|
||||||
|};
|
|};
|
||||||
|
|
|
@ -5,8 +5,8 @@ import {shallow} from "enzyme";
|
||||||
import {PluginWeightConfig} from "./PluginWeightConfig";
|
import {PluginWeightConfig} from "./PluginWeightConfig";
|
||||||
import {
|
import {
|
||||||
FactorioStaticAdapter,
|
FactorioStaticAdapter,
|
||||||
staticAdapterSet,
|
staticExplorerAdapterSet,
|
||||||
} from "../../plugins/demo/appAdapter";
|
} from "../../plugins/demo/explorerAdapter";
|
||||||
import {inserterNodeType} from "../../plugins/demo/declaration";
|
import {inserterNodeType} from "../../plugins/demo/declaration";
|
||||||
import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration";
|
import {FALLBACK_NAME} from "../../analysis/fallbackDeclaration";
|
||||||
import {defaultWeightsForAdapterSet, defaultWeightsForAdapter} from "./weights";
|
import {defaultWeightsForAdapterSet, defaultWeightsForAdapter} from "./weights";
|
||||||
|
@ -18,7 +18,7 @@ describe("explorer/weights/WeightConfig", () => {
|
||||||
describe("WeightConfig", () => {
|
describe("WeightConfig", () => {
|
||||||
function example() {
|
function example() {
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
const adapters = staticAdapterSet();
|
const adapters = staticExplorerAdapterSet();
|
||||||
const types = defaultWeightsForAdapterSet(adapters);
|
const types = defaultWeightsForAdapterSet(adapters);
|
||||||
types.nodes.set(inserterNodeType.prefix, {
|
types.nodes.set(inserterNodeType.prefix, {
|
||||||
weight: 707,
|
weight: 707,
|
||||||
|
@ -76,7 +76,7 @@ describe("explorer/weights/WeightConfig", () => {
|
||||||
type: inserterNodeType,
|
type: inserterNodeType,
|
||||||
});
|
});
|
||||||
const expectedFullWeights = defaultWeightsForAdapterSet(
|
const expectedFullWeights = defaultWeightsForAdapterSet(
|
||||||
staticAdapterSet()
|
staticExplorerAdapterSet()
|
||||||
);
|
);
|
||||||
expectedFullWeights.nodes.set(inserterNodeType.prefix, {
|
expectedFullWeights.nodes.set(inserterNodeType.prefix, {
|
||||||
weight: 955,
|
weight: 955,
|
||||||
|
|
|
@ -5,17 +5,17 @@ import {
|
||||||
combineWeights,
|
combineWeights,
|
||||||
defaultWeightsForDeclaration,
|
defaultWeightsForDeclaration,
|
||||||
} from "../../analysis/weights";
|
} from "../../analysis/weights";
|
||||||
import type {StaticAppAdapter} from "../adapters/appAdapter";
|
import type {StaticExplorerAdapter} from "../adapters/explorerAdapter";
|
||||||
import type {StaticAdapterSet} from "../adapters/adapterSet";
|
import type {StaticExplorerAdapterSet} from "../adapters/explorerAdapterSet";
|
||||||
|
|
||||||
export function defaultWeightsForAdapter(
|
export function defaultWeightsForAdapter(
|
||||||
adapter: StaticAppAdapter
|
adapter: StaticExplorerAdapter
|
||||||
): WeightedTypes {
|
): WeightedTypes {
|
||||||
return defaultWeightsForDeclaration(adapter.declaration());
|
return defaultWeightsForDeclaration(adapter.declaration());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defaultWeightsForAdapterSet(
|
export function defaultWeightsForAdapterSet(
|
||||||
adapters: StaticAdapterSet
|
adapters: StaticExplorerAdapterSet
|
||||||
): WeightedTypes {
|
): WeightedTypes {
|
||||||
return combineWeights(adapters.adapters().map(defaultWeightsForAdapter));
|
return combineWeights(adapters.adapters().map(defaultWeightsForAdapter));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import {
|
||||||
import {declaration} from "../../plugins/demo/declaration";
|
import {declaration} from "../../plugins/demo/declaration";
|
||||||
import {
|
import {
|
||||||
FactorioStaticAdapter,
|
FactorioStaticAdapter,
|
||||||
staticAdapterSet,
|
staticExplorerAdapterSet,
|
||||||
} from "../../plugins/demo/appAdapter";
|
} from "../../plugins/demo/explorerAdapter";
|
||||||
|
|
||||||
describe("explorer/weights/weights", () => {
|
describe("explorer/weights/weights", () => {
|
||||||
describe("defaultWeightsForAdapter", () => {
|
describe("defaultWeightsForAdapter", () => {
|
||||||
|
@ -22,9 +22,9 @@ describe("explorer/weights/weights", () => {
|
||||||
|
|
||||||
describe("defaultWeightsForAdapterSet", () => {
|
describe("defaultWeightsForAdapterSet", () => {
|
||||||
it("works on a demo adapter set", () => {
|
it("works on a demo adapter set", () => {
|
||||||
expect(defaultWeightsForAdapterSet(staticAdapterSet())).toEqual(
|
expect(defaultWeightsForAdapterSet(staticExplorerAdapterSet())).toEqual(
|
||||||
combineWeights(
|
combineWeights(
|
||||||
staticAdapterSet()
|
staticExplorerAdapterSet()
|
||||||
.adapters()
|
.adapters()
|
||||||
.map(defaultWeightsForAdapter)
|
.map(defaultWeightsForAdapter)
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import type {Assets} from "../webutil/assets";
|
import type {Assets} from "../webutil/assets";
|
||||||
import {StaticAdapterSet} from "../explorer/adapters/adapterSet";
|
import {StaticExplorerAdapterSet} from "../explorer/adapters/explorerAdapterSet";
|
||||||
import {StaticAppAdapter as GithubAdapter} from "../plugins/github/appAdapter";
|
import {StaticExplorerAdapter as GithubAdapter} from "../plugins/github/explorerAdapter";
|
||||||
import {StaticAppAdapter as GitAdapter} from "../plugins/git/appAdapter";
|
import {StaticExplorerAdapter as GitAdapter} from "../plugins/git/explorerAdapter";
|
||||||
import {GithubGitGateway} from "../plugins/github/githubGitGateway";
|
import {GithubGitGateway} from "../plugins/github/githubGitGateway";
|
||||||
import {AppPage} from "../explorer/App";
|
import {AppPage} from "../explorer/App";
|
||||||
import type {RepoId} from "../core/repoId";
|
import type {RepoId} from "../core/repoId";
|
||||||
|
|
||||||
function homepageStaticAdapters(): StaticAdapterSet {
|
function homepageStaticAdapters(): StaticExplorerAdapterSet {
|
||||||
return new StaticAdapterSet([
|
return new StaticExplorerAdapterSet([
|
||||||
new GithubAdapter(),
|
new GithubAdapter(),
|
||||||
new GitAdapter(new GithubGitGateway()),
|
new GitAdapter(new GithubGitGateway()),
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
||||||
import {declaration} from "./declaration";
|
import {declaration} from "./declaration";
|
||||||
import type {
|
import type {
|
||||||
StaticAppAdapter,
|
StaticExplorerAdapter,
|
||||||
DynamicAppAdapter,
|
DynamicExplorerAdapter,
|
||||||
} from "../../explorer/adapters/appAdapter";
|
} from "../../explorer/adapters/explorerAdapter";
|
||||||
import {StaticAdapterSet} from "../../explorer/adapters/adapterSet";
|
import {StaticExplorerAdapterSet} from "../../explorer/adapters/explorerAdapterSet";
|
||||||
import {Assets} from "../../webutil/assets";
|
import {Assets} from "../../webutil/assets";
|
||||||
import {type RepoId, makeRepoId} from "../../core/repoId";
|
import {type RepoId, makeRepoId} from "../../core/repoId";
|
||||||
import {NodeAddress, type NodeAddressT} from "../../core/graph";
|
import {NodeAddress, type NodeAddressT} from "../../core/graph";
|
||||||
import {graph} from "./graph";
|
import {graph} from "./graph";
|
||||||
|
|
||||||
export class FactorioStaticAdapter implements StaticAppAdapter {
|
export class FactorioStaticAdapter implements StaticExplorerAdapter {
|
||||||
loadingMock: (assets: Assets, repoId: RepoId) => Promise<mixed>;
|
loadingMock: (assets: Assets, repoId: RepoId) => Promise<mixed>;
|
||||||
declaration(): PluginDeclaration {
|
declaration(): PluginDeclaration {
|
||||||
return declaration;
|
return declaration;
|
||||||
|
@ -26,7 +26,7 @@ export class FactorioStaticAdapter implements StaticAppAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FactorioDynamicAdapter implements DynamicAppAdapter {
|
export class FactorioDynamicAdapter implements DynamicExplorerAdapter {
|
||||||
graph() {
|
graph() {
|
||||||
return graph();
|
return graph();
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,12 @@ export class FactorioDynamicAdapter implements DynamicAppAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function staticAdapterSet() {
|
export function staticExplorerAdapterSet() {
|
||||||
return new StaticAdapterSet([new FactorioStaticAdapter()]);
|
return new StaticExplorerAdapterSet([new FactorioStaticAdapter()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dynamicAdapterSet() {
|
export async function dynamicExplorerAdapterSet() {
|
||||||
return await staticAdapterSet().load(
|
return await staticExplorerAdapterSet().load(
|
||||||
new Assets("/gateway/"),
|
new Assets("/gateway/"),
|
||||||
makeRepoId("foo", "bar")
|
makeRepoId("foo", "bar")
|
||||||
);
|
);
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
import type {
|
import type {
|
||||||
StaticAppAdapter as IStaticAppAdapter,
|
StaticExplorerAdapter as IStaticExplorerAdapter,
|
||||||
DynamicAppAdapter as IDynamicAppAdapter,
|
DynamicExplorerAdapter as IDynamicExplorerAdapter,
|
||||||
} from "../../explorer/adapters/appAdapter";
|
} from "../../explorer/adapters/explorerAdapter";
|
||||||
import {Graph} from "../../core/graph";
|
import {Graph} from "../../core/graph";
|
||||||
import * as N from "./nodes";
|
import * as N from "./nodes";
|
||||||
import {description} from "./render";
|
import {description} from "./render";
|
||||||
|
@ -13,7 +13,7 @@ import type {GitGateway} from "./gitGateway";
|
||||||
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
||||||
import {declaration} from "./declaration";
|
import {declaration} from "./declaration";
|
||||||
|
|
||||||
export class StaticAppAdapter implements IStaticAppAdapter {
|
export class StaticExplorerAdapter implements IStaticExplorerAdapter {
|
||||||
_gitGateway: GitGateway;
|
_gitGateway: GitGateway;
|
||||||
|
|
||||||
constructor(gg: GitGateway): void {
|
constructor(gg: GitGateway): void {
|
||||||
|
@ -22,7 +22,7 @@ export class StaticAppAdapter implements IStaticAppAdapter {
|
||||||
declaration(): PluginDeclaration {
|
declaration(): PluginDeclaration {
|
||||||
return declaration;
|
return declaration;
|
||||||
}
|
}
|
||||||
async load(assets: Assets, repoId: RepoId): Promise<IDynamicAppAdapter> {
|
async load(assets: Assets, repoId: RepoId): Promise<IDynamicExplorerAdapter> {
|
||||||
const baseUrl = `/api/v1/data/data/${repoId.owner}/${repoId.name}/git/`;
|
const baseUrl = `/api/v1/data/data/${repoId.owner}/${repoId.name}/git/`;
|
||||||
async function loadGraph() {
|
async function loadGraph() {
|
||||||
const url = assets.resolve(baseUrl + "graph.json");
|
const url = assets.resolve(baseUrl + "graph.json");
|
||||||
|
@ -45,11 +45,11 @@ export class StaticAppAdapter implements IStaticAppAdapter {
|
||||||
loadGraph(),
|
loadGraph(),
|
||||||
loadRepository(),
|
loadRepository(),
|
||||||
]);
|
]);
|
||||||
return new DynamicAppAdapter(this._gitGateway, graph, repository);
|
return new DynamicExplorerAdapter(this._gitGateway, graph, repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicAppAdapter implements IDynamicAppAdapter {
|
class DynamicExplorerAdapter implements IDynamicExplorerAdapter {
|
||||||
+_graph: Graph;
|
+_graph: Graph;
|
||||||
+_repository: Repository;
|
+_repository: Repository;
|
||||||
+_gitGateway: GitGateway;
|
+_gitGateway: GitGateway;
|
||||||
|
@ -72,6 +72,6 @@ class DynamicAppAdapter implements IDynamicAppAdapter {
|
||||||
return description(address, this._repository, this._gitGateway);
|
return description(address, this._repository, this._gitGateway);
|
||||||
}
|
}
|
||||||
static() {
|
static() {
|
||||||
return new StaticAppAdapter(this._gitGateway);
|
return new StaticExplorerAdapter(this._gitGateway);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,9 +2,9 @@
|
||||||
import pako from "pako";
|
import pako from "pako";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
StaticAppAdapter as IStaticAppAdapter,
|
StaticExplorerAdapter as IStaticExplorerAdapter,
|
||||||
DynamicAppAdapter as IDynamicAppAdapter,
|
DynamicExplorerAdapter as IDynamicExplorerAdapter,
|
||||||
} from "../../explorer/adapters/appAdapter";
|
} from "../../explorer/adapters/explorerAdapter";
|
||||||
import {type Graph, NodeAddress} from "../../core/graph";
|
import {type Graph, NodeAddress} from "../../core/graph";
|
||||||
import {createGraph} from "./createGraph";
|
import {createGraph} from "./createGraph";
|
||||||
import * as N from "./nodes";
|
import * as N from "./nodes";
|
||||||
|
@ -15,11 +15,11 @@ import type {RepoId} from "../../core/repoId";
|
||||||
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
|
||||||
import {declaration} from "./declaration";
|
import {declaration} from "./declaration";
|
||||||
|
|
||||||
export class StaticAppAdapter implements IStaticAppAdapter {
|
export class StaticExplorerAdapter implements IStaticExplorerAdapter {
|
||||||
declaration(): PluginDeclaration {
|
declaration(): PluginDeclaration {
|
||||||
return declaration;
|
return declaration;
|
||||||
}
|
}
|
||||||
async load(assets: Assets, repoId: RepoId): Promise<IDynamicAppAdapter> {
|
async load(assets: Assets, repoId: RepoId): Promise<IDynamicExplorerAdapter> {
|
||||||
const url = assets.resolve(
|
const url = assets.resolve(
|
||||||
`/api/v1/data/data/${repoId.owner}/${repoId.name}/github/view.json.gz`
|
`/api/v1/data/data/${repoId.owner}/${repoId.name}/github/view.json.gz`
|
||||||
);
|
);
|
||||||
|
@ -32,11 +32,11 @@ export class StaticAppAdapter implements IStaticAppAdapter {
|
||||||
const json = JSON.parse(pako.ungzip(blob, {to: "string"}));
|
const json = JSON.parse(pako.ungzip(blob, {to: "string"}));
|
||||||
const view = RelationalView.fromJSON(json);
|
const view = RelationalView.fromJSON(json);
|
||||||
const graph = createGraph(view);
|
const graph = createGraph(view);
|
||||||
return new DynamicAppAdapter(view, graph);
|
return new DynamicExplorerAdapter(view, graph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicAppAdapter implements IDynamicAppAdapter {
|
class DynamicExplorerAdapter implements IDynamicExplorerAdapter {
|
||||||
+_view: RelationalView;
|
+_view: RelationalView;
|
||||||
+_graph: Graph;
|
+_graph: Graph;
|
||||||
constructor(view: RelationalView, graph: Graph): void {
|
constructor(view: RelationalView, graph: Graph): void {
|
||||||
|
@ -57,6 +57,6 @@ class DynamicAppAdapter implements IDynamicAppAdapter {
|
||||||
return this._graph;
|
return this._graph;
|
||||||
}
|
}
|
||||||
static() {
|
static() {
|
||||||
return new StaticAppAdapter();
|
return new StaticExplorerAdapter();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue