From 7bb96e0eceae8bc95e9963dc7249dde92666c9d4 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 1 Jun 2022 22:25:29 +0200 Subject: [PATCH] chore(crypto-node): Use `Either7` (new pending feature). --- crates/matrix-sdk-crypto-nodejs/Cargo.toml | 4 ++-- .../matrix-sdk-crypto-nodejs/src/machine.rs | 18 +++++++-------- .../matrix-sdk-crypto-nodejs/src/requests.rs | 22 ++++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/matrix-sdk-crypto-nodejs/Cargo.toml b/crates/matrix-sdk-crypto-nodejs/Cargo.toml index 6c6d04adf..a4986b919 100644 --- a/crates/matrix-sdk-crypto-nodejs/Cargo.toml +++ b/crates/matrix-sdk-crypto-nodejs/Cargo.toml @@ -28,8 +28,8 @@ matrix-sdk-crypto = { version = "0.5.0", path = "../matrix-sdk-crypto" } matrix-sdk-common = { version = "0.5.0", path = "../matrix-sdk-common" } ruma = { version = "0.6.2", features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] } vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36" } -napi = { git = "https://github.com/Hywan/napi-rs", branch = "feat-tonapivalue-u16", default-features = false, features = ["napi4", "tokio_rt"] } -napi-derive = "2.4.1" +napi = { git = "https://github.com/Hywan/napi-rs", branch = "feat-either-n-up-to-26", default-features = false, features = ["napi4", "tokio_rt"] } +napi-derive = { git = "https://github.com/Hywan/napi-rs", branch = "feat-either-n-up-to-26" } serde_json = "1.0.79" http = "0.2.6" diff --git a/crates/matrix-sdk-crypto-nodejs/src/machine.rs b/crates/matrix-sdk-crypto-nodejs/src/machine.rs index ae4faeee2..57dbfa296 100644 --- a/crates/matrix-sdk-crypto-nodejs/src/machine.rs +++ b/crates/matrix-sdk-crypto-nodejs/src/machine.rs @@ -5,7 +5,7 @@ use std::{ time::Duration, }; -use napi::bindgen_prelude::{Either3, Either5, ToNapiValue}; +use napi::bindgen_prelude::{Either7, ToNapiValue}; use napi_derive::*; use ruma::{ events::room::encrypted::OriginalSyncRoomEncryptedEvent, DeviceKeyAlgorithm, @@ -104,24 +104,22 @@ impl OlmMachine { } // We could be tempted to use `requests::OutgoingRequests` as its - // a type alias for this giant `Either` chain. But `napi` won't - // unfold it properly into a valid TypeScript definition, so… - // let's copy-paste :-(. + // a type alias for this giant `Either7`. But `napi` won't unfold + // it properly into a valid TypeScript definition, so… let's + // copy-paste :-(. #[napi] pub async fn outgoing_requests( &self, ) -> Result< Vec< - Either5< + Either7< requests::KeysUploadRequest, requests::KeysQueryRequest, requests::KeysClaimRequest, requests::ToDeviceRequest, - Either3< - requests::SignatureUploadRequest, - requests::RoomMessageRequest, - requests::KeysBackupRequest, - >, + requests::SignatureUploadRequest, + requests::RoomMessageRequest, + requests::KeysBackupRequest, >, >, napi::Error, diff --git a/crates/matrix-sdk-crypto-nodejs/src/requests.rs b/crates/matrix-sdk-crypto-nodejs/src/requests.rs index 895b016c4..a12c6b285 100644 --- a/crates/matrix-sdk-crypto-nodejs/src/requests.rs +++ b/crates/matrix-sdk-crypto-nodejs/src/requests.rs @@ -4,7 +4,7 @@ use matrix_sdk_crypto::requests::{ KeysBackupRequest as RumaKeysBackupRequest, KeysQueryRequest as RumaKeysQueryRequest, RoomMessageRequest as RumaRoomMessageRequest, ToDeviceRequest as RumaToDeviceRequest, }; -use napi::bindgen_prelude::{Either3, Either5, ToNapiValue}; +use napi::bindgen_prelude::{Either7, ToNapiValue}; use napi_derive::*; use ruma::api::client::keys::{ claim_keys::v3::Request as RumaKeysClaimRequest, @@ -187,12 +187,14 @@ request!(SignatureUploadRequest from RumaSignatureUploadRequest maps fields sign request!(RoomMessageRequest from RumaRoomMessageRequest maps fields room_id, txn_id, content); request!(KeysBackupRequest from RumaKeysBackupRequest maps fields rooms); -pub type OutgoingRequests = Either5< +pub type OutgoingRequests = Either7< KeysUploadRequest, KeysQueryRequest, KeysClaimRequest, ToDeviceRequest, - Either3, + SignatureUploadRequest, + RoomMessageRequest, + KeysBackupRequest, >; // JavaScript has no complex enums like Rust. To return structs of @@ -207,31 +209,31 @@ impl TryFrom for OutgoingRequests { Ok(match outgoing_request.0.request() { matrix_sdk_crypto::OutgoingRequests::KeysUpload(request) => { - Either5::A(KeysUploadRequest::try_from((request_id, request))?) + Either7::A(KeysUploadRequest::try_from((request_id, request))?) } matrix_sdk_crypto::OutgoingRequests::KeysQuery(request) => { - Either5::B(KeysQueryRequest::try_from((request_id, request))?) + Either7::B(KeysQueryRequest::try_from((request_id, request))?) } matrix_sdk_crypto::OutgoingRequests::KeysClaim(request) => { - Either5::C(KeysClaimRequest::try_from((request_id, request))?) + Either7::C(KeysClaimRequest::try_from((request_id, request))?) } matrix_sdk_crypto::OutgoingRequests::ToDeviceRequest(request) => { - Either5::D(ToDeviceRequest::try_from((request_id, request))?) + Either7::D(ToDeviceRequest::try_from((request_id, request))?) } matrix_sdk_crypto::OutgoingRequests::SignatureUpload(request) => { - Either5::E(Either3::A(SignatureUploadRequest::try_from((request_id, request))?)) + Either7::E(SignatureUploadRequest::try_from((request_id, request))?) } matrix_sdk_crypto::OutgoingRequests::RoomMessage(request) => { - Either5::E(Either3::B(RoomMessageRequest::try_from((request_id, request))?)) + Either7::F(RoomMessageRequest::try_from((request_id, request))?) } matrix_sdk_crypto::OutgoingRequests::KeysBackup(request) => { - Either5::E(Either3::C(KeysBackupRequest::try_from((request_id, request))?)) + Either7::G(KeysBackupRequest::try_from((request_id, request))?) } }) }