mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-04 23:38:01 +00:00
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
![]() |
import { DatasetEntity } from '@datahub/data-models/entity/dataset/dataset-entity';
|
||
|
|
||
|
/**
|
||
|
* Defines the interface for the DataModelEntity enum below.
|
||
|
* This allows each entry in the enum to be indexable
|
||
|
*/
|
||
|
interface IDataModelEntity {
|
||
|
[DatasetEntity.displayName]: typeof DatasetEntity;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Enumeration of data model entity displayName values to the related Data Model entity
|
||
|
* Serves as the primary resource map of all DataModelEntity available classes
|
||
|
*/
|
||
|
export const DataModelEntity: IDataModelEntity = {
|
||
|
[DatasetEntity.displayName]: DatasetEntity
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Aliases the keys on the DataModelEntity enum for reference convenience
|
||
|
* This maps to the names of the available entities for example 'datasets', 'users', etc
|
||
|
*/
|
||
|
export type DataModelName = keyof typeof DataModelEntity;
|
||
|
|
||
|
/**
|
||
|
* Aliases the DataModelEntity classes found in the DataModelEntity enum, this is a union type of all entity classifiers
|
||
|
* For example { DatasetEntity | UserEntity | ... }
|
||
|
*/
|
||
|
export type DataModelEntity = typeof DataModelEntity[DataModelName];
|
||
|
|
||
|
/**
|
||
|
* Guards on a string entityName if it maps to an entity data model (class inheriting from BaseEntity)
|
||
|
* @param {string} entityName the displayName to match against for DataModelEntity types
|
||
|
*/
|
||
|
export const isDataModelBaseEntityName = (entityName: DataModelName): boolean =>
|
||
|
Object.values(DataModelEntity)
|
||
|
.mapBy('displayName')
|
||
|
.includes(entityName);
|