const parseAndUpdate = ( doc , modification , options ) => { Object . keys ( modification ) . forEach ( ( operator ) => { switch ( operator ) { case "$inc" : doc = inc ( doc , modification [ operator ] , options ) ; break ; case "$min" : doc = min ( doc , modification [ operator ] , options ) ; break ; case "$max" : doc = max ( doc , modification [ operator ] , options ) ; break ; case "$mul" : doc = mul ( doc , modification [ operator ] , options ) ; break ; case "$set" : doc = set ( doc , modification [ operator ] , options ) ; break ; case "$unset" : doc = unset ( doc , modification [ operator ] , options ) ; break ; case "$rename" : doc = rename ( doc , modification [ operator ] , options ) ; break ; case "$addToSet" : doc = addToSet ( doc , modification [ operator ] , options ) ; break ; case "$pop" : doc = pop ( doc , modification [ operator ] , options ) ; break ; case "$pullAll" : doc = pullAll ( doc , modification [ operator ] , options ) ; break ; default : throw new Error ( `${ operator } update operator is not supported` ) ; } } ) ; } ; param { JSON Object param { JSON Object const currentDate = ( doc , modification , options ) => { } ; param { JSON Object param { JSON Object const inc = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && typeof doc [ field ] == "number" ) { doc [ field ] += modification [ field ] ; } } return doc ; } ; param { JSON Object param { JSON Object const min = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] ) { if ( doc [ field ] >= modification [ field ] ) { doc [ field ] = modification [ field ] ; } } } return doc ; } ; param { JSON Object param { JSON Object const max = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] ) { if ( doc [ field ] <= modification [ field ] ) { doc [ field ] = modification [ field ] ; } } } return doc ; } ; param { JSON Object param { JSON Object const mul = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && typeof doc [ field ] == "number" ) { doc [ field ] *= modification [ field ] ; } else if ( ! doc [ field ] ) { doc [ field ] = 0 ; } } return doc ; } ; param { JSON Object param { JSON Object const rename = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] ) { const value = doc [ field ] ; doc = unset ( doc , { field : "" } ) ; const newField = { } ; newField [ modification . field ] = value ; doc = set ( doc , newField ) ; } } return doc ; } ; param { JSON Object param { JSON Object const set = ( doc , modification , options ? ) => { for ( const field in modification ) { doc [ field ] = modification [ field ] ; } return doc ; } ; param { JSON Object param { JSON Object const setOnInsert = ( doc , modification , options ) => { return doc ; } ; param { JSON Object param { JSON Object const unset = ( doc , modification , options = { } ) => { for ( const field in modification ) { delete doc [ field ] ; } return doc ; } ; param { JSON Object param { JSON Object const addToSet = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && doc [ field ] . constructor === Array ) { if ( ! doc [ field ] . includes ( modification [ field ] ) ) { doc [ field ] . push ( modification [ field ] ) ; } } else if ( ! doc [ field ] ) { doc [ field ] = [ modification [ field ] ] ; } } return doc ; } ; param { JSON Object param { JSON Object const pop = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && doc [ field ] . constructor === Array ) { if ( doc [ field ] . length > 0 ) { if ( modification [ field ] === - 1 ) { doc [ field ] . shift ( ) ; } else if ( modification [ field ] === 1 ) { doc [ field ] . pop ( ) ; } } } } return doc ; } ; param { JSON Object param { JSON Object const pull = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && doc [ field ] . constructor === Array ) { if ( Object . keys ( modification [ field ] ) . length === 0 && modification [ field ] . constructor === Object ) { } else { doc = doc [ field ] . filter ( ( item ) => { return item !== modification [ field ] ; } ) ; } } } } ; param { JSON Object param { JSON Object const push = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && doc [ field ] . constructor === Array ) { doc [ field ] . push ( modification [ field ] ) ; } else if ( ! doc [ field ] ) { doc [ field ] = [ modification [ field ] ] ; } } return doc ; } ; param { JSON Object param { JSON Object const pullAll = ( doc , modification , options ) => { for ( const field in modification ) { if ( doc [ field ] && doc [ field ] . constructor === Array ) { modification [ field ] . forEach ( ( element ) => { doc = doc [ field ] . filter ( ( item ) => { if ( item . constructor === Array ) { return ! arraysEqual ( item , element ) ; } return item !== element ; } ) ; } ) ; } } return doc ; } ; param { JSON Object param { JSON Object const each = ( doc , modification , options ) => { return doc ; } ; param { JSON Object param { JSON Object const position = ( doc , modification , options ) => { return doc ; } ; param { JSON Object param { JSON Object const slice = ( doc , modification , options ) => { return doc ; } ; param { JSON Object param { JSON Object const sort = ( doc , modification , options ) => { return doc ; } ; param { JSON Object param { JSON Object const bit = ( doc , modification , options ) => { return doc ; } ; const arraysEqual = ( a , b ) => { if ( a === b ) return true ; if ( a == null || b == null ) return false ; if ( a . length != b . length ) return false ; for ( let i = 0 ; i < a . length ; ++ i ) { if ( a [ i ] !== b [ i ] ) return false ; } return true ; } ; export { parseAndUpdate } ;