All files / common/src/annotation/context/registry annotation-context.registry.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 4/4
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39  10x     10x 10x         10x 76x 76x     1706x                   61x   22x       61x              
import { AnnotationContext } from '../../annotation-context';
import { AnnotationRef } from '../../annotation-ref';
import { Annotation } from '../../annotation.types';
import type { AnnotationTargetFactory } from '../../target/annotation-target.factory';
import { _AnnotationContextSet } from './annotation-context-set';
import { AnnotationByTargetSelector } from './by-target-selector';
 
/**
 * Store all registered annotations
 */
export class AnnotationContextRegistry {
  private readonly annotationSet = new _AnnotationContextSet();
  constructor(private targetFactory: AnnotationTargetFactory) {}
 
  register(annotationContext: AnnotationContext) {
    this.annotationSet.addAnnotation(annotationContext);
  }
 
  select(
    ...annotations: (
      | Pick<AnnotationRef, 'groupId' | 'name'>
      | Annotation
      | string
    )[]
  ): AnnotationByTargetSelector {
    const annotationsFilter = annotations.length
      ? new Set(
          annotations.filter((a) => a !== undefined).map(AnnotationRef.of),
        )
      : undefined;
 
    return new AnnotationByTargetSelector(
      this.targetFactory,
      this.annotationSet,
      annotationsFilter,
    );
  }
}