diff --git a/src/plugins/discourse/declaration.js b/src/plugins/discourse/declaration.js index fa2584d..4de1eb1 100644 --- a/src/plugins/discourse/declaration.js +++ b/src/plugins/discourse/declaration.js @@ -5,10 +5,13 @@ import type {PluginDeclaration} from "../../analysis/pluginDeclaration"; import type {NodeType, EdgeType} from "../../analysis/types"; import {NodeAddress, EdgeAddress} from "../../core/graph"; +export const nodePrefix = NodeAddress.fromParts(["sourcecred", "discourse"]); +export const edgePrefix = EdgeAddress.fromParts(["sourcecred", "discourse"]); + export const topicNodeType: NodeType = deepFreeze({ name: "Topic", pluralName: "Topics", - prefix: NodeAddress.fromParts(["sourcecred", "discourse", "topic"]), + prefix: NodeAddress.append(nodePrefix, "topic"), defaultWeight: 2, description: "A topic (or post-container) in a Discourse instance. Every topic has at least one post.", @@ -17,7 +20,7 @@ export const topicNodeType: NodeType = deepFreeze({ export const postNodeType: NodeType = deepFreeze({ name: "Post", pluralName: "Posts", - prefix: NodeAddress.fromParts(["sourcecred", "discourse", "post"]), + prefix: NodeAddress.append(nodePrefix, "post"), defaultWeight: 1, description: "A post in some topic in a Discourse instance.", }); @@ -25,7 +28,7 @@ export const postNodeType: NodeType = deepFreeze({ export const userNodeType: NodeType = deepFreeze({ name: "User", pluralName: "Users", - prefix: NodeAddress.fromParts(["sourcecred", "discourse", "user"]), + prefix: NodeAddress.append(nodePrefix, "user"), defaultWeight: 1, description: "A user account on a particular Discourse instance.", }); @@ -33,11 +36,7 @@ export const userNodeType: NodeType = deepFreeze({ export const topicContainsPostEdgeType: EdgeType = deepFreeze({ forwardName: "contains post", backwardName: "is contained by topic", - prefix: EdgeAddress.fromParts([ - "sourcecred", - "discourse", - "topicContainsPost", - ]), + prefix: EdgeAddress.append(edgePrefix, "topicContainsPost"), defaultWeight: {forwards: 1 / 16, backwards: 1 / 4}, description: "Connects a topic to the posts that it contains.", }); @@ -45,7 +44,7 @@ export const topicContainsPostEdgeType: EdgeType = deepFreeze({ export const postRepliesEdgeType: EdgeType = deepFreeze({ forwardName: "post is reply to", backwardName: "post replied to by", - prefix: EdgeAddress.fromParts(["sourcecred", "discourse", "replyTo"]), + prefix: EdgeAddress.append(edgePrefix, "replyTo"), defaultWeight: {forwards: 1, backwards: 1 / 16}, description: "Connects a post to the post that it is a reply to.", }); @@ -53,12 +52,7 @@ export const postRepliesEdgeType: EdgeType = deepFreeze({ export const authorsTopicEdgeType: EdgeType = deepFreeze({ forwardName: "authors topic", backwardName: "topic is authored by", - prefix: EdgeAddress.fromParts([ - "sourcecred", - "discourse", - "authors", - "topic", - ]), + prefix: EdgeAddress.append(edgePrefix, "authors", "topic"), defaultWeight: {forwards: 1 / 4, backwards: 1}, description: "Connects an author to a topic they created.", }); @@ -66,7 +60,7 @@ export const authorsTopicEdgeType: EdgeType = deepFreeze({ export const authorsPostEdgeType: EdgeType = deepFreeze({ forwardName: "authors post", backwardName: "post is authored by", - prefix: EdgeAddress.fromParts(["sourcecred", "discourse", "authors", "post"]), + prefix: EdgeAddress.append(edgePrefix, "authors", "post"), defaultWeight: {forwards: 1 / 4, backwards: 1}, description: "Connects an author to a post they've created.", }); @@ -74,13 +68,15 @@ export const authorsPostEdgeType: EdgeType = deepFreeze({ export const likesEdgeType: EdgeType = deepFreeze({ forwardName: "likes", backwardName: "is liked by", - prefix: EdgeAddress.fromParts(["sourcecred", "discourse", "likes"]), + prefix: EdgeAddress.append(edgePrefix, "likes"), defaultWeight: {forwards: 1, backwards: 1 / 16}, description: "Connects a Discourse user to a post they liked.", }); export const declaration: PluginDeclaration = deepFreeze({ name: "discourse", + nodePrefix, + edgePrefix, nodeTypes: [userNodeType, topicNodeType, postNodeType], edgeTypes: [ postRepliesEdgeType,