1- import type { ContextTimed } from '@matrixai/contexts' ;
21import type { DB } from '@matrixai/db' ;
3- import type { JSONValue } from '@matrixai/rpc' ;
42import type {
53 ClientRPCRequestParams ,
64 ClientRPCResponseResult ,
@@ -23,10 +21,7 @@ class VaultsSecretsList extends ServerHandler<
2321> {
2422 public handle = async function * (
2523 input : ClientRPCRequestParams < SecretIdentifierMessage > ,
26- _cancel : ( reason ?: any ) => void ,
27- _meta : Record < string , JSONValue > ,
28- ctx : ContextTimed ,
29- ) : AsyncGenerator < ClientRPCResponseResult < SecretFilesMessage > > {
24+ ) : AsyncGenerator < ClientRPCResponseResult < SecretFilesMessage > , void , void > {
3025 const { db, vaultManager } : { db : DB ; vaultManager : VaultManager } =
3126 this . container ;
3227 const vaultId = await db . withTransactionF ( async ( tran ) => {
@@ -41,33 +36,34 @@ class VaultsSecretsList extends ServerHandler<
4136 } ) ;
4237
4338 yield * vaultManager . withVaultsG ( [ vaultId ] , ( vault ) => {
44- return vault . readG (
45- async function * ( fs ) : AsyncGenerator < SecretFilesMessage > {
46- let files : Array < string | Buffer > ;
47- try {
48- files = await fs . promises . readdir ( input . secretName ) ;
49- } catch ( e ) {
50- if ( e . code === 'ENOENT' ) {
51- throw new vaultsErrors . ErrorSecretsDirectoryUndefined ( e . message , {
52- cause : e ,
53- } ) ;
54- }
55- if ( e . code === 'ENOTDIR' ) {
56- throw new vaultsErrors . ErrorSecretsIsSecret ( e . message , {
57- cause : e ,
58- } ) ;
59- }
60- throw e ;
39+ return vault . readG ( async function * ( fs ) : AsyncGenerator <
40+ SecretFilesMessage ,
41+ void ,
42+ void
43+ > {
44+ let files : Array < string | Buffer > ;
45+ try {
46+ files = await fs . promises . readdir ( input . secretName ) ;
47+ } catch ( e ) {
48+ if ( e . code === 'ENOENT' ) {
49+ throw new vaultsErrors . ErrorSecretsDirectoryUndefined ( e . message , {
50+ cause : e ,
51+ } ) ;
6152 }
62- for await ( const file of files ) {
63- ctx . signal . throwIfAborted ( ) ;
64- const filePath = path . join ( input . secretName , file . toString ( ) ) ;
65- const stat = await fs . promises . stat ( filePath ) ;
66- const type = stat . isFile ( ) ? 'FILE' : 'DIRECTORY' ;
67- yield { path : filePath , type : type } ;
53+ if ( e . code === 'ENOTDIR' ) {
54+ throw new vaultsErrors . ErrorSecretsIsSecret ( e . message , {
55+ cause : e ,
56+ } ) ;
6857 }
69- } ,
70- ) ;
58+ throw e ;
59+ }
60+ for await ( const file of files ) {
61+ const filePath = path . join ( input . secretName , file . toString ( ) ) ;
62+ const stat = await fs . promises . stat ( filePath ) ;
63+ const type = stat . isFile ( ) ? 'FILE' : 'DIRECTORY' ;
64+ yield { path : filePath , type : type } ;
65+ }
66+ } ) ;
7167 } ) ;
7268 } ;
7369}
0 commit comments