From c0bcf54c454e6c26f6d1b7b86dd05baf55aae03f Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Thu, 30 Aug 2018 16:36:17 -0700 Subject: [PATCH] adds typings for the 'mali' package --- types/mali/index.d.ts | 77 ++++++++++++++++++++++++++++++++++++++++ types/mali/mali-tests.ts | 16 +++++++++ types/mali/tsconfig.json | 19 ++++++++++ types/mali/tslint.json | 3 ++ 4 files changed, 115 insertions(+) create mode 100644 types/mali/index.d.ts create mode 100644 types/mali/mali-tests.ts create mode 100644 types/mali/tsconfig.json create mode 100644 types/mali/tslint.json diff --git a/types/mali/index.d.ts b/types/mali/index.d.ts new file mode 100644 index 0000000000..1c73b18c75 --- /dev/null +++ b/types/mali/index.d.ts @@ -0,0 +1,77 @@ +// Type definitions for mali 0.9 +// Project: https://github.com/malijs/mali +// Definitions by: Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import { EventEmitter } from 'events'; +import { Stream } from 'stream'; + +declare class Mali extends EventEmitter { + constructor(path: any, name?: string | ReadonlyArray, options?: any); + name: string; + env: string; + ports: ReadonlyArray; // ? not sure which it is + silent: boolean; + + addService(path: any, name: string | ReadonlyArray, options?: any): void; + use(service?: any, name?: any, fns?: any): void; + start(port?: any, creds?: any, options?: any): any; // gnarly type asserting for these functions so Im just gonna let them handle it. + toJSON(): any; + close(): void; + inspect(): any; +} + +declare namespace Mali { + interface Context { + name: string; + fullName: string; + service: string; + package: string; + app: any; // ? app + call: any; + request: Request; + response: Response; + req: any; // ? + res: any; // ? + type: string; + metadata: string; + get(field: string): any; + set(field: any, val?: any): void; // do I need `?:` if its of type `any`? + sendMetadata(md: any): void; + getStatus(field: string): any; + setStatus(field: any, val?: any): void; // ^ + } + + class Request { + constructor(call: any, type: string); + call: any; + type: string; + metadata: any; + req: any; // ? + + getMetadata(): any; + get(field: string): any; + } + + class Response { + constructor(call: any, type: string); + call: any; + type: string; + metadata: any; + status: any; + res: any; // ? + set(field: any, val?: any): void; // is `val?:` necessary when its of type `any`? + get(field: string): any; + getMetadata(): any; + sendMetadata(md?: any): void; + getStatus(field: string): any; + setStatus(field: any, val?: any): void; // ^ same as above + } + + function exec(ctx: Context, handler: any, cb?: any): void; +} + +export = Mali; diff --git a/types/mali/mali-tests.ts b/types/mali/mali-tests.ts new file mode 100644 index 0000000000..d6d33a263f --- /dev/null +++ b/types/mali/mali-tests.ts @@ -0,0 +1,16 @@ +// example from https://github.com/malijs/mali#example + +import Mali = require('mali'); +import path = require('path'); + +const PROTO_PATH = path.resolve(__dirname, '../protos/helloworld.proto'); + +async function sayHello(ctx: Mali.Context) { + ctx.res = { message: 'Hello '.concat(ctx.req.name) }; +} + +const app = new Mali(PROTO_PATH); +// $ExpectType void +app.use({sayHello}); +// $ExpectType any +app.start('127.0.0.1:50051'); diff --git a/types/mali/tsconfig.json b/types/mali/tsconfig.json new file mode 100644 index 0000000000..1a4f86d02c --- /dev/null +++ b/types/mali/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mali-tests.ts" + ] +} diff --git a/types/mali/tslint.json b/types/mali/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/mali/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}