11import { TypesonSimplified } from 'dreambase-library/dist/typeson-simplified/TypesonSimplified' ;
2- import { Bison } from " dreambase-library/dist/typeson-simplified/Bison" ;
2+ import { Bison } from ' dreambase-library/dist/typeson-simplified/Bison' ;
33import undefinedDef from 'dreambase-library/dist/typeson-simplified/types/undefined.js' ;
44import tsonBuiltinDefs from 'dreambase-library/dist/typeson-simplified/presets/builtin.js' ;
55import { TypeDefSet } from 'dreambase-library/dist/typeson-simplified/TypeDefSet' ;
@@ -20,7 +20,8 @@ import { PropModSpec, PropModification } from 'dexie';
2020// serverRev.rev = bigIntDef.bigint.revive(server.rev)
2121// else
2222// serverRev.rev = new FakeBigInt(server.rev)
23- export const hasBigIntSupport = typeof BigInt === 'function' && typeof BigInt ( 0 ) === 'bigint' ;
23+ export const hasBigIntSupport =
24+ typeof BigInt === 'function' && typeof BigInt ( 0 ) === 'bigint' ;
2425
2526function getValueOfBigInt ( x : bigint | FakeBigInt | string ) {
2627 if ( typeof x === 'bigint' ) {
@@ -33,7 +34,10 @@ function getValueOfBigInt(x: bigint | FakeBigInt | string) {
3334 }
3435}
3536
36- export function compareBigInts ( a : bigint | FakeBigInt | string , b :bigint | FakeBigInt | string ) {
37+ export function compareBigInts (
38+ a : bigint | FakeBigInt | string ,
39+ b : bigint | FakeBigInt | string
40+ ) {
3741 const valA = getValueOfBigInt ( a ) ;
3842 const valB = getValueOfBigInt ( b ) ;
3943 return valA < valB ? - 1 : valA > valB ? 1 : 0 ;
@@ -48,42 +52,40 @@ export class FakeBigInt {
4852 }
4953}
5054
51- const defs : TypeDefSet = {
52- ...undefinedDef ,
53- ...( hasBigIntSupport
54- ? { }
55- : {
56- bigint : {
57- test : ( val : any ) => val instanceof FakeBigInt ,
58- replace : ( fakeBigInt : any ) => {
59- return {
60- $t : 'bigint' ,
61- ...fakeBigInt
62- } ;
63- } ,
64- revive : ( {
65- v,
66- } : {
67- $t : 'bigint' ;
68- v : string ;
69- } ) => new FakeBigInt ( v ) as any as bigint
70- }
71- } ) ,
72- PropModification : {
73- test : ( val : any ) => val instanceof PropModification ,
74- replace : ( propModification : any ) => {
55+ const bigIntDef = hasBigIntSupport
56+ ? { }
57+ : {
58+ bigint : {
59+ test : ( val : any ) => val instanceof FakeBigInt ,
60+ replace : ( fakeBigInt : any ) => {
7561 return {
76- $t : 'PropModification ' ,
77- ...propModification
62+ $t : 'bigint ' ,
63+ ...fakeBigInt ,
7864 } ;
7965 } ,
80- revive : ( {
81- $t,
82- ...propModification
83- } : {
84- $t : 'PropModification' ;
85- } & PropModSpec ) => new PropModification ( propModification )
86- }
66+ revive : ( { v } : { $t : 'bigint' ; v : string } ) =>
67+ new FakeBigInt ( v ) as any as bigint ,
68+ } ,
69+ } ;
70+
71+ const defs : TypeDefSet = {
72+ ...undefinedDef ,
73+ ...bigIntDef ,
74+ PropModification : {
75+ test : ( val : any ) => val instanceof PropModification ,
76+ replace : ( propModification : any ) => {
77+ return {
78+ $t : 'PropModification' ,
79+ ...propModification [ '@@propmod' ] ,
80+ } ;
81+ } ,
82+ revive : ( {
83+ $t, // strip '$t'
84+ ...propModSpec // keep the rest
85+ } : {
86+ $t : 'PropModification' ;
87+ } & PropModSpec ) => new PropModification ( propModSpec ) ,
88+ } ,
8789} ;
8890
8991export const TSON = TypesonSimplified ( tsonBuiltinDefs , defs ) ;
0 commit comments