31 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-08-31 20:51:14 -07:00
import { ApiVersion, getApiRoot } from '@datahub/utils/api/shared';
import { getJSON } from '@datahub/utils/api/fetcher';
import { encodeUrn } from '@datahub/utils/validators/urn';
/**
* Constructs the Dataset url root endpoint
* @param {ApiVersion} version the version of the api applicable to retrieve the Dataset
2019-08-31 20:51:14 -07:00
* @returns {string}
*/
const datasetUrlRoot = (version: ApiVersion): string => `${getApiRoot(version)}/datasets`;
2019-08-31 20:51:14 -07:00
/**
* Constructs the url for a dataset identified by the provided string urn
* @param {string} urn the urn to use in querying for dataset entity
* @returns {string}
*/
export const datasetUrlByUrn = (urn: string): string => `${datasetUrlRoot(ApiVersion.v2)}/${encodeUrn(urn)}`;
/**
* Constructs the url for a dataset identified by the provided string urn
* @param {string} urn the urn to use in querying for dataset entity
* @returns {string}
*/
export const datasetV1UrlByUrn = (urn: string): string => `${datasetUrlRoot(ApiVersion.v1)}/${encodeUrn(urn)}`;
2019-08-31 20:51:14 -07:00
/**
* Reads a dataset entity from api
2019-08-31 20:51:14 -07:00
*/
export const readDataset = (urn: string): Promise<Com.Linkedin.Dataset.Dataset> =>
getJSON({ url: datasetUrlByUrn(urn) });