One option that comes to mind is to bind to module
as an external
, which would let you treat index.js
’s exports
as a dictionary:
// Firebase.res
type request
type response = JSON.t
type apiCallback
@module("firebase-functions/v2/https")
external onCall: (request => response) => apiCallback = "onCall"
// ApiDefinition.res
let myAction = "myAction"
let myOtherAction = "myOtherAction"
// ApiImpl.res
let myAction = Firebase.onCall(_ => JSON.Number(42.0))
let myOtherAction = Firebase.onCall(_ => JSON.String("Hello!"))
// Index.res
type module_ = {
mutable exports: Js.Dict.t<Firebase.apiCallback>
}
external module_: module_ = "module"
module_.exports = Js.Dict.fromArray([
(ApiDefinition.myAction, ApiImpl.myAction),
(ApiDefinition.myOtherAction, ApiImpl.myOtherAction),
])