Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export function encodeByType(type: string, value: any): string | null {
return (value as Date).getTime().toString();
}

/**
* Support for branded id's having the following structure
*
* interface ConversationId extends String {
* _conversationBrand: string;
* }
*
* the above interface will support toString() method
*/
if (typeof value.toString === 'function') {
return value.toString();
}

break;
}
default: break;
Expand All @@ -38,7 +51,21 @@ export function encodeByType(type: string, value: any): string | null {

export function decodeByType(type: string, value: string): string | number | Date {
switch (type) {
case 'object':
case 'object': {
/**
* Support for branded id's having the following structure
*
* interface ConversationId extends String {
* _conversationBrand: string;
* }
*
* the above interface will support toString() method
*/
if (typeof value.toString === 'function') {
return value.toString();
}
}

case 'date': {
const timestamp = parseInt(value, 10);

Expand Down