Fix missing prefixes in Discourse plugin (#1309)

Summary:
A `PluginDeclaration` must have a `nodePrefix` and an `edgePrefix`, but
the Discourse plugin declaration was missing these. This was not caught
by Flow because `deep-freeze` was introduced in #1249 without type
definitions; see #1308.

Test Plan:
Apply the following patch:

```diff
diff --git a/src/plugins/discourse/declaration.js b/src/plugins/discourse/declaration.js
index 246a0a28..36ae5f13 100644
--- a/src/plugins/discourse/declaration.js
+++ b/src/plugins/discourse/declaration.js
@@ -1,6 +1,6 @@
 // @flow

-import deepFreeze from "deep-freeze";
+declare function deepFreeze<T>(x: T): T;
 import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
 import type {NodeType, EdgeType} from "../../analysis/types";
 import {NodeAddress, EdgeAddress} from "../../core/graph";
```

Note that, with this patch, `yarn flow` fails before this change but
passes after it. Running `yarn unit` still passes.

wchargin-branch: discourse-plugin-prefixes
This commit is contained in:
William Chargin 2019-08-22 08:52:52 -07:00 committed by GitHub
parent ecd15ed3c4
commit 0367c9e50c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 17 deletions

View File

@ -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,