-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up Grain Integration support in Config API
- Loading branch information
Showing
9 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @flow | ||
|
||
import type {GrainIntegrationFunction} from "../core/ledger/grainIntegration"; | ||
import * as C from "../util/combo"; | ||
|
||
import {csvIntegration} from "sc-grainIntegration-csv"; | ||
|
||
export type GrainIntegration = {| | ||
name: string, | ||
function: GrainIntegrationFunction, | ||
|}; | ||
|
||
type AllowedDeclarations = {[pluginKey: string]: GrainIntegrationFunction}; | ||
|
||
const allowedDeclarations: AllowedDeclarations = { | ||
"csv": csvIntegration, | ||
}; | ||
|
||
export function bundledGrainIntegrations( | ||
integrationKey: string | ||
): GrainIntegrationFunction { | ||
const integration = allowedDeclarations[integrationKey]; | ||
if (!integration) | ||
throw new Error( | ||
"grain integration not found; enter a valid `integration` value in config/grain.json" | ||
); | ||
return integration; | ||
} | ||
|
||
export const parser: C.Parser<GrainIntegration> = C.fmap( | ||
C.exactly(["csv"]), | ||
(integrationKey) => ({ | ||
name: integrationKey, | ||
function: bundledGrainIntegrations(integrationKey), | ||
}) | ||
); |
14 changes: 14 additions & 0 deletions
14
packages/sourcecred/src/api/bundledGrainIntegrations.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @flow | ||
|
||
import {bundledGrainIntegrations} from "./bundledGrainIntegrations"; | ||
import {csvIntegration} from "sc-grainIntegration-csv"; | ||
describe("api/bundledGrainIntegrations", () => { | ||
it("returns the csv parser", () => { | ||
const result = bundledGrainIntegrations("csv"); | ||
expect(result).toBe(csvIntegration); | ||
}); | ||
it("errors if integration lookup fails", () => { | ||
const thunk = () => bundledGrainIntegrations("badKey"); | ||
expect(thunk).toThrow("grain integration not found"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters