upgrade typescript

This commit is contained in:
Daniel Lugo 2021-02-22 10:37:15 -04:00
parent a339d1058c
commit 2d24040894
5 changed files with 63 additions and 63 deletions

View file

@ -85,7 +85,7 @@
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"ts-type": "^1.2.16",
"typescript": "^4.0.2"
"typescript": "latest"
},
"lint-staged": {
"*.js": [

View file

@ -314,7 +314,7 @@ const authenticate = async (alias, pass, __user) => {
// clock skew
await new Promise(res => setTimeout(res, 2000))
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
_user.get(Key.FOLLOWS).put(
{
unused: null
@ -327,7 +327,7 @@ const authenticate = async (alias, pass, __user) => {
}
}
)
})
}))
return ack.sea.pub
} else {
@ -345,7 +345,7 @@ const authenticate = async (alias, pass, __user) => {
// clock skew
await new Promise(res => setTimeout(res, 2000))
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
_user.get(Key.FOLLOWS).put(
{
unused: null
@ -358,7 +358,7 @@ const authenticate = async (alias, pass, __user) => {
}
}
)
})
}))
// move this to a subscription; implement off() ? todo
API.Jobs.onAcceptedRequests(_user, mySEA)
@ -404,7 +404,7 @@ const authenticate = async (alias, pass, __user) => {
await new Promise(res => setTimeout(res, 5000))
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
_user.get(Key.FOLLOWS).put(
{
unused: null
@ -417,7 +417,7 @@ const authenticate = async (alias, pass, __user) => {
}
}
)
})
}))
API.Jobs.onAcceptedRequests(_user, mySEA)
API.Jobs.onOrders(_user, gun, mySEA)

View file

@ -100,7 +100,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => {
timestamp: Date.now()
}
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.OUTGOINGS)
.get(newOutgoingFeedID)
@ -113,14 +113,14 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => {
res()
}
})
})
}))
const encryptedForMeNewOutgoingFeedID = await SEA.encrypt(
newOutgoingFeedID,
mySecret
)
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.RECIPIENT_TO_OUTGOING)
.get(withPublicKey)
@ -131,7 +131,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => {
res()
}
})
})
}))
outgoingFeedID = newOutgoingFeedID
}
@ -237,7 +237,7 @@ const acceptRequest = async (
const mySecret = require('../Mediator').getMySecret()
const encryptedForMeIncomingID = await SEA.encrypt(incomingID, mySecret)
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.USER_TO_INCOMING)
.get(senderPublicKey)
@ -248,7 +248,7 @@ const acceptRequest = async (
res()
}
})
})
}))
////////////////////////////////////////////////////////////////////////////
// NOTE: perform non-reversable actions before destructive actions
@ -261,7 +261,7 @@ const acceptRequest = async (
ourSecret
)
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
gun
.get(Key.HANDSHAKE_NODES)
.get(handshakeAddress)
@ -278,7 +278,7 @@ const acceptRequest = async (
}
}
)
})
}))
}
/**
@ -287,7 +287,7 @@ const acceptRequest = async (
* @param {UserGUNNode} userNode
*/
const authenticate = (user, pass, userNode) =>
new Promise((resolve, reject) => {
/** @type {Promise<void>} */ (new Promise((resolve, reject) => {
if (typeof user !== 'string') {
throw new TypeError('expected user to be of type string')
}
@ -317,7 +317,7 @@ const authenticate = (user, pass, userNode) =>
resolve()
}
})
})
}))
/**
* @param {string} publicKey
@ -349,7 +349,7 @@ const generateHandshakeAddress = async () => {
const address = uuidv1()
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user.get(Key.CURRENT_HANDSHAKE_ADDRESS).put(address, ack => {
if (ack.err && typeof ack.err !== 'number') {
rej(new Error(ack.err))
@ -357,9 +357,9 @@ const generateHandshakeAddress = async () => {
res()
}
})
})
}))
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
gun
.get(Key.HANDSHAKE_NODES)
.get(address)
@ -370,7 +370,7 @@ const generateHandshakeAddress = async () => {
res()
}
})
})
}))
}
/**
@ -387,7 +387,7 @@ const cleanup = async pub => {
const promises = []
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.USER_TO_INCOMING)
.get(pub)
@ -398,11 +398,11 @@ const cleanup = async pub => {
res()
}
})
})
}))
)
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.RECIPIENT_TO_OUTGOING)
.get(pub)
@ -413,11 +413,11 @@ const cleanup = async pub => {
res()
}
})
})
}))
)
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.USER_TO_LAST_REQUEST_SENT)
.get(pub)
@ -428,12 +428,12 @@ const cleanup = async pub => {
res()
}
})
})
}))
)
if (outGoingID) {
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.OUTGOINGS)
.get(outGoingID)
@ -444,7 +444,7 @@ const cleanup = async pub => {
res()
}
})
})
}))
)
}
@ -618,7 +618,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
})
})
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.USER_TO_LAST_REQUEST_SENT)
.get(recipientPublicKey)
@ -629,7 +629,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
res()
}
})
})
}))
// This needs to come before the write to sent requests. Because that write
// triggers Jobs.onAcceptedRequests and it in turn reads from request-to-user
@ -644,7 +644,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
timestamp
}
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
//@ts-ignore
user.get(Key.STORED_REQS).set(storedReq, ack => {
if (ack.err && typeof ack.err !== 'number') {
@ -657,7 +657,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
res()
}
})
})
}))
}
/**
@ -1147,7 +1147,7 @@ const generateOrderAddress = user =>
* @returns {Promise<void>}
*/
const setBio = (bio, user) =>
new Promise((resolve, reject) => {
/** @type {Promise<void>} */ (new Promise((resolve, reject) => {
if (!user.is) {
throw new Error(ErrorCode.NOT_AUTH)
}
@ -1171,7 +1171,7 @@ const setBio = (bio, user) =>
resolve()
}
})
}).then(
})).then(
() =>
new Promise((resolve, reject) => {
user
@ -1255,7 +1255,7 @@ const disconnect = async pub => {
* @returns {Promise<void>}
*/
const setLastSeenApp = () =>
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
require('../Mediator')
.getUser()
.get(Key.LAST_SEEN_APP)
@ -1266,7 +1266,7 @@ const setLastSeenApp = () =>
res()
}
})
}).then(
})).then(
() =>
new Promise((res, rej) => {
require('../Mediator')
@ -1386,7 +1386,7 @@ const createPost = async (tags, title, content) => {
pageIdx = Number(pageIdx + 1).toString()
}
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
require('../Mediator')
.getUser()
.get(Key.WALL)
@ -1407,7 +1407,7 @@ const createPost = async (tags, title, content) => {
res()
}
)
})
}))
const [postID, newPost] = await createPostNew(tags, title, content)
@ -1433,7 +1433,7 @@ const createPost = async (tags, title, content) => {
})
if (shouldBeNewPage || numOfPages === 0) {
await new Promise(res => {
await /** @type {Promise<void>} */ (new Promise(res => {
require('../Mediator')
.getUser()
.get(Key.WALL)
@ -1445,7 +1445,7 @@ const createPost = async (tags, title, content) => {
res()
})
})
}))
}
const loadedPost = await new Promise(res => {
@ -1488,7 +1488,7 @@ const createPost = async (tags, title, content) => {
* @returns {Promise<void>}
*/
const deletePost = async (postId, page) => {
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
require('../Mediator')
.getUser()
.get(Key.WALL)
@ -1503,15 +1503,15 @@ const deletePost = async (postId, page) => {
res()
}
})
})
}))
}
/**
* @param {string} publicKey
* @param {boolean} isPrivate Will overwrite previous private status.
* @returns {Promise<string>}
* @returns {Promise<void>}
*/
const follow = (publicKey, isPrivate) => {
const follow = async (publicKey, isPrivate) => {
/** @type {import('shock-common').Schema.Follow} */
const newFollow = {
private: isPrivate,
@ -1519,7 +1519,7 @@ const follow = (publicKey, isPrivate) => {
user: publicKey
}
return new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
require('../Mediator')
.getUser()
.get(Key.FOLLOWS)
@ -1532,7 +1532,7 @@ const follow = (publicKey, isPrivate) => {
res()
}
})
})
}))
}
/**
@ -1564,7 +1564,7 @@ const initWall = async () => {
const promises = []
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.WALL)
.get(Key.NUM_OF_PAGES)
@ -1575,11 +1575,11 @@ const initWall = async () => {
res()
}
})
})
}))
)
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.WALL)
.get(Key.PAGES)
@ -1597,11 +1597,11 @@ const initWall = async () => {
}
}
)
})
}))
)
promises.push(
new Promise((res, rej) => {
/** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.WALL)
.get(Key.PAGES)
@ -1614,7 +1614,7 @@ const initWall = async () => {
res()
}
})
})
}))
)
await Promise.all(promises)

View file

@ -92,7 +92,7 @@ const onAcceptedRequests = (user, SEA) => {
const recipientEpub = await Utils.pubToEpub(recipientPub)
const ourSecret = await SEA.secret(recipientEpub, user._.sea)
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
gun
.get(Key.HANDSHAKE_NODES)
.get(requestAddress)
@ -151,7 +151,7 @@ const onAcceptedRequests = (user, SEA) => {
mySecret
)
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.USER_TO_INCOMING)
.get(recipientPub)
@ -162,9 +162,9 @@ const onAcceptedRequests = (user, SEA) => {
res()
}
})
})
}))
await new Promise((res, rej) => {
await /** @type {Promise<void>} */ (new Promise((res, rej) => {
user
.get(Key.STORED_REQS)
.get(id)
@ -175,12 +175,12 @@ const onAcceptedRequests = (user, SEA) => {
res()
}
})
})
}))
// ensure this listeners gets called at least once
res()
})
})
}))
} catch (err) {
logger.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
logger.error(err)

View file

@ -7031,10 +7031,10 @@ typescript-tuple@^2.2.1:
dependencies:
typescript-compare "^0.0.2"
typescript@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2"
integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==
typescript@latest:
version "4.1.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.5.tgz#123a3b214aaff3be32926f0d8f1f6e704eb89a72"
integrity sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==
uglify-js@^3.1.4:
version "3.10.2"