All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.config.middleware.example-async-middleware.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExampleAsyncMiddleware = void 0;
class ExampleAsyncMiddlewareRequestHandler {
    constructor(logger) {
        this.logger = logger;
    }
    async onRequestMetadata(metadata) {
        this.logger.info('ExampleAsyncMiddleware.onRequestMetadata enter');
        await delay(500);
        this.logger.info('ExampleAsyncMiddleware.onRequestMetadata exit');
        return metadata;
    }
    async onRequestBody(request) {
        this.logger.info('ExampleAsyncMiddleware.onRequestBody enter');
        await delay(500);
        this.logger.info('ExampleAsyncMiddleware.onRequestBody exit');
        // eslint-disable-next-line @typescript-eslint/no-unsafe-return
        return request;
    }
    async onResponseMetadata(metadata) {
        this.logger.info('ExampleAsyncMiddleware.onResponseMetadata enter');
        await delay(500);
        this.logger.info('ExampleAsyncMiddleware.onResponseMetadata exit');
        return metadata;
    }
    async onResponseBody(response) {
        this.logger.info('ExampleAsyncMiddleware.onResponseBody enter');
        await delay(500);
        this.logger.info('ExampleAsyncMiddleware.onResponseBody exit');
        // eslint-disable-next-line @typescript-eslint/no-unsafe-return
        return response;
    }
    async onResponseStatus(status) {
        this.logger.info('ExampleAsyncMiddleware.onResponseStatus enter');
        await delay(500);
        this.logger.info('ExampleAsyncMiddleware.onResponseStatus exit');
        return status;
    }
}
/**
 * This class provides an example of how users can implement a Middleware that
 * requires async calls.
 */
class ExampleAsyncMiddleware {
    constructor(loggerFactory) {
        this.logger = loggerFactory.getLogger(this);
    }
    onNewRequest() {
        this.logger.info('ExampleAsyncMiddleware handling new request');
        return new ExampleAsyncMiddlewareRequestHandler(this.logger);
    }
}
exports.ExampleAsyncMiddleware = ExampleAsyncMiddleware;
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhhbXBsZS1hc3luYy1taWRkbGV3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