Do not use internal and actual values anymore (Fixes #42)
This commit is contained in:
parent
b40f4a774e
commit
c0117fa7d6
13 changed files with 421 additions and 393 deletions
|
|
@ -1,8 +1,21 @@
|
|||
// @flow
|
||||
import type { TopicType } from "config/flowtypes";
|
||||
import at from "lodash/at";
|
||||
|
||||
export const string: TopicType = (msg: Buffer) => msg.toString();
|
||||
|
||||
export const string: TopicType = (msg) => msg.toString();
|
||||
export const json = (path: string, innerType?: TopicType): TopicType => {
|
||||
const parseAgain = innerType == null ? (x) => x : innerType;
|
||||
return (msg) => parseAgain(JSON.parse(msg.toString())[path]);
|
||||
const parseAgain = innerType == null ? (x) => x.toString() : innerType;
|
||||
return (msg) => parseAgain(Buffer.from(
|
||||
at(JSON.parse(msg.toString()), path)[0].toString()));
|
||||
};
|
||||
|
||||
export type TypeOptionParam = { otherwise?: string, [string]: string };
|
||||
export const option = (values: TypeOptionParam): TopicType => {
|
||||
// TODO: error
|
||||
const defaultValue = values.otherwise != null ? values.otherwise : "";
|
||||
const mapVal = (x) => (values[x] != null ? values[x] : defaultValue);
|
||||
return (x) => mapVal(x.toString());
|
||||
};
|
||||
|
||||
export const jsonArray = (msg: Buffer) => JSON.parse(msg.toString()).join(", ");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue