From 47be78f6c8a5b70bbf9c5fc6d2b3000312df19c8 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Wed, 20 Mar 2024 14:24:47 +0300 Subject: [PATCH] Fixes doc comments from PR review. --- .../src/serialization/untypedArray.ts | 18 ++++++++++++-- .../src/serialization/untypedBoolean.ts | 18 ++++++++++++-- .../src/serialization/untypedNode.ts | 23 +++++++++++++++++- .../src/serialization/untypedNull.ts | 15 +++++++++++- .../src/serialization/untypedNumber.ts | 18 ++++++++++++-- .../src/serialization/untypedObject.ts | 24 +++++++++++++++---- .../src/serialization/untypedString.ts | 18 ++++++++++++-- 7 files changed, 120 insertions(+), 14 deletions(-) diff --git a/packages/abstractions/src/serialization/untypedArray.ts b/packages/abstractions/src/serialization/untypedArray.ts index dd05f69e7..d97649195 100644 --- a/packages/abstractions/src/serialization/untypedArray.ts +++ b/packages/abstractions/src/serialization/untypedArray.ts @@ -1,9 +1,18 @@ import { isUntypedNode, UntypedNode } from "./untypedNode"; +/** Defines an interface for defining an untyped array. */ export interface UntypedArray extends UntypedNode { + /** + * Gets the value of the UntypedNode as an array of UntypedNodes. + */ getValue(): UntypedNode[]; } +/** + * Type guard to assert that an UntypedNode instance is an UntypedArray. + * @param node The UntypedNode to check. + * @return boolean indicating if the node is an UntypedArray. + */ export function isUntypedArray(node: UntypedNode): node is UntypedArray { const proposedNode = node as UntypedArray; return ( @@ -13,9 +22,14 @@ export function isUntypedArray(node: UntypedNode): node is UntypedArray { ); } +/** + * Factory to create an UntypedArray from an array of UntypedNodes. + * @param value The value to create from. + * @return The created UntypedArray. + */ export function createUntypedArray(value: UntypedNode[]): UntypedArray { return { value: value, - getValue: () => value as UntypedNode[], + getValue: () => value as UntypedNode[], }; -} \ No newline at end of file +} diff --git a/packages/abstractions/src/serialization/untypedBoolean.ts b/packages/abstractions/src/serialization/untypedBoolean.ts index 469858294..9e71190d2 100644 --- a/packages/abstractions/src/serialization/untypedBoolean.ts +++ b/packages/abstractions/src/serialization/untypedBoolean.ts @@ -1,17 +1,31 @@ import { UntypedNode } from "./untypedNode"; +/** Defines an interface for defining an untyped boolean. */ export interface UntypedBoolean extends UntypedNode { + /** + * Gets the value of the UntypedNode as a boolean value. + */ getValue(): boolean; } +/** + * Type guard to assert that an UntypedNode instance is an UntypedBoolean. + * @param node The UntypedNode to check. + * @return boolean indicating if the node is an UntypedBoolean. + */ export function isUntypedBoolean(node: UntypedNode): node is UntypedBoolean { const proposedNode = node as UntypedBoolean; return proposedNode && typeof proposedNode.value === "boolean"; } +/** + * Factory to create an UntypedBoolean from a boolean. + * @param value The boolean value to create from. + * @return The created UntypedBoolean. + */ export function createUntypedBoolean(value: boolean): UntypedBoolean { return { value: value, - getValue: () => value as boolean, + getValue: () => value as boolean, }; -} \ No newline at end of file +} diff --git a/packages/abstractions/src/serialization/untypedNode.ts b/packages/abstractions/src/serialization/untypedNode.ts index 6cc2b258d..314d4b9ea 100644 --- a/packages/abstractions/src/serialization/untypedNode.ts +++ b/packages/abstractions/src/serialization/untypedNode.ts @@ -3,22 +3,40 @@ import type { Parsable } from "./parsable"; import type { ParseNode } from "./parseNode"; import type { SerializationWriter } from "./serializationWriter"; +/** Defines the base interface for defining an untyped node. */ export interface UntypedNode extends Parsable { - getValue(): any + /** + * Gets the value of the UntypedNode. + */ + getValue(): any; + /** + * The value represented by the UntypedNode. + */ value?: any; } +/** + * Factory to create an UntypedNode from a string during deserialization. + */ export function createUntypedNodeFromDiscriminatorValue( _parseNode: ParseNode | undefined, ): (instance?: Parsable) => Record void> { return deserializeIntoUntypedNode; } +/** + * Type guard to assert that an object instance is an UntypedNode. + * @param node The object to check. + * @return boolean indicating if the node is an UntypedNode. + */ export function isUntypedNode(node: any): node is UntypedNode { const potentialNode = node as UntypedNode; return potentialNode && potentialNode.getValue !== undefined; } +/** + * The deserialization implementation for UntypedNode. + */ export function deserializeIntoUntypedNode( untypedNode: Partial | undefined = {}, ): Record void> { @@ -32,6 +50,9 @@ export function deserializeIntoUntypedNode( }; } +/** + * The serialization implementation for UntypedNode. + */ export function serializeUntypedNode( _writer: SerializationWriter, _errorDetails: Partial | undefined = {}, diff --git a/packages/abstractions/src/serialization/untypedNull.ts b/packages/abstractions/src/serialization/untypedNull.ts index 0282b3462..bd7076c70 100644 --- a/packages/abstractions/src/serialization/untypedNull.ts +++ b/packages/abstractions/src/serialization/untypedNull.ts @@ -1,16 +1,29 @@ import { UntypedNode } from "./untypedNode"; +/** Defines the interface for defining an untyped null value. */ export interface UntypedNull extends UntypedNode { + /** + * Gets the value of the UntypedNode as null. + */ getValue(): null; } +/** + * Type guard to assert that an object instance is an UntypedNull. + * @param node The object to check. + * @return boolean indicating if the node is an UntypedNull. + */ export function isUntypedNull(node: UntypedNode): node is UntypedNull { return node.value === null; } +/** + * Factory to create an UntypedNull from a boolean. + * @return The created UntypedNull. + */ export function createUntypedNull(): UntypedNull { return { value: null, - getValue: () => null, + getValue: () => null, }; } diff --git a/packages/abstractions/src/serialization/untypedNumber.ts b/packages/abstractions/src/serialization/untypedNumber.ts index ec225cd4d..42822e1df 100644 --- a/packages/abstractions/src/serialization/untypedNumber.ts +++ b/packages/abstractions/src/serialization/untypedNumber.ts @@ -1,17 +1,31 @@ import { UntypedNode } from "./untypedNode"; +/** Defines the interface for defining an untyped number value. */ export interface UntypedNumber extends UntypedNode { + /** + * Gets the value of the UntypedNode as a number. + */ getValue(): number; } +/** + * Type guard to assert that an object instance is an UntypedNumber. + * @param node The object to check. + * @return boolean indicating if the node is an UntypedNumber. + */ export function isUntypedNumber(node: UntypedNode): node is UntypedNumber { const proposedNode = node as UntypedNumber; return proposedNode && typeof proposedNode.value === "number"; } +/** + * Factory to create an UntypedNumber from a number. + * @param value The number value to create from. + * @return The created UntypedNumber. + */ export function createUntypedNumber(value: number): UntypedNumber { return { value: value, - getValue: () => value as number, + getValue: () => value as number, }; -} \ No newline at end of file +} diff --git a/packages/abstractions/src/serialization/untypedObject.ts b/packages/abstractions/src/serialization/untypedObject.ts index c3022a917..83c57f451 100644 --- a/packages/abstractions/src/serialization/untypedObject.ts +++ b/packages/abstractions/src/serialization/untypedObject.ts @@ -1,9 +1,18 @@ import { isUntypedNode, UntypedNode } from "./untypedNode"; +/** Defines the interface for defining an untyped object value. */ export interface UntypedObject extends UntypedNode { - getValue(): Record ; + /** + * Gets the value of the UntypedNode as a Record. + */ + getValue(): Record; } +/** + * Type guard to assert that an object instance is an UntypedObject. + * @param node The object to check. + * @return boolean indicating if the node is an UntypedObject. + */ export function isUntypedObject(node: UntypedNode): node is UntypedObject { const proposedNode = node as UntypedObject; return ( @@ -14,9 +23,16 @@ export function isUntypedObject(node: UntypedNode): node is UntypedObject { ); } -export function createUntypedObject(value: Record): UntypedObject { +/** + * Factory to create an UntypedObject from a Record. + * @param value The Record value to create from. + * @return The created UntypedObject. + */ +export function createUntypedObject( + value: Record, +): UntypedObject { return { value: value, - getValue: () => value as Record, + getValue: () => value as Record, }; -} \ No newline at end of file +} diff --git a/packages/abstractions/src/serialization/untypedString.ts b/packages/abstractions/src/serialization/untypedString.ts index 57c7b9234..cbcbd6300 100644 --- a/packages/abstractions/src/serialization/untypedString.ts +++ b/packages/abstractions/src/serialization/untypedString.ts @@ -1,17 +1,31 @@ import { UntypedNode } from "./untypedNode"; +/** Defines the interface for defining an untyped string value. */ export interface UntypedString extends UntypedNode { + /** + * Gets the value of the UntypedNode as a Record. + */ getValue(): string; } +/** + * Type guard to assert that an object instance is an UntypedString. + * @param node The object to check. + * @return boolean indicating if the node is an UntypedString. + */ export function isUntypedString(node: UntypedNode): node is UntypedString { const proposedNode = node as UntypedString; return proposedNode && typeof proposedNode.value === "string"; } +/** + * Factory to create an UntypedString from a string. + * @param value The string value to create from. + * @return The created UntypedString. + */ export function createUntypedString(value: string): UntypedString { return { value: value, - getValue: () => value as string, + getValue: () => value as string, }; -} \ No newline at end of file +}