From 2d24040894792d11c0223ec1095bc82d4c3f0078 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 22 Feb 2021 10:37:15 -0400 Subject: [PATCH] upgrade typescript --- package.json | 2 +- services/gunDB/Mediator/index.js | 12 +-- services/gunDB/contact-api/actions.js | 92 +++++++++---------- .../contact-api/jobs/onAcceptedRequests.js | 12 +-- yarn.lock | 8 +- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/package.json b/package.json index 28331476..d4f5e685 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index e7914de8..eddb2466 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -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} */ (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} */ (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} */ (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) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index 2d93fc29..14fd4bf1 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -100,7 +100,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => { timestamp: Date.now() } - await new Promise((res, rej) => { + await /** @type {Promise} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ (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} */ const setBio = (bio, user) => - new Promise((resolve, reject) => { + /** @type {Promise} */ (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} */ const setLastSeenApp = () => - new Promise((res, rej) => { + /** @type {Promise} */ (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} */ (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} */ (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} */ const deletePost = async (postId, page) => { - await new Promise((res, rej) => { + await /** @type {Promise} */ (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} + * @returns {Promise} */ -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} */ (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} */ (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} */ (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} */ (new Promise((res, rej) => { user .get(Key.WALL) .get(Key.PAGES) @@ -1614,7 +1614,7 @@ const initWall = async () => { res() } }) - }) + })) ) await Promise.all(promises) diff --git a/services/gunDB/contact-api/jobs/onAcceptedRequests.js b/services/gunDB/contact-api/jobs/onAcceptedRequests.js index ba9cad5a..255cc107 100644 --- a/services/gunDB/contact-api/jobs/onAcceptedRequests.js +++ b/services/gunDB/contact-api/jobs/onAcceptedRequests.js @@ -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} */ (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} */ (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} */ (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) diff --git a/yarn.lock b/yarn.lock index 22c9bbc9..f0de2b4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"