From 9d85a0c77340da9fd815aa18fbfb7c89cc0870f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vilim=20Stubi=C4=8Dan?= Date: Mon, 26 Feb 2018 17:31:11 +0100 Subject: [PATCH] Type definitions for parity-pmd 0.4.0 (#23901) * Type definitions for parity-pmd 0.4.0 * Contributors list update * Removed unnecessary reference to node --- types/parity-pmd/index.d.ts | 27 +++++++++++++++++++++++++++ types/parity-pmd/parity-pmd-tests.ts | 27 +++++++++++++++++++++++++++ types/parity-pmd/tsconfig.json | 23 +++++++++++++++++++++++ types/parity-pmd/tslint.json | 1 + 4 files changed, 78 insertions(+) create mode 100644 types/parity-pmd/index.d.ts create mode 100644 types/parity-pmd/parity-pmd-tests.ts create mode 100644 types/parity-pmd/tsconfig.json create mode 100644 types/parity-pmd/tslint.json diff --git a/types/parity-pmd/index.d.ts b/types/parity-pmd/index.d.ts new file mode 100644 index 0000000000..30b02d72ef --- /dev/null +++ b/types/parity-pmd/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for parity-pmd 0.4 +// Project: https://github.com/paritytrading/node-parity-pmd#readme +// Definitions by: Leonard Vujanić +// Vilim Stubičan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/// + +/** + * Declares Parity PMD message structure + * Full reference can be found here https://github.com/paritytrading/parity/blob/master/libraries/net/doc/PMD.md + */ +export interface PMDMessage { + messageType: string; + version?: string; + timestamp?: number; + orderNumber?: number; + side?: string; + instrument?: string; + quantity?: number; + price?: number; +} + +export function format(message: PMDMessage): Buffer; + +export function parse(buffer: Buffer): PMDMessage; diff --git a/types/parity-pmd/parity-pmd-tests.ts b/types/parity-pmd/parity-pmd-tests.ts new file mode 100644 index 0000000000..3645e7598c --- /dev/null +++ b/types/parity-pmd/parity-pmd-tests.ts @@ -0,0 +1,27 @@ +import { format, parse, PMDMessage } from 'parity-pmd'; + +// Arrange +const buffer = new Buffer(5); +buffer.writeUInt8(0x56, 0); +buffer.writeUInt32BE(70, 1); +const parsedContent: PMDMessage = parse(buffer); + +// Act & Assert +// $ExpectType PMDMessage +parse(buffer); + +// $ExpectType Buffer +format(parsedContent); + +// Invalid type +// $ExpectError +parse(''); + +// $ExpectError +format({}); + +// Invalid sub type +// $ExpectError +format({ + messageType: 1 +}); diff --git a/types/parity-pmd/tsconfig.json b/types/parity-pmd/tsconfig.json new file mode 100644 index 0000000000..92345f62fb --- /dev/null +++ b/types/parity-pmd/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "parity-pmd-tests.ts" + ] +} diff --git a/types/parity-pmd/tslint.json b/types/parity-pmd/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/parity-pmd/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }