Skip to content

Commit

Permalink
Document raw to model functions
Browse files Browse the repository at this point in the history
  • Loading branch information
diehuxx committed Feb 6, 2024
1 parent 16e8880 commit 483dc1d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/protocol/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export class Parser {
return resource
}

/**
* Util for JSON.parse-ing a stringified Tbdex Message
* @param rawMessage - Either a stringified Tbdex Message or an object Tbdex Message
* @returns A Tbdex Message as an object
* @throws If the stringified message could not be JSON.parse'd
*/
static rawToMessageModel(rawMessage: MessageModel | string): MessageModel {
try {
return typeof rawMessage === 'string' ? JSON.parse(rawMessage): rawMessage
Expand All @@ -116,6 +122,12 @@ export class Parser {
}
}

/**
* Util for JSON.parse-ing a stringified Tbdex resource
* @param rawMessage - Either a stringified Tbdex resource or an object Tbdex resource
* @returns A Tbdex message as an object
* @throws If the stringified resource could not be JSON.parse'd
*/
static rawToResourceModel(rawMessage: ResourceModel | string): ResourceModel {
try {
return typeof rawMessage === 'string' ? JSON.parse(rawMessage): rawMessage
Expand Down

0 comments on commit 483dc1d

Please sign in to comment.