feat(db): add listRef utility to get ref list from filter

This commit is contained in:
Julien Oculi 2024-06-18 15:42:12 +02:00
parent 28a517323b
commit 007f9deee0

View file

@ -2,6 +2,7 @@ import {
Credential, Credential,
Group, Group,
Machine, Machine,
type Ref,
type Ressource, type Ressource,
Service, Service,
User, User,
@ -58,6 +59,15 @@ export class Db {
list: ( list: (
filter: (ressource: T) => boolean | Promise<boolean> = () => true, filter: (ressource: T) => boolean | Promise<boolean> = () => true,
) => this.#list<T>(type, Builder, filter), ) => this.#list<T>(type, Builder, filter),
listRef: async (
filter: (ressource: T) => boolean | Promise<boolean> = () => true,
) => {
const ressources: Ref<T>[] = []
for await (const ressource of this.#list<T>(type, Builder, filter)) {
ressources.push(ressource.toRef() as Ref<T>)
}
return ressources
},
} }
} }