import {IKey} from "./IKey"; export class Key implements IKey{ primaryKey: string; secondaryKey: string; constructor(primaryKey?: string, secondaryKey?: string) { this.primaryKey = primaryKey; this.secondaryKey = secondaryKey; } asSingleComponentKey(): string { return Key.asSingleComponentKey(this.primaryKey, this.secondaryKey); } static asSingleComponentKey(primaryKey: string , secondaryKey: string): string { if (primaryKey == null) { throw new Error("primary key cannot be null"); } return `${primaryKey}${(secondaryKey == null) || (secondaryKey === "") ? "" : `:${secondaryKey}`}`; } static fromSingleComponentKey(source: string): IKey { if (source == null) { throw new Error("source cannot be null"); } const components = source.split(":"); if (components.length < 2) { return new Key(source, ""); } const primaryKey = components.slice(0, components.length - 2).join(":"); const secondaryKey = components[components.length - 1]; return new Key(primaryKey, secondaryKey); } }