import { CoatyObject , CommunicationEventType , CoreTypes , isPlainObject } from ".." ; import { CommunicationEvent , CommunicationEventData } from "./communication-event" ; /**
 * Update event.
 */ export class UpdateEvent extends CommunicationEvent < UpdateEventData > { get eventType ( ) { return CommunicationEventType . Update ; } get responseEventType ( ) { return CommunicationEventType . Complete ; } param event complete : ( event : CompleteEvent ) => void ; internal param eventData throws constructor ( eventData ) { super ( eventData ) ; if ( ! CommunicationEvent . isValidEventFilter ( eventData . object . objectType ) ) { throw new TypeError ( `in UpdateEvent: invalid objectType ${ eventData . object . objectType }` ) ; } } param object throws static withObject ( object ) { return new UpdateEvent ( new UpdateEventData ( object ) ) ; } internal param eventData throws ensureValidResponseParameters ( eventData ) { if ( this . data . object . objectId !== eventData . object . objectId ) { throw new TypeError ( "object ID of Complete event doesn't match object ID of Update event" ) ; } } } /**
 * Defines event data format for update operations on an object.
 */ export class UpdateEventData extends CommunicationEventData { /**
     * The object with properties to be updated.
     */ get object ( ) { return this . _object ; } param object constructor ( private _object ) { super ( ) ; if ( ! this . _hasValidParameters ( ) ) { throw new TypeError ( "in UpdateEventData: arguments not valid" ) ; } } internal static createFrom ( eventData ) { return new UpdateEventData ( eventData . object ) ; } toJsonObject ( ) { return { object : this . _object } ; } private _hasValidParameters ( ) { return CoreTypes . isObject ( this . _object ) ; } } /**
 * Complete event with associated request event.
 */ export class CompleteEvent extends CommunicationEvent < CompleteEventData > { get eventType ( ) { return CommunicationEventType . Complete ; } internal eventRequest : UpdateEvent ; param object param privateData static withObject ( object , privateData ? ) { return new CompleteEvent ( new CompleteEventData ( object , privateData ) ) ; } } /**
 * Defines event data format for Complete events.
 */ export class CompleteEventData extends CommunicationEventData { private _object : CoatyObject ; private _privateData : { [ key ] : any ; } ; param object param privateData constructor ( object , privateData ? ) { super ( ) ; this . _object = object ; this . _privateData = privateData ; if ( ! this . _hasValidParameters ( ) ) { throw new TypeError ( "in CompleteEventData: arguments not valid" ) ; } } internal static createFrom ( eventData ) { return new CompleteEventData ( eventData . object , eventData . privateData ) ; } /**
     * The updated object.
     */ get object ( ) { return this . _object ; } /**
     * Application-specific options as an object hash (optional).
     */ get privateData ( ) { return this . _privateData ; } toJsonObject ( ) { return { object : this . _object , privateData : this . _privateData , } ; } private _hasValidParameters ( ) { return CoreTypes . isObject ( this . _object ) && this . _isValidPrivateData ( ) ; } private _isValidPrivateData ( ) { return this . _privateData === undefined || isPlainObject ( this . _privateData ) ; } }