| 
									
										
										
										
											2017-01-26 14:03:53 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @dgService getDocFromAlias | 
					
						
							|  |  |  |  * @description Get an array of docs that match this alias, relative to the originating doc. | 
					
						
							| 
									
										
										
										
											2018-02-28 14:52:29 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @property {Array<(alias: string, originatingDoc: Doc, ambiguousDocs: Doc[]) => Doc[]>} disambiguators | 
					
						
							|  |  |  |  *           a collection of functions that attempt to resolve ambiguous links. Each disambiguator returns | 
					
						
							|  |  |  |  *           a new collection of docs with unwanted ambiguous docs removed (see links-package/service/disambiguators | 
					
						
							|  |  |  |  *           for examples). | 
					
						
							| 
									
										
										
										
											2017-01-26 14:03:53 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-01 21:34:10 +03:00
										 |  |  | module.exports = function getDocFromAlias(aliasMap) { | 
					
						
							| 
									
										
										
										
											2017-01-26 14:03:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 14:52:29 +00:00
										 |  |  |   getDocFromAlias.disambiguators = []; | 
					
						
							|  |  |  |   return getDocFromAlias; | 
					
						
							| 
									
										
										
										
											2017-01-26 14:03:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 14:52:29 +00:00
										 |  |  |   function getDocFromAlias(alias, originatingDoc) { | 
					
						
							|  |  |  |     return getDocFromAlias.disambiguators.reduce( | 
					
						
							|  |  |  |       // Run the disambiguators while there is more than 1 doc found
 | 
					
						
							|  |  |  |       (docs, disambiguater) => docs.length > 1 ? disambiguater(alias, originatingDoc, docs) : docs, | 
					
						
							|  |  |  |       // Start with the docs that match the alias
 | 
					
						
							|  |  |  |       aliasMap.getDocs(alias) | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-04-01 21:34:10 +03:00
										 |  |  | }; |