Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deleting / setting to undefined variables in hooks #29

Open
a3957273 opened this issue Mar 13, 2022 · 1 comment
Open

Support deleting / setting to undefined variables in hooks #29

a3957273 opened this issue Mar 13, 2022 · 1 comment

Comments

@a3957273
Copy link

hooks.pre('cook', function () { new Promise(resolve => {
  this = undefined // obviously doesn't work
  resolve()
})})

function() {
  return new Promise(resolve => {
    resolve()
  });
});


var obj = { exists: true };

hooks.execPre('cook', obj, function(error) {
  assert.equal(null, error);
  assert.equal(undefined, obj);
});

At the moment you can alter objects passed through kareem hooks, but you're unable to remove them / set them to undefined. Is there any chance it could be changed so that we could? One suggestion would be to allow the returned value from the hook to be an array which match the arguments returned.

@a3957273
Copy link
Author

a3957273 commented Mar 13, 2022

Our use case is in Mongoose, which allows you to set pre/post hooks on Database lookups (Automattic/mongoose#11426). The intention is to do authorisation checks within Mongoose hooks in order to ensure users cannot see documents they are not supposed to even if app developers forget to do authorisation checks, as they're all done at the ORM level (gchq/Bailo#37). We can already splice arrays to remove them from find() lookups, but find() return objects which we cannot set to undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant