import { ICollection , ModelId } from '.' ; param { Collection < * > } source param { Array < string > } ids param { keyof T } field export function referenceOne < T , K extends keyof T > ( source , id ) ; export function referenceOne < T , K extends keyof T > ( source , ids ) ; export function referenceOne < T , K extends keyof T > ( source , id , field ? ) ; export function referenceOne < T , K extends keyof T > ( source , ids , field ? ) ; export function referenceOne < T , K extends keyof T > ( source , ids , field ? ) { if ( Array . isArray ( ids ) ) { return ids . map ( id => referenceOne ( source , id , field ) ) . filter ( Boolean ) as Array < T > ; } if ( field !== undefined ) { return source . find ( x => x [ field ] === ids ) || null ; } return source . get ( ids ) || null ; } param { Collection < * > } source param { Array < string > } ids param { keyof T } field export function referenceMany < T , K extends keyof T > ( source , ids , field ) { if ( Array . isArray ( ids ) ) { const result = ids . map ( id => referenceMany ( source , id , field ) ) . filter ( Boolean ) ; return [ ] . concat . apply ( [ ] , result as any ) ; } return source . filter ( x => x [ field ] === ids ) ; }