Merge pull request #28548 from danwbyrne/mali

adds typings for the 'mali' package
This commit is contained in:
Armando Aguirre
2018-08-31 14:11:17 -07:00
committed by GitHub
4 changed files with 115 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
// Type definitions for mali 0.9
// Project: https://github.com/malijs/mali
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Stream } from 'stream';
declare class Mali extends EventEmitter {
constructor(path: any, name?: string | ReadonlyArray<string>, options?: any);
name: string;
env: string;
ports: ReadonlyArray<string | number>; // ? not sure which it is
silent: boolean;
addService(path: any, name: string | ReadonlyArray<string>, 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;
+16
View File
@@ -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');
+19
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}