File tree 1 file changed +11
-7
lines changed 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -182,24 +182,28 @@ export class NodeCrud implements crud.CrudApi {
182
182
}
183
183
} ;
184
184
185
- public readonly list = async ( collection : crud . CrudCollection ) : Promise < crud . CrudCollectionEntry [ ] > = > {
186
- assertType ( collection , 'drop ' , 'crudfs' ) ;
185
+ public readonly scan = async function * ( collection : crud . CrudCollection ) : AsyncIterableIterator < crud . CrudCollectionEntry > {
186
+ assertType ( collection , 'scan ' , 'crudfs' ) ;
187
187
const dir = await this . checkDir ( collection ) ;
188
188
const dirents = ( await this . fs . readdir ( dir , { withFileTypes : true } ) ) as IDirent [ ] ;
189
- const entries : crud . CrudCollectionEntry [ ] = [ ] ;
190
189
for await ( const entry of dirents ) {
191
190
if ( entry . isFile ( ) ) {
192
- entries . push ( {
191
+ yield {
193
192
type : 'resource' ,
194
193
id : '' + entry . name ,
195
- } ) ;
194
+ } ;
196
195
} else if ( entry . isDirectory ( ) ) {
197
- entries . push ( {
196
+ yield {
198
197
type : 'collection' ,
199
198
id : '' + entry . name ,
200
- } ) ;
199
+ } ;
201
200
}
202
201
}
202
+ } ;
203
+
204
+ public readonly list = async ( collection : crud . CrudCollection ) : Promise < crud . CrudCollectionEntry [ ] > => {
205
+ const entries : crud . CrudCollectionEntry [ ] = [ ] ;
206
+ for await ( const entry of this . scan ( collection ) ) entries . push ( entry ) ;
203
207
return entries ;
204
208
} ;
205
209
You can’t perform that action at this time.
0 commit comments