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
This commit is contained in:
Dandelion Mané 2019-10-11 13:40:10 -06:00 committed by GitHub
parent 5e02a2caeb
commit eb008f40cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 25 deletions

View File

@ -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);
}

View File

@ -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}/`;

View File

@ -14,9 +14,10 @@ import {
topicContainsPostEdge,
postRepliesEdge,
likesEdge,
userAddress,
postAddress,
} from "./createGraph";
import {userAddress, postAddress} from "./address";
import {
userNodeType,
topicNodeType,

View File

@ -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.
*

View File

@ -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", () => {