Commits
Lotte Hofstede authored 57aa58ac56d Merge
1 + | import "reflect-metadata"; |
1 2 | import { GenericConstructor } from "../../shared/generic-constructor"; |
2 3 | import { CacheableObject } from "../object-cache.reducer"; |
4 + | import { NormalizedDSOType } from "../models/normalized-dspace-object-type"; |
3 5 | |
4 6 | const mapsToMetadataKey = Symbol("mapsTo"); |
5 7 | const relationshipKey = Symbol("relationship"); |
6 8 | |
7 9 | const relationshipMap = new Map(); |
8 10 | |
9 11 | export const mapsTo = function(value: GenericConstructor<CacheableObject>) { |
10 12 | return Reflect.metadata(mapsToMetadataKey, value); |
11 13 | }; |
12 14 | |
13 15 | export const getMapsTo = function(target: any) { |
14 16 | return Reflect.getOwnMetadata(mapsToMetadataKey, target); |
15 17 | }; |
16 18 | |
17 - | export const relationship = function(value: any): any { |
19 + | export const relationship = function(value: NormalizedDSOType): any { |
18 20 | return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { |
19 21 | if (!target || !propertyKey) { |
20 22 | return; |
21 23 | } |
22 24 | |
23 25 | let metaDataList : Array<string> = relationshipMap.get(target.constructor) || []; |
24 26 | if (metaDataList.indexOf(propertyKey) === -1) { |
25 27 | metaDataList.push(propertyKey); |
26 28 | } |
27 29 | relationshipMap.set(target.constructor, metaDataList); |