@@ -4,7 +4,7 @@ import {printTree} from 'tree-dump/lib/printTree';
44import * as schema from '../../schema' ;
55import { RandomJson } from '@jsonjoy.com/util/lib/json-random' ;
66import { stringifyBinary } from '@jsonjoy.com/json-pack/lib/json-binary' ;
7- import { validateTType } from '../../schema/validate' ;
7+ import { validateMinMax , validateTType } from '../../schema/validate' ;
88import type { ValidatorCodegenContext } from '../../codegen/validator/ValidatorCodegenContext' ;
99import type { ValidationPath } from '../../codegen/validator/types' ;
1010import { ValidationError } from '../../constants' ;
@@ -23,6 +23,17 @@ import type {json_string} from '@jsonjoy.com/util/lib/json-brand';
2323import type * as ts from '../../typescript/types' ;
2424import type { TypeExportContext } from '../../system/TypeExportContext' ;
2525
26+ const formats = new Set < schema . BinarySchema [ 'format' ] > ( [
27+ 'bencode' ,
28+ 'bson' ,
29+ 'cbor' ,
30+ 'ion' ,
31+ 'json' ,
32+ 'msgpack' ,
33+ 'resp3' ,
34+ 'ubjson' ,
35+ ] ) ;
36+
2637export class BinaryType < T extends Type > extends AbstractType < schema . BinarySchema > {
2738 protected schema : schema . BinarySchema ;
2839
@@ -54,7 +65,13 @@ export class BinaryType<T extends Type> extends AbstractType<schema.BinarySchema
5465 }
5566
5667 public validateSchema ( ) : void {
57- validateTType ( this . getSchema ( ) , 'bin' ) ;
68+ const schema = this . getSchema ( ) ;
69+ validateTType ( schema , 'bin' ) ;
70+ const { min, max, format} = schema ;
71+ validateMinMax ( min , max ) ;
72+ if ( format !== undefined ) {
73+ if ( ! formats . has ( format ) ) throw new Error ( 'FORMAT' ) ;
74+ }
5875 this . type . validateSchema ( ) ;
5976 }
6077
0 commit comments