UNPKG

@essential-projects/metadata

Version:

the core metadata service for using the metadata from inside the domain

29 lines (22 loc) 1.09 kB
import {ISchemaAttribute} from '@essential-projects/core_contracts'; import {ISchemaAttributeDecorator, MetadataType} from '@essential-projects/metadata_contracts'; import {MetadataProvider} from './../provider'; export function schemaAttribute(schema: ISchemaAttribute, namespace?: string): ISchemaAttributeDecorator { return function schemaAttributeFactory(...args: Array<any>): void|PropertyDescriptor { switch (args.length) { case 3: if (typeof args[2] === 'number') { // this is a parameter descriptor // those should not support schemas } return methodSchemaAttribute.apply(this, [args[0], args[1], args[2], schema, namespace]); default: throw new Error('Decorators are not valid here!'); } }; } export function methodSchemaAttribute(target: any, key: string, descriptor: any, schema: ISchemaAttribute, namespace?: string): PropertyDescriptor { const type: string = target.constructor.name; MetadataProvider.setForType(MetadataType.SchemaAttribute, schema, namespace, type, key); return descriptor; }