import { ensureReflectMetadataExists } from "type-graphql/dist/metadata/utils"; import { ClassType } from "type-graphql"; import { IPermission, IResource, ClassTypeResolver, TypeValueThunk, TypeOptions, } from "../helpers"; export class MetadataStorage { fields: FilterableMetadata[] = []; resources: ResourceMetadata[] = []; permissions: PermissionMetadata[] = []; instances: InstanceMetadata[] = []; constructor() { ensureReflectMetadataExists(); } collectClassFieldMetadata(definition: FilterableMetadata) { this.fields.push(definition); } collectPermissionsMetadata(definition: PermissionMetadata) { this.permissions.push(definition); } collectResourcesMetadata(definition: ResourceMetadata) { this.resources.push(definition); } collectInstanceMetadata(definition: InstanceMetadata) { this.instances.push(definition); } clear() { this.fields = []; this.resources = []; this.permissions = []; this.instances = []; } } export interface FilterableMetadata { getType?: TypeValueThunk; typeOptions?: TypeOptions | null; getObjectType?: ClassTypeResolver; methodName: string; fieldType: string | ClassType; name: string; // tslint:disable-next-line:ban-types target: Function; objectType: any; filterSchema?: any; } export interface PermissionMetadata { getType?: TypeValueThunk; typeOptions?: TypeOptions | null; getObjectType?: ClassTypeResolver; methodName: string; fieldType: string | ClassType; name: string; // tslint:disable-next-line:ban-types target: Function; objectType: any; filterSchema?: any; options?: IPermission; } export interface ResourceMetadata { prototype?: any; fieldType: string | ClassType; name: string; // tslint:disable-next-line:ban-types target: Function; objectType: any; options?: IResource; } export interface InstanceMetadata { prototype?: any; getObjectType?: ClassTypeResolver; fieldType: string | ClassType; name: string; // tslint:disable-next-line:ban-types target: Function; objectType: any; }