1- import { TypeSystem } from '../../../system ' ;
1+ import { ModuleType } from '../../../type/classes/ModuleType ' ;
22import type { Type } from '../../../type' ;
33
4- export const testBinaryCodegen = ( transcode : ( system : TypeSystem , type : Type , value : unknown ) => void ) => {
4+ export const testBinaryCodegen = ( transcode : ( system : ModuleType , type : Type , value : unknown ) => void ) => {
55 describe ( '"any" type' , ( ) => {
66 test ( 'can encode any value - 1' , ( ) => {
7- const system = new TypeSystem ( ) ;
7+ const system = new ModuleType ( ) ;
88 const any = system . t . any ;
99 const value = { foo : 'bar' } ;
1010 const decoded = transcode ( system , any , value ) ;
1111 expect ( decoded ) . toStrictEqual ( value ) ;
1212 } ) ;
1313
1414 test ( 'can encode any value - 2' , ( ) => {
15- const system = new TypeSystem ( ) ;
15+ const system = new ModuleType ( ) ;
1616 const any = system . t . any ;
1717 const value = 123 ;
1818 const decoded = transcode ( system , any , value ) ;
@@ -22,15 +22,15 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
2222
2323 describe ( '"con" type' , ( ) => {
2424 test ( 'can encode number const' , ( ) => {
25- const system = new TypeSystem ( ) ;
25+ const system = new ModuleType ( ) ;
2626 const any = system . t . Const < 123 > ( 123 ) ;
2727 const value = { foo : 'bar' } ;
2828 const decoded = transcode ( system , any , value ) ;
2929 expect ( decoded ) . toStrictEqual ( 123 ) ;
3030 } ) ;
3131
3232 test ( 'can encode array const' , ( ) => {
33- const system = new TypeSystem ( ) ;
33+ const system = new ModuleType ( ) ;
3434 const any = system . t . Const ( < const > [ 1 , 2 , 3 ] ) ;
3535 const decoded = transcode ( system , any , [ false , true , null ] ) ;
3636 expect ( decoded ) . toStrictEqual ( [ 1 , 2 , 3 ] ) ;
@@ -39,7 +39,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
3939
4040 describe ( '"bool" type' , ( ) => {
4141 test ( 'can encode booleans' , ( ) => {
42- const system = new TypeSystem ( ) ;
42+ const system = new ModuleType ( ) ;
4343 const any = system . t . bool ;
4444 expect ( transcode ( system , any , true ) ) . toStrictEqual ( true ) ;
4545 expect ( transcode ( system , any , false ) ) . toStrictEqual ( false ) ;
@@ -50,7 +50,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
5050
5151 describe ( '"num" type' , ( ) => {
5252 test ( 'can encode any number' , ( ) => {
53- const system = new TypeSystem ( ) ;
53+ const system = new ModuleType ( ) ;
5454 const any = system . t . num ;
5555 expect ( transcode ( system , any , 0 ) ) . toBe ( 0 ) ;
5656 expect ( transcode ( system , any , 1 ) ) . toBe ( 1 ) ;
@@ -61,7 +61,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
6161 } ) ;
6262
6363 test ( 'can encode an integer' , ( ) => {
64- const system = new TypeSystem ( ) ;
64+ const system = new ModuleType ( ) ;
6565 const any = system . t . num . options ( { format : 'i' } ) ;
6666 expect ( transcode ( system , any , 0 ) ) . toBe ( 0 ) ;
6767 expect ( transcode ( system , any , 1 ) ) . toBe ( 1 ) ;
@@ -71,7 +71,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
7171 } ) ;
7272
7373 test ( 'can encode an unsigned ints' , ( ) => {
74- const system = new TypeSystem ( ) ;
74+ const system = new ModuleType ( ) ;
7575 const any = system . t . num . options ( { format : 'u8' } ) ;
7676 expect ( transcode ( system , any , 0 ) ) . toBe ( 0 ) ;
7777 expect ( transcode ( system , any , 1 ) ) . toBe ( 1 ) ;
@@ -80,7 +80,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
8080 } ) ;
8181
8282 test ( 'can encode an floats' , ( ) => {
83- const system = new TypeSystem ( ) ;
83+ const system = new ModuleType ( ) ;
8484 const any = system . t . num . options ( { format : 'f' } ) ;
8585 expect ( transcode ( system , any , 0 ) ) . toBe ( 0 ) ;
8686 expect ( transcode ( system , any , 1 ) ) . toBe ( 1 ) ;
@@ -92,7 +92,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
9292
9393 describe ( '"str" type' , ( ) => {
9494 test ( 'can encode regular strings' , ( ) => {
95- const system = new TypeSystem ( ) ;
95+ const system = new ModuleType ( ) ;
9696 const type = system . t . str ;
9797 let value = '' ;
9898 expect ( transcode ( system , type , value ) ) . toBe ( value ) ;
@@ -108,7 +108,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
108108 } ) ;
109109
110110 test ( 'can encode ascii strings' , ( ) => {
111- const system = new TypeSystem ( ) ;
111+ const system = new ModuleType ( ) ;
112112 const type = system . t . str . options ( { ascii : true } ) ;
113113 let value = '' ;
114114 expect ( transcode ( system , type , value ) ) . toBe ( value ) ;
@@ -126,7 +126,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
126126
127127 describe ( '"bin" type' , ( ) => {
128128 test ( 'can encode binary data' , ( ) => {
129- const system = new TypeSystem ( ) ;
129+ const system = new ModuleType ( ) ;
130130 const type = system . t . bin ;
131131 let value = new Uint8Array ( ) ;
132132 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
@@ -137,7 +137,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
137137
138138 describe ( '"arr" type' , ( ) => {
139139 test ( 'can encode simple arrays' , ( ) => {
140- const system = new TypeSystem ( ) ;
140+ const system = new ModuleType ( ) ;
141141 const type = system . t . arr ;
142142 let value : any [ ] = [ ] ;
143143 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
@@ -146,7 +146,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
146146 } ) ;
147147
148148 test ( 'can encode array inside array' , ( ) => {
149- const system = new TypeSystem ( ) ;
149+ const system = new ModuleType ( ) ;
150150 const type = system . t . Array ( system . t . arr ) ;
151151 const value : any [ ] = [
152152 [ 1 , 2 , 3 ] ,
@@ -157,46 +157,46 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
157157 } ) ;
158158
159159 test ( 'can encode array of strings' , ( ) => {
160- const system = new TypeSystem ( ) ;
160+ const system = new ModuleType ( ) ;
161161 const type = system . t . Array ( system . t . str ) ;
162162 const value : any [ ] = [ '1' , '2' , '3' ] ;
163163 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
164164 } ) ;
165165
166166 test ( 'can encode a simple tuple' , ( ) => {
167- const system = new TypeSystem ( ) ;
167+ const system = new ModuleType ( ) ;
168168 const t = system . t ;
169169 const type = system . t . Tuple ( [ t . str , t . num , t . bool ] ) ;
170170 const value : any [ ] = [ 'abc' , 123 , true ] ;
171171 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
172172 } ) ;
173173
174174 test ( 'can encode an empty tuple' , ( ) => {
175- const system = new TypeSystem ( ) ;
175+ const system = new ModuleType ( ) ;
176176 const t = system . t ;
177177 const type = system . t . Tuple ( [ ] ) ;
178178 const value : any [ ] = [ ] ;
179179 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
180180 } ) ;
181181
182182 test ( 'can encode a tuple of arrays' , ( ) => {
183- const system = new TypeSystem ( ) ;
183+ const system = new ModuleType ( ) ;
184184 const t = system . t ;
185185 const type = system . t . Tuple ( [ t . arr , t . arr ] ) ;
186186 const value : any [ ] = [ [ ] , [ 1 , 'b' , false ] ] ;
187187 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
188188 } ) ;
189189
190190 test ( 'can encode a tuple tail' , ( ) => {
191- const system = new TypeSystem ( ) ;
191+ const system = new ModuleType ( ) ;
192192 const t = system . t ;
193193 const type = system . t . Tuple ( [ t . arr , t . arr ] , t . bool , [ t . str , t . num ] ) ;
194194 const value : any [ ] = [ [ ] , [ 1 , 'b' , false ] , true , false , 'abc' , 123 ] ;
195195 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
196196 } ) ;
197197
198198 test ( 'elements and 2-tail' , ( ) => {
199- const system = new TypeSystem ( ) ;
199+ const system = new ModuleType ( ) ;
200200 const t = system . t ;
201201 const type = system . t . Tuple ( [ ] , t . bool , [ t . str , t . num ] ) ;
202202 const value1 : any [ ] = [ true , false , 'abc' , 123 ] ;
@@ -210,7 +210,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
210210 } ) ;
211211
212212 test ( 'elements and 1-tail' , ( ) => {
213- const system = new TypeSystem ( ) ;
213+ const system = new ModuleType ( ) ;
214214 const t = system . t ;
215215 const type = system . t . Tuple ( [ ] , t . bool , [ t . num ] ) ;
216216 const value1 : any [ ] = [ true , false , 123 ] ;
@@ -226,15 +226,15 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
226226
227227 describe ( '"obj" type' , ( ) => {
228228 test ( 'can encode empty object' , ( ) => {
229- const system = new TypeSystem ( ) ;
229+ const system = new ModuleType ( ) ;
230230 const t = system . t ;
231231 const type = t . obj ;
232232 const value : any = { } ;
233233 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
234234 } ) ;
235235
236236 test ( 'can encode empty object, which has optional fields' , ( ) => {
237- const system = new TypeSystem ( ) ;
237+ const system = new ModuleType ( ) ;
238238 const t = system . t ;
239239 const type = t . Object ( t . propOpt ( 'field1' , t . str ) ) ;
240240 const value1 : any = { } ;
@@ -244,7 +244,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
244244 } ) ;
245245
246246 test ( 'can encode fixed size object' , ( ) => {
247- const system = new TypeSystem ( ) ;
247+ const system = new ModuleType ( ) ;
248248 const t = system . t ;
249249 const type = t . Object ( t . prop ( 'field1' , t . str ) , t . prop ( 'field2' , t . num ) , t . prop ( 'bool' , t . bool ) ) ;
250250 const value : any = {
@@ -256,7 +256,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
256256 } ) ;
257257
258258 test ( 'can encode object with an optional field' , ( ) => {
259- const system = new TypeSystem ( ) ;
259+ const system = new ModuleType ( ) ;
260260 const t = system . t ;
261261 const type = t . Object ( t . prop ( 'id' , t . str ) , t . propOpt ( 'name' , t . str ) ) ;
262262 const value : any = {
@@ -267,7 +267,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
267267 } ) ;
268268
269269 test ( 'can encode object with a couple of optional fields' , ( ) => {
270- const system = new TypeSystem ( ) ;
270+ const system = new ModuleType ( ) ;
271271 const t = system . t ;
272272 const type = t . Object (
273273 t . prop ( 'id' , t . str ) ,
@@ -285,7 +285,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
285285 } ) ;
286286
287287 test ( 'can encode object with unknown fields' , ( ) => {
288- const system = new TypeSystem ( ) ;
288+ const system = new ModuleType ( ) ;
289289 const t = system . t ;
290290 const type = t
291291 . Object ( t . prop ( 'id' , t . str ) , t . propOpt ( 'name' , t . str ) , t . prop ( 'age' , t . num ) , t . propOpt ( 'address' , t . str ) )
@@ -301,7 +301,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
301301 } ) ;
302302
303303 test ( 'can encode nested objects' , ( ) => {
304- const system = new TypeSystem ( ) ;
304+ const system = new ModuleType ( ) ;
305305 const t = system . t ;
306306 const type = t
307307 . Object (
@@ -349,7 +349,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
349349 } ) ;
350350
351351 test ( 'can encode object with only optional fields (encodeUnknownFields = true)' , ( ) => {
352- const system = new TypeSystem ( ) ;
352+ const system = new ModuleType ( ) ;
353353 const t = system . t ;
354354 const type = t
355355 . Object ( t . propOpt ( 'id' , t . str ) , t . propOpt ( 'name' , t . str ) , t . propOpt ( 'address' , t . str ) )
@@ -376,7 +376,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
376376 } ) ;
377377
378378 test ( 'can encode object with only optional fields (encodeUnknownFields = false)' , ( ) => {
379- const system = new TypeSystem ( ) ;
379+ const system = new ModuleType ( ) ;
380380 const t = system . t ;
381381 const type = t
382382 . Object ( t . propOpt ( 'id' , t . str ) , t . propOpt ( 'name' , t . str ) , t . propOpt ( 'address' , t . str ) )
@@ -405,31 +405,31 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
405405
406406 describe ( '"map" type' , ( ) => {
407407 test ( 'can encode empty map' , ( ) => {
408- const system = new TypeSystem ( ) ;
408+ const system = new ModuleType ( ) ;
409409 const t = system . t ;
410410 const type = t . map ;
411411 const value : any = { } ;
412412 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
413413 } ) ;
414414
415415 test ( 'can encode empty map with one key' , ( ) => {
416- const system = new TypeSystem ( ) ;
416+ const system = new ModuleType ( ) ;
417417 const t = system . t ;
418418 const type = t . map ;
419419 const value : any = { a : 'asdf' } ;
420420 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
421421 } ) ;
422422
423423 test ( 'can encode typed map with two keys' , ( ) => {
424- const system = new TypeSystem ( ) ;
424+ const system = new ModuleType ( ) ;
425425 const t = system . t ;
426426 const type = t . Map ( t . bool ) ;
427427 const value : any = { x : true , y : false } ;
428428 expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
429429 } ) ;
430430
431431 test ( 'can encode nested maps' , ( ) => {
432- const system = new TypeSystem ( ) ;
432+ const system = new ModuleType ( ) ;
433433 const t = system . t ;
434434 const type = t . Map ( t . Map ( t . bool ) ) ;
435435 const value : any = { a : { x : true , y : false } } ;
@@ -439,7 +439,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
439439
440440 describe ( '"ref" type' , ( ) => {
441441 test ( 'can encode a simple reference' , ( ) => {
442- const system = new TypeSystem ( ) ;
442+ const system = new ModuleType ( ) ;
443443 const t = system . t ;
444444 system . alias ( 'Obj' , t . Object ( t . prop ( 'foo' , t . str ) ) ) ;
445445 const type = t . Ref ( 'Obj' ) ;
@@ -451,7 +451,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
451451
452452 describe ( '"or" type' , ( ) => {
453453 test ( 'can encode a simple union type' , ( ) => {
454- const system = new TypeSystem ( ) ;
454+ const system = new ModuleType ( ) ;
455455 const t = system . t ;
456456 const type = system . t . Or ( t . str , t . num ) . options ( {
457457 discriminator : [ 'if' , [ '==' , 'string' , [ 'type' , [ 'get' , '' ] ] ] , 0 , 1 ] ,
@@ -463,7 +463,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
463463
464464 describe ( 'various' , ( ) => {
465465 test ( 'encodes benchmark example' , ( ) => {
466- const system = new TypeSystem ( ) ;
466+ const system = new ModuleType ( ) ;
467467 const t = system . t ;
468468 const response = system . alias (
469469 'Response' ,
@@ -522,7 +522,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
522522 } ) ;
523523
524524 test ( 'serializes according to schema a POJO object' , ( ) => {
525- const system = new TypeSystem ( ) ;
525+ const system = new ModuleType ( ) ;
526526 const t = system . t ;
527527 const type = t . Object (
528528 t . prop ( 'a' , t . num ) ,
@@ -548,7 +548,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
548548 } ) ;
549549
550550 test ( 'supports "encodeUnknownFields" property' , ( ) => {
551- const system = new TypeSystem ( ) ;
551+ const system = new ModuleType ( ) ;
552552 const t = system . t ;
553553 const type = t . Object ( t . prop ( 'a' , t . Object ( ) . options ( { encodeUnknownKeys : true } ) ) ) ;
554554 const value = {
@@ -561,7 +561,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
561561 } ) ;
562562
563563 test ( 'supports "encodeUnknownFields" property' , ( ) => {
564- const system = new TypeSystem ( ) ;
564+ const system = new ModuleType ( ) ;
565565 const t = system . t ;
566566 const type = t . Object ( t . prop ( 'a' , t . num ) , t . propOpt ( 'b' , t . num ) , t . prop ( 'c' , t . bool ) , t . propOpt ( 'd' , t . nil ) ) ;
567567 const json1 = {
@@ -588,7 +588,7 @@ export const testBinaryCodegen = (transcode: (system: TypeSystem, type: Type, va
588588 } ) ;
589589
590590 test ( 'supports "encodeUnknownFields" property' , ( ) => {
591- const system = new TypeSystem ( ) ;
591+ const system = new ModuleType ( ) ;
592592 const t = system . t ;
593593 const type = t . Object (
594594 t . prop (
0 commit comments