diff --git a/README.md b/README.md index fd3e30c..ef9b272 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,8 @@ ThreeLengthString.decode(1); // Left("[error message]") #### chainCodec Utility for composing multiple Codecs. -This function accepts up to 9 Codecs. +This function accepts up to 9 Codecs. +⚠️ `schema` only uses last one codec schema. ```typescript const ThreeDigitIntegerFromString = chainCodec( diff --git a/src/Codec/utils.ts b/src/Codec/utils.ts index a037096..4fc9391 100644 --- a/src/Codec/utils.ts +++ b/src/Codec/utils.ts @@ -108,12 +108,14 @@ export function chainCodec( return Codec.custom({ decode: (value) => c1.decode(value).chain(c2.decode), encode: (value) => c1.encode(c2.encode(value) as any), + schema: c2.schema, }); } if (!c4) { return Codec.custom({ decode: (value) => c1.decode(value).chain(c2.decode).chain(c3.decode), encode: (value) => c1.encode(c2.encode(c3.encode(value) as any) as any), + schema: c3.schema, }); } if (!c5) { @@ -122,6 +124,7 @@ export function chainCodec( c1.decode(value).chain(c2.decode).chain(c3.decode).chain(c4.decode), encode: (value) => c1.encode(c2.encode(c3.encode(c4.encode(value) as any) as any) as any), + schema: c4.schema, }); } if (!c6) { @@ -139,6 +142,7 @@ export function chainCodec( c3.encode(c4.encode(c5.encode(value) as any) as any) as any ) as any ), + schema: c5.schema, }); } if (!c7) { @@ -159,6 +163,7 @@ export function chainCodec( ) as any ) as any ), + schema: c6.schema, }); } if (!c8) { @@ -182,6 +187,7 @@ export function chainCodec( ) as any ) as any ), + schema: c7.schema, }); } if (!c9) { @@ -208,6 +214,7 @@ export function chainCodec( ) as any ) as any ), + schema: c8.schema, }); } @@ -237,5 +244,6 @@ export function chainCodec( ) as any ) as any ), + schema: c9.schema, }); }