| 
									
										
										
										
											2018-07-19 16:18:06 -07:00
										 |  |  | import { getJSON, returnDefaultIfNotFound } from 'wherehows-web/utils/api/fetcher'; | 
					
						
							| 
									
										
										
										
											2018-05-17 23:46:03 -07:00
										 |  |  | import { datasetUrlByUrn } from 'wherehows-web/utils/api/datasets/shared'; | 
					
						
							| 
									
										
										
										
											2018-05-21 00:19:45 -07:00
										 |  |  | import { encodeUrn } from 'wherehows-web/utils/validators/urn'; | 
					
						
							| 
									
										
										
										
											2018-09-13 20:26:48 -07:00
										 |  |  | import { LineageList } from 'wherehows-web/typings/api/datasets/relationships'; | 
					
						
							| 
									
										
										
										
											2018-05-17 23:46:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Constructs the url for a datasets upstreams | 
					
						
							|  |  |  |  * @param {string} urn the urn for the child dataset | 
					
						
							|  |  |  |  * @return {string} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const datasetUpstreamUrlByUrn = (urn: string): string => `${datasetUrlByUrn(urn)}/upstreams`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-19 16:18:06 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Constructs the url for a datasets downstreams | 
					
						
							|  |  |  |  * @param {string} urn | 
					
						
							|  |  |  |  * @return {string} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const datasetDownstreamUrlByUrn = (urn: string): string => `${datasetUrlByUrn(urn)}/downstreams`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 23:46:03 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Fetches the list of upstream datasets for a dataset by urn | 
					
						
							|  |  |  |  * @param {string} urn urn for the child dataset | 
					
						
							|  |  |  |  * @return {Promise<Array<IDatasetView>>} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-13 20:26:48 -07:00
										 |  |  | const readUpstreamDatasetsByUrn = (urn: string): Promise<LineageList> => | 
					
						
							|  |  |  |   returnDefaultIfNotFound(getJSON<LineageList>({ url: datasetUpstreamUrlByUrn(encodeUrn(urn)) }), []); | 
					
						
							| 
									
										
										
										
											2018-05-17 23:46:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-19 16:18:06 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Requests the downstream datasets for the dataset identified by urn | 
					
						
							|  |  |  |  * @param {string} urn string urn for the dataset | 
					
						
							|  |  |  |  * @return {Promise<Array<IDatasetView>>} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-13 20:26:48 -07:00
										 |  |  | const readDownstreamDatasetsByUrn = (urn: string): Promise<LineageList> => | 
					
						
							|  |  |  |   returnDefaultIfNotFound(getJSON<LineageList>({ url: datasetDownstreamUrlByUrn(encodeUrn(urn)) }), []); | 
					
						
							| 
									
										
										
										
											2018-07-19 16:18:06 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export { readUpstreamDatasetsByUrn, readDownstreamDatasetsByUrn }; |