informatics-isi-edu / ermrestjs

ERMrest client library in JavaScript
Apache License 2.0
4 stars 3 forks source link

Generate map on the $session variable for phs ids #955

Closed jrchudy closed 2 years ago

jrchudy commented 2 years ago

We need to create an extra object in the $session templating variable that takes each phs_id from the objects in the $session.client.extensions.ras_dbgap_permissions array. Each phs_id should be used as a key in the created object with true as the value.

This is being done for a CFDE use case to prevent looping over a potentially large array for every single generated template. Array.includes() could almost accomplish the same thing but doing so could be potentially dangerous given the ras_dbgap_permissions array is an unknown size. The array also includes objects so a simple Array.includes wouldn't solve this use case.

To work with this created map, we need to also enable the lookup helper from handlebars (further explained here. One thing to note about this helper is how it behaves with null and undefined. This helper will return the value associated with the key in the map even if the value is set to null or set to undefined. If the key isn't present, undefined will be returned (which is the expected behavior in JS.