import fs from "fs" ; import os from "os" ; import { TextEncoder } from "util" ; import InternalDatabase from "../../src/Database" ; import { Env , FileHandle } from "../../src/Env" ; import { DatabaseOptions } from "../../src/Options" ; import { InternalDBRepairer } from "../../src/DBRepairer" ; import { WriteBatch } from "../../src/WriteBatch" ; import { onExit } from "./cleanup" ; if ( ! global . TextEncoder ) { global . TextEncoder = TextEncoder ; } class NodeEnv implements Env { platform ( ) { return os . platform ( ) ; } /**
     * get current time
     */ now ( ) { return Number ( process . hrtime . bigint ( ) ) / Math . pow ( 10 , 9 ) ; } onExit = onExit ; access ( dbpath ) { return fs . promises . access ( dbpath , fs . constants . W_OK ) ; } mkdir ( dbpath ) { return fs . promises . mkdir ( dbpath , { recursive : true } ) ; } writeFile = fs . promises . writeFile ; readFile = fs . promises . readFile ; open = fs . promises . open ; rename = fs . promises . rename ; unlink = fs . promises . unlink ; unlinkSync = fs . unlinkSync ; fstat = fs . promises . fstat ; readdir ( dbpath ) { return fs . promises . readdir ( dbpath , { withFileTypes : true } ) ; } async infoLog ( handle , message ) { const finalMessage = `${ new Date ( ) . toISOString ( ) } ${ message }\n` ; await handle . appendFile ( finalMessage ) ; } async getFileSize ( filename ) { const stat = await fs . promises . stat ( filename ) ; return stat . size ; } } class Database extends InternalDatabase { constructor ( dbpath , options = { } ) { if ( ! options . env ) options . env = new NodeEnv ( ) ; super ( dbpath , options ) ; } } class DBRepairer extends InternalDBRepairer { constructor ( dbpath , options = { } ) { if ( ! options . env ) options . env = new NodeEnv ( ) ; super ( dbpath , options ) ; } } export { WriteBatch , Env , NodeEnv , Database , DBRepairer , InternalDBRepairer , InternalDatabase , } ;