Skip to content

Commit

Permalink
Improve Core types in preparation for ts v4.7.4 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf authored Aug 7, 2023
1 parent f33aa04 commit a746d2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ export class CoreVersionedRoute implements VersionedRoute {
) {
try {
const { body, params, query } = validate(req, validation.request, handler.options.version);
(req as Mutable<KibanaRequest>).body = body;
(req as Mutable<KibanaRequest>).params = params;
(req as Mutable<KibanaRequest>).query = query;
req.body = body;
req.params = params;
req.query = query;
} catch (e) {
return res.badRequest({
body: e.message,
});
}
} else {
// Preserve behavior of not passing through unvalidated data
(req as Mutable<KibanaRequest>).body = {};
(req as Mutable<KibanaRequest>).params = {};
(req as Mutable<KibanaRequest>).query = {};
req.body = {};
req.params = {};
req.query = {};
}

const response = await handler.fn(ctx, req, res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KibanaRequest>
): request is Mutable<KibanaRequestWithQueryVersion> {
return isObject(request.query) && ELASTIC_HTTP_VERSION_QUERY_PARAM in request.query;
}
export function removeQueryVersion(request: Mutable<KibanaRequestWithQueryVersion>): void {
Expand Down

0 comments on commit a746d2c

Please sign in to comment.