feat: bru fns update (#3231)

This commit is contained in:
lohit 2024-10-01 23:45:05 +05:30 committed by GitHub
parent 96e58f2f40
commit 6bc8acd1e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 0 deletions

View File

@ -69,6 +69,7 @@ if (!SERVER_RENDERED) {
'bru.getVar(key)', 'bru.getVar(key)',
'bru.setVar(key,value)', 'bru.setVar(key,value)',
'bru.deleteVar(key)', 'bru.deleteVar(key)',
'bru.deleteAllVars()',
'bru.setNextRequest(requestName)', 'bru.setNextRequest(requestName)',
'req.disableParsingResponseJson()', 'req.disableParsingResponseJson()',
'bru.getRequestVar(key)', 'bru.getRequestVar(key)',

View File

@ -97,6 +97,14 @@ class Bru {
delete this.runtimeVariables[key]; delete this.runtimeVariables[key];
} }
deleteAllVars() {
for (let key in this.runtimeVariables) {
if (this.runtimeVariables.hasOwnProperty(key)) {
delete this.runtimeVariables[key];
}
}
}
getCollectionVar(key) { getCollectionVar(key) {
return this._interpolate(this.collectionVariables[key]); return this._interpolate(this.collectionVariables[key]);
} }

View File

@ -21,6 +21,12 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'getProcessEnv', getProcessEnv); vm.setProp(bruObject, 'getProcessEnv', getProcessEnv);
getProcessEnv.dispose(); getProcessEnv.dispose();
let hasEnvVar = vm.newFunction('hasEnvVar', function (key) {
return marshallToVm(bru.hasEnvVar(vm.dump(key)), vm);
});
vm.setProp(bruObject, 'hasEnvVar', hasEnvVar);
hasEnvVar.dispose();
let getEnvVar = vm.newFunction('getEnvVar', function (key) { let getEnvVar = vm.newFunction('getEnvVar', function (key) {
return marshallToVm(bru.getEnvVar(vm.dump(key)), vm); return marshallToVm(bru.getEnvVar(vm.dump(key)), vm);
}); });
@ -33,6 +39,12 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'setEnvVar', setEnvVar); vm.setProp(bruObject, 'setEnvVar', setEnvVar);
setEnvVar.dispose(); setEnvVar.dispose();
let hasVar = vm.newFunction('hasVar', function (key) {
return marshallToVm(bru.hasVar(vm.dump(key)), vm);
});
vm.setProp(bruObject, 'hasVar', hasVar);
hasVar.dispose();
let getVar = vm.newFunction('getVar', function (key) { let getVar = vm.newFunction('getVar', function (key) {
return marshallToVm(bru.getVar(vm.dump(key)), vm); return marshallToVm(bru.getVar(vm.dump(key)), vm);
}); });
@ -45,6 +57,18 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'setVar', setVar); vm.setProp(bruObject, 'setVar', setVar);
setVar.dispose(); setVar.dispose();
let deleteVar = vm.newFunction('deleteVar', function (key) {
bru.deleteVar(vm.dump(key));
});
vm.setProp(bruObject, 'deleteVar', deleteVar);
deleteVar.dispose();
let deleteAllVars = vm.newFunction('deleteAllVars', function () {
bru.deleteAllVars();
});
vm.setProp(bruObject, 'deleteAllVars', deleteAllVars);
deleteAllVars.dispose();
let setNextRequest = vm.newFunction('setNextRequest', function (nextRequest) { let setNextRequest = vm.newFunction('setNextRequest', function (nextRequest) {
bru.setNextRequest(vm.dump(nextRequest)); bru.setNextRequest(vm.dump(nextRequest));
}); });