@@ -4,7 +4,7 @@ import {printTree} from 'tree-dump/lib/printTree';
4
4
import * as schema from '../../schema' ;
5
5
import { RandomJson } from '@jsonjoy.com/util/lib/json-random' ;
6
6
import { stringifyBinary } from '@jsonjoy.com/json-pack/lib/json-binary' ;
7
- import { validateTType } from '../../schema/validate' ;
7
+ import { validateMinMax , validateTType } from '../../schema/validate' ;
8
8
import type { ValidatorCodegenContext } from '../../codegen/validator/ValidatorCodegenContext' ;
9
9
import type { ValidationPath } from '../../codegen/validator/types' ;
10
10
import { ValidationError } from '../../constants' ;
@@ -23,6 +23,17 @@ import type {json_string} from '@jsonjoy.com/util/lib/json-brand';
23
23
import type * as ts from '../../typescript/types' ;
24
24
import type { TypeExportContext } from '../../system/TypeExportContext' ;
25
25
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
+
26
37
export class BinaryType < T extends Type > extends AbstractType < schema . BinarySchema > {
27
38
protected schema : schema . BinarySchema ;
28
39
@@ -54,7 +65,13 @@ export class BinaryType<T extends Type> extends AbstractType<schema.BinarySchema
54
65
}
55
66
56
67
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
+ }
58
75
this . type . validateSchema ( ) ;
59
76
}
60
77
0 commit comments