Commit 46445c1d authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout d'une méthode APIMetadataRegistry.has.

parent dee6cd84
......@@ -253,6 +253,11 @@ export interface APIMeta {
* Classe abstraite d'un registre des metadonnées des ressources.
*/
export interface APIMetadataRegistry<API extends APIMeta> {
/**
* Vérifie si on a des métadonnées pour le type de ressourcce indiqué.
*/
has<T extends keyof API>(type: T): type is T;
/**
* (Construit et) retourne l'instance de métadonnées pour le type de resource 'type'.
*/
......@@ -270,8 +275,12 @@ export class LazyMetadataRegistry<API extends APIMeta> implements APIMetadataReg
private readonly builders: { readonly [T in keyof API]: (r?: APIMetadataRegistry<API>) => API[T]['metadata'] }
) {}
public has<T extends keyof API>(type: T): type is T {
return typeof type === 'string' && type in this.builders;
}
public get<T extends keyof API>(type: T): API[T]['metadata'] {
if (typeof type !== 'string' || !(type in this.builders)) {
if (!this.has(type)) {
throw new Error(`Invalid resource type: ${type}`);
}
return this.getOrCreate(type);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment