11/* tslint:disable no-console */
22
3- import { TypeSystem } from ".." ;
4- import { CborEncoder } from " @jsonjoy.com/json-pack/lib/cbor/CborEncoder" ;
5- import { JsonEncoder } from " @jsonjoy.com/json-pack/lib/json/JsonEncoder" ;
6- import type { CompiledBinaryEncoder } from " ../codegen/types" ;
7- import { EncodingFormat } from " @jsonjoy.com/json-pack/lib/constants" ;
8- import { Writer } from " @jsonjoy.com/util/lib/buffers/Writer" ;
3+ import { TypeSystem } from '..' ;
4+ import { CborEncoder } from ' @jsonjoy.com/json-pack/lib/cbor/CborEncoder' ;
5+ import { JsonEncoder } from ' @jsonjoy.com/json-pack/lib/json/JsonEncoder' ;
6+ import type { CompiledBinaryEncoder } from ' ../codegen/types' ;
7+ import { EncodingFormat } from ' @jsonjoy.com/json-pack/lib/constants' ;
8+ import { Writer } from ' @jsonjoy.com/util/lib/buffers/Writer' ;
99
1010const system = new TypeSystem ( ) ;
11- const { t } = system ;
11+ const { t } = system ;
1212
1313const response = system . alias (
14- " Response" ,
14+ ' Response' ,
1515 t . Object (
1616 t . prop (
17- " collection" ,
17+ ' collection' ,
1818 t . Object (
19- t . prop ( "id" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
20- t . prop ( "ts" , t . num . options ( { format : " u64" } ) ) ,
21- t . prop ( " cid" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
22- t . prop ( " prid" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
23- t . prop ( " slug" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
24- t . propOpt ( " name" , t . str ) ,
25- t . propOpt ( " src" , t . str ) ,
26- t . propOpt ( " doc" , t . str ) ,
27- t . propOpt ( " longText" , t . str ) ,
28- t . prop ( " active" , t . bool ) ,
29- t . prop ( " views" , t . Array ( t . num ) ) ,
19+ t . prop ( 'id' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
20+ t . prop ( 'ts' , t . num . options ( { format : ' u64' } ) ) ,
21+ t . prop ( ' cid' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
22+ t . prop ( ' prid' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
23+ t . prop ( ' slug' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
24+ t . propOpt ( ' name' , t . str ) ,
25+ t . propOpt ( ' src' , t . str ) ,
26+ t . propOpt ( ' doc' , t . str ) ,
27+ t . propOpt ( ' longText' , t . str ) ,
28+ t . prop ( ' active' , t . bool ) ,
29+ t . prop ( ' views' , t . Array ( t . num ) ) ,
3030 ) ,
3131 ) ,
3232 t . prop (
33- " block" ,
33+ ' block' ,
3434 t . Object (
35- t . prop ( "id" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
36- t . prop ( "ts" , t . num . options ( { format : " u64" } ) ) ,
37- t . prop ( " cid" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
38- t . prop ( " slug" , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
35+ t . prop ( 'id' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
36+ t . prop ( 'ts' , t . num . options ( { format : ' u64' } ) ) ,
37+ t . prop ( ' cid' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
38+ t . prop ( ' slug' , t . String ( { ascii : true , noJsonEscape : true } ) ) ,
3939 ) ,
4040 ) ,
4141 ) ,
4242) ;
4343
4444const json = {
4545 collection : {
46- id : " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
46+ id : ' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ,
4747 ts : Date . now ( ) ,
48- cid : " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
49- prid : " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
50- slug : " slug-name" ,
51- name : " Super collection" ,
48+ cid : ' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ,
49+ prid : ' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ,
50+ slug : ' slug-name' ,
51+ name : ' Super collection' ,
5252 src : '{"foo": "bar"}' ,
5353 longText :
54- " After implementing a workaround for the first issue and merging the changes to another feature branch with some extra code and tests, the following error was printed in the stage’s log “JavaScript heap out of memory error.”" ,
54+ ' After implementing a workaround for the first issue and merging the changes to another feature branch with some extra code and tests, the following error was printed in the stage’s log “JavaScript heap out of memory error.”' ,
5555 active : true ,
5656 views : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ,
5757 } ,
5858 block : {
59- id : " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
59+ id : ' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ,
6060 ts : Date . now ( ) ,
61- cid : " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
62- slug : " slug-name" ,
61+ cid : ' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ,
62+ slug : ' slug-name' ,
6363 } ,
6464} ;
6565
6666const jsonTextEncoder = response . type . jsonTextEncoder ( ) ;
67- const jsonEncoderFn = response . type . encoder (
68- EncodingFormat . Json ,
69- ) as CompiledBinaryEncoder ;
70- const cborEncoderFn = response . type . encoder (
71- EncodingFormat . Cbor ,
72- ) as CompiledBinaryEncoder ;
67+ const jsonEncoderFn = response . type . encoder ( EncodingFormat . Json ) as CompiledBinaryEncoder ;
68+ const cborEncoderFn = response . type . encoder ( EncodingFormat . Cbor ) as CompiledBinaryEncoder ;
7369
7470const jsonEncoder = new JsonEncoder ( new Writer ( ) ) ;
7571const cborEncoder = new CborEncoder ( ) ;
7672
77- const { Suite } = require ( " benchmark" ) ;
73+ const { Suite} = require ( ' benchmark' ) ;
7874const suite = new Suite ( ) ;
7975suite
8076 . add ( `json-type "json" text encoder and Buffer.from()` , ( ) => {
@@ -94,14 +90,11 @@ suite
9490 . add ( `Buffer.from(JSON.stringify())` , ( ) => {
9591 Buffer . from ( JSON . stringify ( json ) ) ;
9692 } )
97- . on ( "cycle" , ( event : any ) => {
98- console . log (
99- String ( event . target ) +
100- `, ${ Math . round ( 1000000000 / event . target . hz ) } ns/op` ,
101- ) ;
93+ . on ( 'cycle' , ( event : any ) => {
94+ console . log ( String ( event . target ) + `, ${ Math . round ( 1000000000 / event . target . hz ) } ns/op` ) ;
10295 } )
103- . on ( " complete" , ( ) => {
104- console . log ( " Fastest is " + suite . filter ( " fastest" ) . map ( " name" ) ) ;
96+ . on ( ' complete' , ( ) => {
97+ console . log ( ' Fastest is ' + suite . filter ( ' fastest' ) . map ( ' name' ) ) ;
10598 } )
10699 . run ( ) ;
107100
0 commit comments