Skip to content

Commit

Permalink
Cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenbf committed Oct 5, 2023
1 parent 448c4c6 commit 72b0325
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/sdk/src/pub/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export {
isJsonParseError,
TypedJsonParseError,
TypedJsonParseErrorType,
TypedJson,
ToTypedJson,
} from '../types/util.js';

// These cannot be exported directly as modules because of a bug in an eslint plugin.
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/DataBlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Json = HexString;
export class DataBlob extends TypeBase<Json> {
protected jsonType = JSON_TYPE;
protected get jsonValue(): string {
// TODO: why is this prefixed with length of data?
return packBufferWithWord16Length(this.data).toString('hex');
}
public readonly data: Buffer;
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/types/ModuleReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Json = HexString;
class ModuleReference extends TypeBase<Json> {
protected jsonType = JSON_TYPE;
protected get jsonValue(): Json {
// TODO: why?
// TODO: why is this prefixed with length of data?
return packBufferWithWord32Length(this.decodedModuleRef).toString(
'hex'
);
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/types/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { JsonString } from '../types.js';

/**
* Discriminator for {@link TypedJson}.
* Discriminator for {@link TypedJson}. The member used to identify each type is
* exported from each type module and can be accessed through named export `JSON_TYPE`.
*/
export enum TypedJsonDiscriminator {
AccountAddress = 'ccd_account_address',
Expand Down Expand Up @@ -91,6 +92,7 @@ export class TypedJsonParseError extends Error {
message: string
) {
super(message);
this.name = 'TypedJsonParseError'; // convention for discriminating between error types.
}

public static fromParseValueError(e: unknown): TypedJsonParseError {
Expand All @@ -104,7 +106,7 @@ export class TypedJsonParseError extends Error {
/**
* Determines if error is of type {@link TypedJsonParseError}
*/
export const isJsonParseError = (
export const isTypedJsonParseError = (
error: unknown
): error is TypedJsonParseError => error instanceof TypedJsonParseError;

Expand All @@ -116,7 +118,11 @@ interface Class<V, T> {
* Creates a function to convert typed JSON strings to their corresponding type instance.
*
* @template V - The JSON value
* @template T - The type returned
*
* @param {D} expectedTypeDiscriminator - The discriminator expected in the JSON string parsed
* @param {Class} Class - A class which can be instantiated with a single parameter of type `V`
*
* @returns The JSON parser function
*/
export function fromTypedJson<V, T>(
Expand Down

0 comments on commit 72b0325

Please sign in to comment.