1+ import type { ContextTimed } from '@matrixai/contexts' ;
12import type { DB } from '@matrixai/db' ;
3+ import type { JSONValue } from '@matrixai/rpc' ;
24import type {
35 ClientRPCRequestParams ,
46 ClientRPCResponseResult ,
@@ -21,7 +23,10 @@ class VaultsSecretsList extends ServerHandler<
2123> {
2224 public handle = async function * (
2325 input : ClientRPCRequestParams < SecretIdentifierMessage > ,
24- ) : AsyncGenerator < ClientRPCResponseResult < SecretFilesMessage > , void , void > {
26+ _cancel : ( reason ?: any ) => void ,
27+ _meta : Record < string , JSONValue > ,
28+ ctx : ContextTimed ,
29+ ) : AsyncGenerator < ClientRPCResponseResult < SecretFilesMessage > > {
2530 const { db, vaultManager } : { db : DB ; vaultManager : VaultManager } =
2631 this . container ;
2732 const vaultId = await db . withTransactionF ( async ( tran ) => {
@@ -36,34 +41,33 @@ class VaultsSecretsList extends ServerHandler<
3641 } ) ;
3742
3843 yield * vaultManager . withVaultsG ( [ vaultId ] , ( vault ) => {
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- } ) ;
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 ;
5261 }
53- if ( e . code === 'ENOTDIR' ) {
54- throw new vaultsErrors . ErrorSecretsIsSecret ( e . message , {
55- cause : e ,
56- } ) ;
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 } ;
5768 }
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- } ) ;
69+ } ,
70+ ) ;
6771 } ) ;
6872 } ;
6973}
0 commit comments