From eb008f40cc498912cd79682b7a5fd00a2fe4d864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Fri, 11 Oct 2019 13:40:10 -0600 Subject: [PATCH] discourse: factor out address module (#1404) This will make it possible to depend on addresses in the reference module. Test plan: `yarn test` passes. This is progress towards [Discourse reference and mention detection][1]. [1]: https://discourse.sourcecred.io/t/discourse-reference-mention-detection/270 --- src/plugins/discourse/address.js | 17 +++++++++++++++++ src/plugins/discourse/createGraph.js | 23 ++--------------------- src/plugins/discourse/createGraph.test.js | 5 +++-- src/plugins/identity/alias.js | 2 +- src/plugins/identity/alias.test.js | 2 +- 5 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 src/plugins/discourse/address.js diff --git a/src/plugins/discourse/address.js b/src/plugins/discourse/address.js new file mode 100644 index 0000000..4b6a5e0 --- /dev/null +++ b/src/plugins/discourse/address.js @@ -0,0 +1,17 @@ +// @flow + +import {NodeAddress, type NodeAddressT} from "../../core/graph"; + +import {type PostId, type TopicId} from "./fetch"; + +import {topicNodeType, postNodeType, userNodeType} from "./declaration"; + +export function topicAddress(serverUrl: string, id: TopicId): NodeAddressT { + return NodeAddress.append(topicNodeType.prefix, serverUrl, String(id)); +} +export function postAddress(serverUrl: string, id: PostId): NodeAddressT { + return NodeAddress.append(postNodeType.prefix, serverUrl, String(id)); +} +export function userAddress(serverUrl: string, username: string): NodeAddressT { + return NodeAddress.append(userNodeType.prefix, serverUrl, username); +} diff --git a/src/plugins/discourse/createGraph.js b/src/plugins/discourse/createGraph.js index 781ce3e..44e234f 100644 --- a/src/plugins/discourse/createGraph.js +++ b/src/plugins/discourse/createGraph.js @@ -1,13 +1,6 @@ // @flow -import { - Graph, - NodeAddress, - EdgeAddress, - type Node, - type Edge, - type NodeAddressT, -} from "../../core/graph"; +import {Graph, EdgeAddress, type Node, type Edge} from "../../core/graph"; import { type PostId, type TopicId, @@ -17,25 +10,13 @@ import { } from "./fetch"; import {type DiscourseData} from "./mirror"; import { - topicNodeType, - postNodeType, - userNodeType, authorsPostEdgeType, authorsTopicEdgeType, postRepliesEdgeType, topicContainsPostEdgeType, likesEdgeType, } from "./declaration"; - -export function topicAddress(serverUrl: string, id: TopicId): NodeAddressT { - return NodeAddress.append(topicNodeType.prefix, serverUrl, String(id)); -} -export function postAddress(serverUrl: string, id: PostId): NodeAddressT { - return NodeAddress.append(postNodeType.prefix, serverUrl, String(id)); -} -export function userAddress(serverUrl: string, username: string): NodeAddressT { - return NodeAddress.append(userNodeType.prefix, serverUrl, username); -} +import {userAddress, topicAddress, postAddress} from "./address"; export function userNode(serverUrl: string, username: string): Node { const url = `${serverUrl}/u/${username}/`; diff --git a/src/plugins/discourse/createGraph.test.js b/src/plugins/discourse/createGraph.test.js index 4be882b..ee5bd94 100644 --- a/src/plugins/discourse/createGraph.test.js +++ b/src/plugins/discourse/createGraph.test.js @@ -14,9 +14,10 @@ import { topicContainsPostEdge, postRepliesEdge, likesEdge, - userAddress, - postAddress, } from "./createGraph"; + +import {userAddress, postAddress} from "./address"; + import { userNodeType, topicNodeType, diff --git a/src/plugins/identity/alias.js b/src/plugins/identity/alias.js index c516153..f713f20 100644 --- a/src/plugins/identity/alias.js +++ b/src/plugins/identity/alias.js @@ -2,7 +2,7 @@ import {type NodeAddressT} from "../../core/graph"; import {loginAddress as githubAddress} from "../github/nodes"; -import {userAddress as discourseAddress} from "../discourse/createGraph"; +import {userAddress as discourseAddress} from "../discourse/address"; /** An Alias is a string specification of an identity within another plugin. * diff --git a/src/plugins/identity/alias.test.js b/src/plugins/identity/alias.test.js index 118d607..04e41bc 100644 --- a/src/plugins/identity/alias.test.js +++ b/src/plugins/identity/alias.test.js @@ -2,7 +2,7 @@ import {resolveAlias} from "./alias"; import {loginAddress as githubAddress} from "../github/nodes"; -import {userAddress as discourseAddress} from "../discourse/createGraph"; +import {userAddress as discourseAddress} from "../discourse/address"; describe("src/plugins/identity/alias", () => { describe("resolveAlias", () => {