Skip to content

Commit 47be78f

Browse files
author
Andrew Omondi
committed
Fixes doc comments from PR review.
1 parent b0ac754 commit 47be78f

File tree

7 files changed

+120
-14
lines changed

7 files changed

+120
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import { isUntypedNode, UntypedNode } from "./untypedNode";
22

3+
/** Defines an interface for defining an untyped array. */
34
export interface UntypedArray extends UntypedNode {
5+
/**
6+
* Gets the value of the UntypedNode as an array of UntypedNodes.
7+
*/
48
getValue(): UntypedNode[];
59
}
610

11+
/**
12+
* Type guard to assert that an UntypedNode instance is an UntypedArray.
13+
* @param node The UntypedNode to check.
14+
* @return boolean indicating if the node is an UntypedArray.
15+
*/
716
export function isUntypedArray(node: UntypedNode): node is UntypedArray {
817
const proposedNode = node as UntypedArray;
918
return (
@@ -13,9 +22,14 @@ export function isUntypedArray(node: UntypedNode): node is UntypedArray {
1322
);
1423
}
1524

25+
/**
26+
* Factory to create an UntypedArray from an array of UntypedNodes.
27+
* @param value The value to create from.
28+
* @return The created UntypedArray.
29+
*/
1630
export function createUntypedArray(value: UntypedNode[]): UntypedArray {
1731
return {
1832
value: value,
19-
getValue: () => value as UntypedNode[],
33+
getValue: () => value as UntypedNode[],
2034
};
21-
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import { UntypedNode } from "./untypedNode";
22

3+
/** Defines an interface for defining an untyped boolean. */
34
export interface UntypedBoolean extends UntypedNode {
5+
/**
6+
* Gets the value of the UntypedNode as a boolean value.
7+
*/
48
getValue(): boolean;
59
}
610

11+
/**
12+
* Type guard to assert that an UntypedNode instance is an UntypedBoolean.
13+
* @param node The UntypedNode to check.
14+
* @return boolean indicating if the node is an UntypedBoolean.
15+
*/
716
export function isUntypedBoolean(node: UntypedNode): node is UntypedBoolean {
817
const proposedNode = node as UntypedBoolean;
918
return proposedNode && typeof proposedNode.value === "boolean";
1019
}
1120

21+
/**
22+
* Factory to create an UntypedBoolean from a boolean.
23+
* @param value The boolean value to create from.
24+
* @return The created UntypedBoolean.
25+
*/
1226
export function createUntypedBoolean(value: boolean): UntypedBoolean {
1327
return {
1428
value: value,
15-
getValue: () => value as boolean,
29+
getValue: () => value as boolean,
1630
};
17-
}
31+
}

packages/abstractions/src/serialization/untypedNode.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,40 @@ import type { Parsable } from "./parsable";
33
import type { ParseNode } from "./parseNode";
44
import type { SerializationWriter } from "./serializationWriter";
55

6+
/** Defines the base interface for defining an untyped node. */
67
export interface UntypedNode extends Parsable {
7-
getValue(): any
8+
/**
9+
* Gets the value of the UntypedNode.
10+
*/
11+
getValue(): any;
12+
/**
13+
* The value represented by the UntypedNode.
14+
*/
815
value?: any;
916
}
1017

18+
/**
19+
* Factory to create an UntypedNode from a string during deserialization.
20+
*/
1121
export function createUntypedNodeFromDiscriminatorValue(
1222
_parseNode: ParseNode | undefined,
1323
): (instance?: Parsable) => Record<string, (node: ParseNode) => void> {
1424
return deserializeIntoUntypedNode;
1525
}
1626

27+
/**
28+
* Type guard to assert that an object instance is an UntypedNode.
29+
* @param node The object to check.
30+
* @return boolean indicating if the node is an UntypedNode.
31+
*/
1732
export function isUntypedNode(node: any): node is UntypedNode {
1833
const potentialNode = node as UntypedNode;
1934
return potentialNode && potentialNode.getValue !== undefined;
2035
}
2136

37+
/**
38+
* The deserialization implementation for UntypedNode.
39+
*/
2240
export function deserializeIntoUntypedNode(
2341
untypedNode: Partial<UntypedNode> | undefined = {},
2442
): Record<string, (node: ParseNode) => void> {
@@ -32,6 +50,9 @@ export function deserializeIntoUntypedNode(
3250
};
3351
}
3452

53+
/**
54+
* The serialization implementation for UntypedNode.
55+
*/
3556
export function serializeUntypedNode(
3657
_writer: SerializationWriter,
3758
_errorDetails: Partial<UntypedNode> | undefined = {},
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
import { UntypedNode } from "./untypedNode";
22

3+
/** Defines the interface for defining an untyped null value. */
34
export interface UntypedNull extends UntypedNode {
5+
/**
6+
* Gets the value of the UntypedNode as null.
7+
*/
48
getValue(): null;
59
}
610

11+
/**
12+
* Type guard to assert that an object instance is an UntypedNull.
13+
* @param node The object to check.
14+
* @return boolean indicating if the node is an UntypedNull.
15+
*/
716
export function isUntypedNull(node: UntypedNode): node is UntypedNull {
817
return node.value === null;
918
}
1019

20+
/**
21+
* Factory to create an UntypedNull from a boolean.
22+
* @return The created UntypedNull.
23+
*/
1124
export function createUntypedNull(): UntypedNull {
1225
return {
1326
value: null,
14-
getValue: () => null,
27+
getValue: () => null,
1528
};
1629
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import { UntypedNode } from "./untypedNode";
22

3+
/** Defines the interface for defining an untyped number value. */
34
export interface UntypedNumber extends UntypedNode {
5+
/**
6+
* Gets the value of the UntypedNode as a number.
7+
*/
48
getValue(): number;
59
}
610

11+
/**
12+
* Type guard to assert that an object instance is an UntypedNumber.
13+
* @param node The object to check.
14+
* @return boolean indicating if the node is an UntypedNumber.
15+
*/
716
export function isUntypedNumber(node: UntypedNode): node is UntypedNumber {
817
const proposedNode = node as UntypedNumber;
918
return proposedNode && typeof proposedNode.value === "number";
1019
}
1120

21+
/**
22+
* Factory to create an UntypedNumber from a number.
23+
* @param value The number value to create from.
24+
* @return The created UntypedNumber.
25+
*/
1226
export function createUntypedNumber(value: number): UntypedNumber {
1327
return {
1428
value: value,
15-
getValue: () => value as number,
29+
getValue: () => value as number,
1630
};
17-
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import { isUntypedNode, UntypedNode } from "./untypedNode";
22

3+
/** Defines the interface for defining an untyped object value. */
34
export interface UntypedObject extends UntypedNode {
4-
getValue(): Record<string, UntypedNode> ;
5+
/**
6+
* Gets the value of the UntypedNode as a Record<string, UntypedNode>.
7+
*/
8+
getValue(): Record<string, UntypedNode>;
59
}
610

11+
/**
12+
* Type guard to assert that an object instance is an UntypedObject.
13+
* @param node The object to check.
14+
* @return boolean indicating if the node is an UntypedObject.
15+
*/
716
export function isUntypedObject(node: UntypedNode): node is UntypedObject {
817
const proposedNode = node as UntypedObject;
918
return (
@@ -14,9 +23,16 @@ export function isUntypedObject(node: UntypedNode): node is UntypedObject {
1423
);
1524
}
1625

17-
export function createUntypedObject(value: Record<string, UntypedNode>): UntypedObject {
26+
/**
27+
* Factory to create an UntypedObject from a Record<string, UntypedNode>.
28+
* @param value The Record<string, UntypedNode> value to create from.
29+
* @return The created UntypedObject.
30+
*/
31+
export function createUntypedObject(
32+
value: Record<string, UntypedNode>,
33+
): UntypedObject {
1834
return {
1935
value: value,
20-
getValue: () => value as Record<string, UntypedNode>,
36+
getValue: () => value as Record<string, UntypedNode>,
2137
};
22-
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import { UntypedNode } from "./untypedNode";
22

3+
/** Defines the interface for defining an untyped string value. */
34
export interface UntypedString extends UntypedNode {
5+
/**
6+
* Gets the value of the UntypedNode as a Record<string, UntypedNode>.
7+
*/
48
getValue(): string;
59
}
610

11+
/**
12+
* Type guard to assert that an object instance is an UntypedString.
13+
* @param node The object to check.
14+
* @return boolean indicating if the node is an UntypedString.
15+
*/
716
export function isUntypedString(node: UntypedNode): node is UntypedString {
817
const proposedNode = node as UntypedString;
918
return proposedNode && typeof proposedNode.value === "string";
1019
}
1120

21+
/**
22+
* Factory to create an UntypedString from a string.
23+
* @param value The string value to create from.
24+
* @return The created UntypedString.
25+
*/
1226
export function createUntypedString(value: string): UntypedString {
1327
return {
1428
value: value,
15-
getValue: () => value as string,
29+
getValue: () => value as string,
1630
};
17-
}
31+
}

0 commit comments

Comments
 (0)