declare module '@compassdigital/id/interface' { export type EncodedID = string; export interface DecodedID { service: string; provider: string; type: string; id: string; } export interface Constraints extends Partial { prefix?: string; } } declare module '@compassdigital/id' { import { DecodedID, EncodedID, Constraints } from '@compassdigital/id/interface'; /** * ID is a utility function which both encodes and decodes CDL ids using a * bespoke encoding scheme. * * - If a string is provided, it will be decoded to an id object. * - If an id object is provided, it will be encoded to a string. * - If a falsy value is provided, undefined will be returned. * - If 4 string parameters are provided, they will be used to construct an * id object which will then be encoded to a string. */ function ID( service: string, provider: string, type: string, id: string | number ): string; function ID(decoded: DecodedID): string; function ID(encoded: string): DecodedID | undefined; function ID(encoded: string | undefined): DecodedID | undefined; function ID(decoded: DecodedID | undefined): string | undefined; namespace ID { export class CompassDigitalId { static word_shortform(longform: string): string | undefined; static word_longform(shortform: string): string | undefined; static encode(config: DecodedID): string; static valid(id?: string): boolean; static decode(id?: string): DecodedID | undefined; } /** * Check if the provided id contains one or more properties. * * Ex: check if it's a device id * * ID.contains(id, { service: "kds", provider: "cdl", type: "device" }) * * @param id - encoded or decoded id * @param constraints - id properties to check for * @return true if constraints are satisfied */ function contains(id: EncodedID | undefined, constraints: Constraints): id is EncodedID; function contains(id: DecodedID | undefined, constraints: Constraints): id is DecodedID; /** * If id is an encoded cdl id, decode it and check it against the provided constraints. * If it matches, return the inner id. Otherwise return the original value. * * @param id - cdlid or decoded cdlid id * @return inner id */ function unwrap(id: string, constraints?: Constraints): string; function unwrap(id: string | undefined, constraints?: Constraints): string | undefined; /** * Split the prefix from the inner id. * If there's no prefix, return the fallback prefix. * If no fallback is provided, the prefix will be undefined. * * Example: tacit/be6eeceeb2c811edafa10242ac120002 */ function split(id: string): [string | undefined, string]; function split(id: string, fallback: string): [string, string]; } export = ID; }