import { ENTITY_TYPES, EntityType } from '../constants/Repository.constants'; import { ParsePartitionKeyResult } from './ParsePartitionKey.types'; import { InternalServerError } from '../errors'; export function parsePartitionKey(type: string): ParsePartitionKeyResult { const entityTypes = Object.values(ENTITY_TYPES).join('|'); const matches = type.match(new RegExp(`^(?${entityTypes})~(?.+)$`)); if (matches?.groups) { return { entityType: matches.groups.entityType as EntityType, tenant: matches.groups.tenant, }; } throw new InternalServerError(`'${type}' is an invalid type`); }