From 16e27d2ca4337d01a53e8b6716a659e98badff0a Mon Sep 17 00:00:00 2001 From: Pragadesh-45 <54320162+Pragadesh-45@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:57:00 +0530 Subject: [PATCH] feat: make `BrunoResponse` callable to access body data using expressions fixes (#481) (#3710) * feat: make `BrunoResponse` callable to access body data using expressions --- packages/bruno-js/src/bruno-response.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/bruno-js/src/bruno-response.js b/packages/bruno-js/src/bruno-response.js index 9e68045d9..faa315235 100644 --- a/packages/bruno-js/src/bruno-response.js +++ b/packages/bruno-js/src/bruno-response.js @@ -1,3 +1,5 @@ +const { get } = require('@usebruno/query'); + class BrunoResponse { constructor(res) { this.res = res; @@ -6,6 +8,13 @@ class BrunoResponse { this.headers = res ? res.headers : null; this.body = res ? res.data : null; this.responseTime = res ? res.responseTime : null; + + // Make the instance callable + const callable = (...args) => get(this.body, ...args); + Object.setPrototypeOf(callable, this.constructor.prototype); + Object.assign(callable, this); + + return callable; } getStatus() {