import { BigNumber } from '@0x/utils' ; import { ValueTransformer } from 'typeorm' ; import { ZeroExTransactionWithoutDomain } from '../types' ; export const BigIntTransformer = { from : ( value ) : number | null => { if ( value === null ) { return null ; } const num = Number ( value ) ; if ( ! Number . isSafeInteger ( num ) ) { throw new Error ( 'unsafe integer precision when transforming value' ) ; } return value === null ? null : Number ( value ) ; } , to : ( value ) : string | null => { if ( value === null || value === undefined ) { return null ; } if ( ! Number . isSafeInteger ( value ) ) { throw new Error ( 'unsafe integer precision when transforming value' ) ; } return value . toString ( ) ; } , } ; export const ZeroExTransactionWithoutDomainTransformer = { from : ( value ) : ZeroExTransactionWithoutDomain | null => { if ( value === undefined || value === null ) { return null ; } const obj = JSON . parse ( value ) ; obj . salt = new BigNumber ( obj . salt ) ; obj . expirationTimeSeconds = new BigNumber ( obj . expirationTimeSeconds ) ; obj . gasPrice = new BigNumber ( obj . gasPrice ) ; return obj ; } , to : ( value ) : string | null => { if ( value === null || value === undefined ) { return null ; } const objToStore = { ... value , salt : value . salt . toString ( ) , expirationTimeSeconds : value . expirationTimeSeconds . toString ( ) , gasPrice : value . gasPrice . toString ( ) , } ; return JSON . stringify ( objToStore ) ; } , } ; export const BigNumberTransformer = { from : ( value ) : BigNumber | null => { return value === null ? null : new BigNumber ( value ) ; } , to : ( value ) : string | null => { return value === null || value === undefined ? null : value . toString ( ) ; } , } ;