Using JS in Actions to Manipulate Tokens

I am migrating my rules to actions and I am wondering how to the same thing I am doing in actions.

I first added the user’s app metadata to the token.
Then in the metadata I have a json array named databases. I want to remove all but 1 key that matches a specific key value.
Below code is how I did it in rules, in actions we use the setCustomClaim( function. What’s the best way to do the same thing?

context.accessToken[namespace + '/app_metadata'].databases = context.accessToken[namespace + '/app_metadata'].databases.filter((o) => o.dbKey === clavenKey);