From a746d2c49a1ed690e5ac682040879679777ee3db Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 7 Aug 2023 18:28:57 +0200 Subject: [PATCH] Improve Core types in preparation for ts v4.7.4 (#17) --- .../src/versioned_router/core_versioned_route.ts | 12 ++++++------ .../src/versioned_router/route_version_utils.ts | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.ts b/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.ts index 1c972b346c353..dd1a0c21d5593 100644 --- a/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.ts +++ b/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.ts @@ -161,9 +161,9 @@ export class CoreVersionedRoute implements VersionedRoute { ) { try { const { body, params, query } = validate(req, validation.request, handler.options.version); - (req as Mutable).body = body; - (req as Mutable).params = params; - (req as Mutable).query = query; + req.body = body; + req.params = params; + req.query = query; } catch (e) { return res.badRequest({ body: e.message, @@ -171,9 +171,9 @@ export class CoreVersionedRoute implements VersionedRoute { } } else { // Preserve behavior of not passing through unvalidated data - (req as Mutable).body = {}; - (req as Mutable).params = {}; - (req as Mutable).query = {}; + req.body = {}; + req.params = {}; + req.query = {}; } const response = await handler.fn(ctx, req, res); diff --git a/packages/core/http/core-http-router-server-internal/src/versioned_router/route_version_utils.ts b/packages/core/http/core-http-router-server-internal/src/versioned_router/route_version_utils.ts index c5e6ff5967deb..6d22046ed81e1 100644 --- a/packages/core/http/core-http-router-server-internal/src/versioned_router/route_version_utils.ts +++ b/packages/core/http/core-http-router-server-internal/src/versioned_router/route_version_utils.ts @@ -52,7 +52,9 @@ type KibanaRequestWithQueryVersion = KibanaRequest< { [ELASTIC_HTTP_VERSION_QUERY_PARAM]: unknown } >; -export function hasQueryVersion(request: KibanaRequest): request is KibanaRequestWithQueryVersion { +export function hasQueryVersion( + request: Mutable +): request is Mutable { return isObject(request.query) && ELASTIC_HTTP_VERSION_QUERY_PARAM in request.query; } export function removeQueryVersion(request: Mutable): void {