feat: add snjs package

This commit is contained in:
Karol Sójko
2022-07-06 14:04:18 +02:00
parent 321a055bae
commit 0e40469e2f
296 changed files with 46109 additions and 187 deletions

View File

@@ -0,0 +1,34 @@
import FakeWebCrypto from './fake_web_crypto.js'
export async function safeDeinit(application) {
if (application.dealloced) {
console.warn(
'Attempting to deinit already deinited application. Check the test case to find where you are double deiniting.',
)
return
}
await application.diskStorageService.awaitPersist()
/** Limit waiting to 1s */
await Promise.race([sleep(1), application.syncService?.awaitCurrentSyncs()])
await application.prepareForDeinit()
application.deinit(DeinitMode.Soft, DeinitSource.SignOut)
}
export async function sleep(seconds) {
console.warn(`Test sleeping for ${seconds}s`)
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve()
}, seconds * 1000)
})
}
export function generateUuid() {
const crypto = new FakeWebCrypto()
return crypto.generateUUID()
}