opaqueid
Version:
A basic opaque ID generator with support for types and metadata.
35 lines (34 loc) • 1.19 kB
TypeScript
/**
* Base64 encodes a string.
* @param b The string to encode.
*/
export declare function encode(str: string): string;
/**
* Base64 decodes a string
* @param encoded The Base64 encoded string.
*/
export declare function decode(encoded: string): string;
/**
* Generates a base64 encoded opaque ID for an entity.
* The default type is an empty string.
* @param id The original ID.
* @param type The type of the entity.
*/
export declare function encodeId<T extends Object = Object>(id: string | number, type?: string, metadata?: T): string;
/**
* Decodes a base64 encoded ID for an entity.
* @param encodedId The base64 encoded ID.
* @param type The expected type of the entity.
*/
export declare function decodeId(encodedId: string, type?: string): string | number;
/**
* Returns the opaque ID's entity type.
* @param encodedId The opaque ID to check.
*/
export declare function getIdType(encodedId: string): string | undefined;
/**
* Returns the opaque ID's metadata.
* @param encodedId The base64 encoded ID.
* @param type The expected type of the entity.
*/
export declare function getIdMetadata<T extends Object>(encodedId: string, type?: string): T | undefined;