import { JSONObject , ReadonlyJSONObject , UUID } from '@lumino/coreutils' ; import { Datastore } from '@lumino/datastore' ; /**
 * A patch history object for the datastore.
 */ export type TransactionHistory = { /**
     * All known transactions.
     */ readonly transactions : ReadonlyArray < Datastore . Transaction > ; } ; /**
 * A namespace for messages for communicating with the patch server.
 */ export namespace WSAdapterMessages { /**
     * A base message for the patch server.
     */ export type IBaseMessage = JSONObject & { msgId : string ; msgType : 'storeid-request' | 'storeid-reply' | 'undo-request' | 'undo-reply' | 'redo-request' | 'redo-reply' | 'transaction-broadcast' | 'transaction-ack' | 'history-request' | 'history-reply' | 'fetch-transaction-request' | 'fetch-transaction-reply' ; readonly content : ReadonlyJSONObject ; } ; export type IBaseReplyMessage = IBaseMessage & { parentId : string ; } ; /**
     * A message representing a request for a unique store ID from the server.
     */ export type IStoreIdMessageRequest = IBaseMessage & { msgType : 'storeid-request' ; content : { } ; } ; /**
     * A reply from the server containing a unique store ID.
     */ export type IStoreIdMessageReply = IBaseReplyMessage & { msgType : 'storeid-reply' ; content : { readonly storeId : number ; } ; } ; /**
     * A message representing a request to undo a transaction.
     */ export type IUndoMessageRequest = IBaseMessage & { msgType : 'undo-request' ; content : { readonly transactionId : string ; } ; } ; /**
     * A reply from the server containing a transaction to undo.
     */ export type IUndoMessageReply = IBaseReplyMessage & { msgType : 'undo-reply' ; content : { readonly transaction : Datastore . Transaction ; } ; } ; /**
     * A message representing a request to redo a transaction.
     */ export type IRedoMessageRequest = IBaseMessage & { msgType : 'redo-request' ; content : { readonly transactionId : string ; } ; } ; /**
     * A reply from the server containing a transaction to redo.
     */ export type IRedoMessageReply = IBaseReplyMessage & { msgType : 'redo-reply' ; content : { readonly transaction : Datastore . Transaction ; } ; } ; /**
     * A message from a client broadcasting a transaction.
     */ export type ITransactionBroadcastMessage = IBaseMessage & { msgType : 'transaction-broadcast' ; content : { readonly transactions : ReadonlyArray < Datastore . Transaction > ; } ; } ; /**
     * A message from the server acknowledging receipt of a transaction.
     */ export type ITransactionAckMessage = IBaseReplyMessage & { msgType : 'transaction-ack' ; content : { readonly transactionIds : string [ ] ; } ; } ; /**
     * A request from a client for the patch history from the server.
     */ export type IHistoryRequestMessage = IBaseMessage & { msgType : 'history-request' ; content : { } ; } ; /**
     * A response from the server with the patch history.
     */ export type IHistoryReplyMessage = IBaseReplyMessage & { msgType : 'history-reply' ; content : { history : TransactionHistory ; } ; } ; /**
     * A base reply message from the server.
     */ export type IReplyMessage = IStoreIdMessageReply | ITransactionAckMessage | IUndoMessageReply | IRedoMessageReply | IHistoryReplyMessage ; /**
     * A WSAdapter message.
     */ export type IMessage = IStoreIdMessageRequest | ITransactionBroadcastMessage | IUndoMessageRequest | IRedoMessageRequest | IHistoryRequestMessage | IReplyMessage ; param msgType param content param parentId returns export function createMessage < T extends IMessage > ( msgType , content ? , parentId ? ) { let msgId = UUID . uuid4 ( ) ; if ( content === undefined ) { content = { } ; } return { msgId , msgType , parentId , content } as T ; } param msgType param content param parentId returns export function createReply < T extends IBaseReplyMessage > ( msgType , content , parentId ) { let msgId = UUID . uuid4 ( ) ; return { msgId , msgType , parentId , content } as T ; } returns export function createStoreIdRequestMessage ( ) { return createMessage ( 'storeid-request' , { } ) ; } param parentId param storeId returns export function createStoreIdReplyMessage ( parentId , storeId ) { return createReply ( 'storeid-reply' , { storeId } , parentId ) ; } returns { IUndoMessageRequest } export function createUndoRequestMessage ( id ) { return createMessage < IUndoMessageRequest > ( 'undo-request' , { transactionId : id } ) ; } param parentId param storeId returns export function createUndoReplyMessage ( parentId , transaction ) { return createReply ( 'undo-reply' , { transaction : transaction as any } , parentId ) ; } returns export function createRedoRequestMessage ( id ) { return createMessage ( 'redo-request' , { transactionId : id } ) ; } param parentId param storeId returns export function createRedoReplyMessage ( parentId , transaction ) { return createReply ( 'redo-reply' , { transaction : transaction as any } , parentId ) ; } param transactions returns export function createTransactionBroadcastMessage ( transactions ) { return createMessage ( 'transaction-broadcast' , { transactions : transactions as any } ) ; } param parentId param transactionIds returns export function createTransactionAckMessage ( parentId , transactionIds ) { return createReply ( 'transaction-ack' , { transactionIds } , parentId ) ; } returns { IHistoryRequestMessage } export function createHistoryRequestMessage ( ) { return createMessage ( 'history-request' , { } ) ; } param parentId param history returns export function createHistoryReplyMessage ( parentId , history ) { return createReply ( 'history-reply' , { history } as any , parentId ) ; } param message returns export function isReply ( message ) { return message . parentId !== undefined ; } }