From 2c9bf198053c1a3bbdfcd374c1d4a333a1d83dc7 Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Thu, 30 May 2024 17:53:05 -0400 Subject: [PATCH] Stop using required, start using OptionalSchema --- typescript_templates/model.vm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/typescript_templates/model.vm b/typescript_templates/model.vm index 6bf91c0..346088d 100644 --- a/typescript_templates/model.vm +++ b/typescript_templates/model.vm @@ -65,6 +65,9 @@ $unknown.type ## force a template failure with an unknown type #end ## Gets the Schema object for a given type. #macro ( toSchema $param ) +#if ( !$param.required ) +new OptionalSchema(## +#end #if ( $param.arrayType ) new ArraySchema(## #end @@ -100,6 +103,9 @@ $unknown.type ## force a template failure with an unknown type #if ( $param.arrayType ) )## #end +#if ( !$param.required ) +)## +#end #end ## Check if there's a class associated with this type #macro ( isClassType $param ) @@ -283,7 +289,7 @@ ${prop.refType}## /* eslint-disable no-use-before-define */ import { ensureBigInt, ensureSafeInteger } from '../../../../utils/utils.js'; import { Encodable, Schema } from '../../../../encoding/encoding.js'; -import { NamedMapSchema, ArraySchema, Uint64Schema, StringSchema, BooleanSchema, ByteArraySchema } from '../../../../encoding/schema/index.js'; +import { NamedMapSchema, ArraySchema, Uint64Schema, StringSchema, BooleanSchema, ByteArraySchema, OptionalSchema } from '../../../../encoding/schema/index.js'; import { base64ToBytes } from '../../../../encoding/binarydata.js'; #if ( $propFile.indexer == "false" ) import BlockHeader, { blockHeaderFromEncodingData, blockHeaderToEncodingData, BLOCK_HEADER_SCHEMA } from '../../../../types/blockHeader.js'; @@ -320,7 +326,7 @@ export class $def.name implements Encodable { ## we allow circular references to be handled properly. (this.encodingSchemaValue as NamedMapSchema).entries.push( #foreach( $prop in $props ) - { key: '$prop.propertyName', valueSchema: #toSchema($prop), required: $prop.required, omitEmpty: true }, + { key: '$prop.propertyName', valueSchema: #toSchema($prop), omitEmpty: true }, #end ); }