import { Ident } from './idents' ; /**
 * The kind of operation.
 */ export enum OpKind { /**
     * The insertion of a value.
     */ Insert = 1 , /**
     * The removal of a value.
     */ Remove = 2 } /**
 * An operation that can be applied to a KSeq.
 */ export abstract class Op { /**
     * The kind of operation.
     */ kind : OpKind ; /**
     * The name of the replica on which the operation was performed.
     */ replica : string ; /**
     * A UNIX epoch timestamp for the wall time at which the operation was performed.
     * (Note: since this is generated by the local replica's clock, it is just an
     * approximation and should not be used to create a total order.)
     */ timestamp : number ; param kind param replica param timestamp returns constructor ( kind , replica , timestamp ) { this . kind = kind ; this . replica = replica ; this . timestamp = timestamp ; } param str returns static parse ( str ) { const kind = str [ 0 ] ; switch ( kind ) { case '+' : return InsertOp . parse ( str ) ; case '-' : return RemoveOp . parse ( str ) ; } } /**
     * Encodes the Op as a compact string representation.
     */ abstract toString ( ) ; } /**
 * An operation that inserts an atom into the sequence with the specified
 * identifier and value.
 */ export class InsertOp extends Op { /**
     * The identifier for the value.
     */ id : Ident ; /**
     * The value to insert.
     */ value : any ; param replica param timestamp param id param value returns constructor ( replica , timestamp , id , value ) { super ( OpKind . Insert , replica , timestamp ) ; this . id = id ; this . value = value ; } param str returns static parse ( str ) { let [ timestamp , replica , id , value ] = str . substr ( 1 ) . split ( '/' , 4 ) ; return new InsertOp ( replica , Number ( timestamp ) , Ident . parse ( str ) , JSON . parse ( value ) ) ; } inheritdoc toString ( ) { return `+${ this . timestamp }/${ this . replica }/${ this . id . toString ( ) }/${ JSON . stringify ( this . value ) }` ; } } /**
 * An operation that removes an atom with the specified identifer.
 */ export class RemoveOp extends Op { /**
     * The identifier to remove.
     */ id : Ident ; param replica param timestamp param id returns constructor ( replica , timestamp , id ) { super ( OpKind . Remove , replica , timestamp ) ; this . id = id ; } param str returns static parse ( str ) { let [ timestamp , replica , id ] = str . substr ( 1 ) . split ( '/' , 3 ) ; return new RemoveOp ( replica , Number ( timestamp ) , Ident . parse ( str ) ) ; } inheritdoc toString ( ) { return `-${ this . timestamp }/${ this . replica }/${ this . id . toString ( ) }` ; } }