aboutsummaryrefslogtreecommitdiff
path: root/src/server/Message.ts
blob: b0193472406e885df4adf5e04a0b3b5f841cbb77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Utils } from "../Utils";

export class Message<T> {
    private _name: string;
    private _guid: string;

    constructor(name: string) {
        this._name = name;
        this._guid = Utils.GenerateDeterministicGuid(name);
    }

    get Name(): string { return this._name; }
    get Message(): string { return this._guid; }
}

export enum Types {
    Number, List, Key, Image, Web, Document, Text, Icon, RichText, DocumentReference,
    Html, Video, Audio, Ink, PDF, Tuple, HistogramOp, Boolean, Script,
}

export interface Transferable {
    readonly id: string;
    readonly type: Types;
    readonly data?: any;
}

export interface Reference {
    readonly id: string;
}

export interface Diff extends Reference {
    readonly diff: any;
}

export namespace MessageStore {
    export const Foo = new Message<string>("Foo");
    export const Bar = new Message<string>("Bar");
    export const SetField = new Message<Transferable>("Set Field"); // send Transferable (no reply)
    export const GetField = new Message<string>("Get Field"); // send string 'id' get Transferable back
    export const GetFields = new Message<string[]>("Get Fields"); // send string[] of 'id' get Transferable[] back
    export const GetDocument = new Message<string>("Get Document");
    export const DeleteAll = new Message<any>("Delete All");

    export const GetRefField = new Message<string>("Get Ref Field");
    export const UpdateField = new Message<Diff>("Update Ref Field");
    export const CreateField = new Message<Reference>("Create Ref Field");
}