From 2f0c2be0bde230811c508302990bc91626b47efd Mon Sep 17 00:00:00 2001 From: Aryan Jassal Date: Fri, 6 Dec 2024 17:28:10 +1100 Subject: [PATCH] fix: expand header message out of the function --- src/client/handlers/VaultsSecretsCat.ts | 2 +- src/client/handlers/VaultsSecretsEnv.ts | 4 ++-- src/client/handlers/VaultsSecretsMkdir.ts | 2 +- src/client/handlers/VaultsSecretsRemove.ts | 21 +++++++++++---------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/client/handlers/VaultsSecretsCat.ts b/src/client/handlers/VaultsSecretsCat.ts index 2770b3b0b..f98084de4 100644 --- a/src/client/handlers/VaultsSecretsCat.ts +++ b/src/client/handlers/VaultsSecretsCat.ts @@ -23,7 +23,7 @@ class VaultsSecretsCat extends DuplexHandler< ClientRPCResponseResult > { public handle = async function* ( - input: AsyncIterable>, + input: AsyncIterableIterator>, ): AsyncGenerator> { const { db, vaultManager }: { db: DB; vaultManager: VaultManager } = this.container; diff --git a/src/client/handlers/VaultsSecretsEnv.ts b/src/client/handlers/VaultsSecretsEnv.ts index acfc78119..58cb1b79d 100644 --- a/src/client/handlers/VaultsSecretsEnv.ts +++ b/src/client/handlers/VaultsSecretsEnv.ts @@ -10,7 +10,7 @@ import { DuplexHandler } from '@matrixai/rpc'; import * as vaultsUtils from '../../vaults/utils'; import * as vaultsErrors from '../../vaults/errors'; -class VaultsSecretsList extends DuplexHandler< +class VaultsSecretsEnv extends DuplexHandler< { db: DB; vaultManager: VaultManager; @@ -86,4 +86,4 @@ class VaultsSecretsList extends DuplexHandler< }; } -export default VaultsSecretsList; +export default VaultsSecretsEnv; diff --git a/src/client/handlers/VaultsSecretsMkdir.ts b/src/client/handlers/VaultsSecretsMkdir.ts index 9284c74e0..da8b2c00c 100644 --- a/src/client/handlers/VaultsSecretsMkdir.ts +++ b/src/client/handlers/VaultsSecretsMkdir.ts @@ -21,7 +21,7 @@ class VaultsSecretsMkdir extends DuplexHandler< ClientRPCResponseResult > { public handle = async function* ( - input: AsyncIterable>, + input: AsyncIterableIterator>, ): AsyncGenerator> { const { db, vaultManager }: { db: DB; vaultManager: VaultManager } = this.container; diff --git a/src/client/handlers/VaultsSecretsRemove.ts b/src/client/handlers/VaultsSecretsRemove.ts index a3a2150df..cbf4a7fb1 100644 --- a/src/client/handlers/VaultsSecretsRemove.ts +++ b/src/client/handlers/VaultsSecretsRemove.ts @@ -34,15 +34,16 @@ class VaultsSecretsRemove extends DuplexHandler< ): AsyncGenerator> { const { db, vaultManager }: { db: DB; vaultManager: VaultManager } = this.container; - // Extracts the header message from the iterator - const headerMessage = await (async () => { - const header: SecretsRemoveHeaderMessage | SecretIdentifierMessageTagged = - (await input.next()).value; - if (header == null || header.type !== 'VaultNamesHeaderMessage') { - throw new clientErrors.ErrorClientInvalidHeader(); - } - return header; - })(); + // Extract the header message from the iterator + const headerMessage: + | SecretsRemoveHeaderMessage + | SecretIdentifierMessageTagged = (await input.next()).value; + if ( + headerMessage == null || + headerMessage.type !== 'VaultNamesHeaderMessage' + ) { + throw new clientErrors.ErrorClientInvalidHeader(); + } // Create an array of write acquires const vaultAcquires = await db.withTransactionF(async (tran) => { const vaultAcquires: Array> = []; @@ -103,7 +104,7 @@ class VaultsSecretsRemove extends DuplexHandler< e.code === 'ENOTEMPTY' || e.code === 'EINVAL' ) { - // INVAL can be triggered if removing the root of the + // EINVAL can be triggered if removing the root of the // vault is attempted. yield { type: 'error',