diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/codec.ts | 56 | ||||
-rw-r--r-- | src/util/taleruri.ts | 2 |
2 files changed, 57 insertions, 1 deletions
diff --git a/src/util/codec.ts b/src/util/codec.ts index 136c5b053..c468704b2 100644 --- a/src/util/codec.ts +++ b/src/util/codec.ts @@ -18,6 +18,8 @@ * Type-safe codecs for converting from/to JSON. */ + /* eslint-disable @typescript-eslint/ban-types */ + /** * Error thrown when decoding fails. */ @@ -335,6 +337,60 @@ export function makeCodecForConstString<V extends string>(s: V): Codec<V> { }; } +/** + * Return a codec for a boolean true constant. + */ +export function makeCodecForConstTrue(): Codec<true> { + return { + decode(x: any, c?: Context): true { + if (x === true) { + return x; + } + throw new DecodingError( + `expected boolean true at ${renderContext( + c, + )} but got ${typeof x}`, + ); + }, + }; +} + +/** + * Return a codec for a boolean true constant. + */ +export function makeCodecForConstFalse(): Codec<false> { + return { + decode(x: any, c?: Context): false { + if (x === false) { + return x; + } + throw new DecodingError( + `expected boolean false at ${renderContext( + c, + )} but got ${typeof x}`, + ); + }, + }; +} + +/** + * Return a codec for a value that must be a constant number. + */ +export function makeCodecForConstNumber<V extends number>(n: V): Codec<V> { + return { + decode(x: any, c?: Context): V { + if (x === n) { + return x; + } + throw new DecodingError( + `expected number constant "${n}" at ${renderContext( + c, + )} but got ${typeof x}`, + ); + }, + }; +} + export function makeCodecOptional<V>( innerCodec: Codec<V>, ): Codec<V | undefined> { diff --git a/src/util/taleruri.ts b/src/util/taleruri.ts index 30209d48a..73280b6c8 100644 --- a/src/util/taleruri.ts +++ b/src/util/taleruri.ts @@ -220,7 +220,7 @@ export function parseRefundUri(s: string): RefundUriResult | undefined { } if (maybePath === "-") { - maybePath = "public/"; + maybePath = ""; } else { maybePath = decodeURIComponent(maybePath) + "/"; } |