add tests, implement kstate and state diffing

This commit is contained in:
Cadence Ember 2023-05-05 17:29:08 +12:00
parent c7868e9dbb
commit f09eeccef3
10 changed files with 2656 additions and 64 deletions

View file

@ -1,6 +1,6 @@
// @ts-check
const fetch = require("node-fetch")
const fetch = require("node-fetch").default
const mixin = require("mixin-deep")
const passthrough = require("../passthrough")
@ -26,7 +26,7 @@ class MatrixServerError {
* @param {any} [body]
* @param {any} [extra]
*/
function mreq(method, url, body, extra = {}) {
async function mreq(method, url, body, extra = {}) {
const opts = mixin({
method,
body: (body == undefined || Object.is(body.constructor, Object)) ? JSON.stringify(body) : body,
@ -34,13 +34,13 @@ function mreq(method, url, body, extra = {}) {
Authorization: `Bearer ${reg.as_token}`
}
}, extra)
console.log(baseUrl + url, opts)
return fetch(baseUrl + url, opts).then(res => {
return res.json().then(root => {
if (!res.ok || root.errcode) throw new MatrixServerError(root)
return root
})
})
const res = await fetch(baseUrl + url, opts)
const root = await res.json()
if (!res.ok || root.errcode) throw new MatrixServerError(root)
return root
}
module.exports.MatrixServerError = MatrixServerError