import { BigNumber } from "ethers/utils"; import { PlainObject, DbObject, AnyObject, Primitive } from "./objects"; /** * Plain objects obtained by serialising some other (non-plain) * object are marked by having a `_type` member field. */ export interface TypedPlainObject extends PlainObject { __type__: string; } declare const DB_TYPE = "__type__"; /** * An object that can be serialised and deserialised. * Implementations should also the corresponding public static `deserialise` method. * Moreover, they should have a public static readonly constant `TYPE` */ export interface Serialisable { serialise(): TypedPlainObject; } /** * Given a Serialisable type X, Serialised is the type of the serialised form of X. * The X class should have a public static method X.deserialise of type Serialised and returning X. **/ export declare type Serialised = ReturnType; /** * An object that is AnyObject or is Serialisable * We need this type for recursive serialisation and deserialisation functions. */ export declare type AnyObjectOrSerialisable = bigint | Serialisable | AnyObject | AnyObjectOrSerialisable[] | { [key: string]: AnyObjectOrSerialisable; }; /** * An object that is a plain js object or Serialisable */ export declare type PlainObjectOrSerialisable = Serialisable | { [key: string]: AnyObjectOrSerialisable; }; /** * A DB object or Serialisable */ export declare type DbObjectOrSerialisable = Serialisable | DbObject | AnyObjectOrSerialisable[] | { [key: string]: AnyObjectOrSerialisable; }; export declare function isPrimitive(value: any): value is Primitive; export declare function isSerialisable(obj: any): obj is Serialisable; export declare type Deserialisers = { [type: string]: (obj: TypedPlainObject) => Serialisable; }; declare type SerialisedBigInt = { [DB_TYPE]: "bigint"; value: string; } & TypedPlainObject; export declare const serialiseBigInt: (val: bigint) => SerialisedBigInt; /** * Serialises the objects */ export declare class DbObjectSerialiser { readonly deserialisers: Deserialisers; constructor(deserialisers: Deserialisers); private isSerialisedPlainObject; private serialiseAnyObject; /** * Serialise an object to its database representation * @param obj */ serialise(obj: DbObjectOrSerialisable): DbObject; private deserialiseAnyObject; /** * Deserialise an object from the database. * @param obj */ deserialise(obj: DbObject): T; } /** * A Serialisable version of the BigNumber class. */ export declare class SerialisableBigNumber extends BigNumber implements Serialisable { static TYPE: string; serialise(): { __type__: string; value: string; }; static deserialise(obj: Serialised): SerialisableBigNumber; } /** * Convenience default serialisers config that knows how to handle BigNumbers */ export declare const defaultDeserialisers: { [x: string]: typeof SerialisableBigNumber.deserialise; }; /** * Convenience default serialiser that can handle BigNumbers */ export declare const defaultSerialiser: DbObjectSerialiser; export {}; //# sourceMappingURL=serialiser.d.ts.map