Add express-correlation-id and correlation-id packages (#25710)

* feat(correlation-id & express-correlation-id): Add express-correlation-id and correlation-id packages

* fix(correlation-id) Update type of bindID function
This commit is contained in:
Nate Mara
2018-05-14 11:12:35 -07:00
committed by Sheetal Nandi
parent 020bc73382
commit 0c564acdc0
8 changed files with 92 additions and 0 deletions
@@ -0,0 +1,21 @@
import { withId, bindId, getId } from "correlation-id";
withId("my-id", () => {
const id: string = getId() || "";
});
withId(() => {
const id: string = getId() || "";
});
const x: string = bindId("my-id", (foo: string, bar: number): string => {
const id: string = getId() || "";
return foo + bar + id;
})("foo", 12);
const y: string = bindId((foo: string, bar: number): string => {
const id: string = getId() || "";
return foo + bar + id;
})("foo", 12);
+12
View File
@@ -0,0 +1,12 @@
// Type definitions for correlation-id 2.1
// Project: https://github.com/toboid/correlation-id#readme
// Definitions by: Nate <https://github.com/natemara>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function withId(id: string, work: () => void): void;
export function withId(work: () => void): void;
export function bindId<T extends (...p: any[]) => any>(id: string, work: T): T;
export function bindId<T extends (...p: any[]) => any>(work: T): T;
export function getId(): string | undefined;
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "correlation-id-tests.ts"]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
@@ -0,0 +1,9 @@
import * as express from "express";
import correlator from "express-correlation-id";
const app = express();
app.use(correlator());
app.use(correlator({}));
app.use(correlator({ header: "x-correlation-id" }));
const x: string = correlator.getId() || "";
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for express-correlation-id 1.2
// Project: https://github.com/toboid/express-correlation-id#readme
// Definitions by: Nate <https://github.com/natemara>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import { RequestHandler } from "express-serve-static-core";
declare const correlator: {
(options?: { header?: string }): RequestHandler;
getId(): string | undefined;
};
export default correlator;
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "express-correlation-id-tests.ts"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }