2018-02-14 16:00:32 -08:00
|
|
|
import { ApiVersion, getApiRoot } from 'wherehows-web/utils/api/shared';
|
2018-03-07 11:15:11 -08:00
|
|
|
import buildUrl from 'wherehows-web/utils/build-url';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { encodeForwardSlash } from '@datahub/utils/validators/urn';
|
|
|
|
import { IReadDatasetsOptionBag } from '@datahub/data-models/types/entity/dataset';
|
|
|
|
import { datasetUrlRoot } from '@datahub/data-models/api/dataset/dataset';
|
2017-08-24 00:23:48 -07:00
|
|
|
|
|
|
|
/**
|
2019-08-31 20:51:14 -07:00
|
|
|
* Base url / root for metrics endpoints
|
|
|
|
* @param {ApiVersion} version
|
|
|
|
* @returns {string}
|
2017-08-24 00:23:48 -07:00
|
|
|
*/
|
2019-08-31 20:51:14 -07:00
|
|
|
export const metricsUrlRoot = (version: ApiVersion): string => `${getApiRoot(version)}/metrics`;
|
2017-08-24 00:23:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a url to get a dataset with a given id
|
|
|
|
* @param {number} id the id of the dataset
|
|
|
|
* @return {string} the dataset url
|
|
|
|
*/
|
2019-08-31 20:51:14 -07:00
|
|
|
export const datasetUrlById = (id: number): string => `${datasetUrlRoot(ApiVersion.v1)}/${id}`;
|
2018-02-14 16:00:32 -08:00
|
|
|
|
2018-02-14 20:47:26 -08:00
|
|
|
/**
|
|
|
|
* Composes a url to get a specific dataset by urn
|
|
|
|
* @param {string} urn
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2019-08-31 20:51:14 -07:00
|
|
|
export const datasetUrlByUrn = (urn: string): string => `${datasetUrlRoot(ApiVersion.v2)}/${urn}`;
|
2018-02-14 16:00:32 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Composes the datasets url using the platform and prefix if one is provided
|
|
|
|
* @param {IReadDatasetsOptionBag} { platform, prefix }
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2018-03-07 11:15:11 -08:00
|
|
|
export const datasetsUrl = ({ platform, prefix, start = 0 }: IReadDatasetsOptionBag): string => {
|
2019-08-31 20:51:14 -07:00
|
|
|
const urlRoot = datasetUrlRoot(ApiVersion.v2);
|
2018-03-07 11:15:11 -08:00
|
|
|
let url = urlRoot;
|
2018-02-14 16:00:32 -08:00
|
|
|
|
|
|
|
if (platform) {
|
2018-03-07 11:15:11 -08:00
|
|
|
url = `${urlRoot}/platform/${platform}`;
|
2018-03-08 10:21:01 -08:00
|
|
|
|
|
|
|
if (prefix) {
|
|
|
|
url = `${urlRoot}/platform/${platform}/prefix/${encodeForwardSlash(prefix)}`;
|
|
|
|
}
|
2018-02-14 16:00:32 -08:00
|
|
|
}
|
|
|
|
|
2018-03-07 11:15:11 -08:00
|
|
|
return buildUrl(url, 'start', `${start}`);
|
2018-02-14 16:00:32 -08:00
|
|
|
};
|