Merge pull request #28571 from danwbyrne/mali-compose

adds typings for the 'mali-compose' package
This commit is contained in:
Armando Aguirre
2018-08-31 16:12:37 -07:00
committed by GitHub
4 changed files with 76 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
// Type definitions for mali 1.1
// Project: https://github.com/malijs/mali-compose
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
import { Context } from "mali";
declare function compose(
middleware: ReadonlyArray<
(ctx: Context, next: () => Promise<void>) => Promise<void>
>
): (context: Context, next: () => Promise<void>) => Promise<void>;
export = compose;
+39
View File
@@ -0,0 +1,39 @@
import compose = require('mali-compose');
import { Context } from 'mali';
type middleware = (context: Context, next: () => Promise<void>) => Promise<void>;
const arr: number[] = [];
const stack: middleware[] = [];
function _sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
stack.push(async (ctx: Context, next: () => Promise<void>) => {
arr.push(1);
await _sleep(1);
await next();
await _sleep(1);
arr.push(6);
});
stack.push(async (ctx: Context, next: () => Promise<void>) => {
arr.push(2);
await _sleep(1);
await next();
await _sleep(1);
arr.push(5);
});
stack.push(async (ctx: Context, next: () => Promise<void>) => {
arr.push(3);
await _sleep(1);
await next();
await _sleep(1);
arr.push(4);
});
compose(stack);
compose([]);
compose([compose(stack)]);
+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-compose-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}