allow migrating from old to new bridge

This commit is contained in:
Cadence Ember
2023-09-04 01:38:30 +12:00
parent 5185ae45ab
commit 39458bd2bf
13 changed files with 214 additions and 42 deletions

View File

@@ -43,5 +43,24 @@ async function mreq(method, url, body, extra = {}) {
return root
}
/**
* JavaScript doesn't have Racket-like parameters with dynamic scoping, so
* do NOT do anything else at the same time as this.
* @template T
* @param {string} token
* @param {(...arg: any[]) => Promise<T>} callback
* @returns {Promise<T>}
*/
async function withAccessToken(token, callback) {
const prevToken = reg.as_token
reg.as_token = token
try {
return await callback()
} finally {
reg.as_token = prevToken
}
}
module.exports.MatrixServerError = MatrixServerError
module.exports.mreq = mreq
module.exports.withAccessToken = withAccessToken