import { ObjectID } from "mongodb" ; import { IdentityGenerator } from "./configuration" ; export class ObjectIdGenerator implements IdentityGenerator { constructor ( ) { ( < any > ObjectID ) . cacheHexString = true ; } generate ( ) { return new ObjectID ( ) ; } validate ( value ) { if ( value == null ) return false ; if ( value . _bsontype && value . _bsontype == 'ObjectID' ) return true ; return false ; } fromString ( text ) { if ( text == null || text . length != 24 ) { return null ; } return ObjectID . createFromHexString ( text ) ; } areEqual ( first , second ) { return first . equals ( second ) ; } }