From 1b8a696df3b17070d59ac16388d3b6eca918a0b1 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 21 Mar 2020 09:31:25 +0100 Subject: [PATCH] Open up event type checking --- packages/sdk/src/logs.ts | 15 +++------------ packages/sdk/types/logs.d.ts | 4 +--- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/sdk/src/logs.ts b/packages/sdk/src/logs.ts index 496fe2ca..1db37544 100644 --- a/packages/sdk/src/logs.ts +++ b/packages/sdk/src/logs.ts @@ -1,22 +1,13 @@ /* eslint-disable @typescript-eslint/camelcase */ import { isNonNullObject } from "@iov/encoding"; -const supportedEventTypes: readonly string[] = ["message", "transfer", "wasm"]; - -export type SupportedEventType = "message" | "transfer" | "wasm"; - -export function isSupportedEventType(data: any): data is SupportedEventType { - if (typeof data !== "string") return false; - return supportedEventTypes.includes(data); -} - export interface Attribute { readonly key: string; readonly value: string; } export interface Event { - readonly type: SupportedEventType; + readonly type: string; readonly attributes: readonly Attribute[]; } @@ -43,8 +34,8 @@ export function parseAttribute(input: unknown): Attribute { export function parseEvent(input: unknown): Event { if (!isNonNullObject(input)) throw new Error("Event must be a non-null object"); const { type, attributes } = input as any; - if (!isSupportedEventType(type)) { - throw new Error(`Event type must be one of ${supportedEventTypes.join(", ")}; got ${type}`); + if (typeof type !== "string" || type === "") { + throw new Error(`Event type must be a non-empty string`); } if (!Array.isArray(attributes)) throw new Error("Event's attributes must be an array"); return { diff --git a/packages/sdk/types/logs.d.ts b/packages/sdk/types/logs.d.ts index a84e8276..2e1decb3 100644 --- a/packages/sdk/types/logs.d.ts +++ b/packages/sdk/types/logs.d.ts @@ -1,11 +1,9 @@ -export declare type SupportedEventType = "message" | "transfer" | "wasm"; -export declare function isSupportedEventType(data: any): data is SupportedEventType; export interface Attribute { readonly key: string; readonly value: string; } export interface Event { - readonly type: SupportedEventType; + readonly type: string; readonly attributes: readonly Attribute[]; } export interface Log {