@types/emartech__cls-adapter
TypeScript icon, indicating that this package has built-in type declarations

1.3.6 • Public • Published

Installation

npm install --save @types/emartech__cls-adapter

Summary

This package contains type definitions for @emartech/cls-adapter (https://github.com/emartech/cls-adapter).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/emartech__cls-adapter.

import * as CLS from "cls-hooked";
import * as Express from "express";
import * as Koa from "koa";

declare class ContextFactory {
    private _namespace: CLS.Namespace;

    /**
     * Returns a middleware function compatible with Koa that stores (or generates if missing)
     * the request identifier from the header (X-Request-Id) and sets it on the storage as request_id.
     */
    static getKoaMiddleware: () => Koa.Middleware;

    /**
     * Returns a middleware function compatible with Express that stores (or generates if missing)
     * the request identifier from the header (X-Request-Id) and sets it on the storage as request_id.
     */
    static getExpressMiddleware: () => Express.Handler;

    static run: CLS.Namespace["runAndReturn"];

    /**
     * Sets a key with a given value on the storage.
     */
    static setOnContext: CLS.Namespace["set"];

    /**
     * Returns the all the values set on the storage.
     */
    // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
    static getContextStorage: <T = Record<string, unknown>>() => T & {
        requestId: string;
    };

    /**
     * Returns the the request identifier set on the storage. The identifiers key is request_id.
     */
    static getRequestId: () => string | undefined;

    /**
     * Returns a function that extends the given object with the current storage.
     */
    static addContextStorageToInput: () => <T extends {}>(input: T) => T & { requestId: string };

    /**
     * Returns a function that extends the given object with the request identifier set on the current storage.
     */
    static addRequestIdToInput: () => <T extends {}>(
        input: T,
    ) => T & { requestId: string };

    /**
     * Destroys (if exists) the namespace with the name 'session'
     */
    static destroyNamespace: () => void;

    /**
     * Creates (or returns existing namespace) with the namespace name 'session'
     */
    static createNamespace: () => CLS.Namespace;
}

export = ContextFactory;

Additional Details

Credits

These definitions were written by Lex Webb.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/emartech__cls-adapter

Weekly Downloads

20

Version

1.3.6

License

MIT

Unpacked Size

6.93 kB

Total Files

5

Last publish

Collaborators

  • types