aboutsummaryrefslogtreecommitdiff
path: root/src/server/Message.ts
blob: 0274609bb91144a9212eb9363bf8b1a3f061774a (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { Utils } from "../Utils";

export class Message<T> {
    private name: string;
    private guid: string;

    get Name(): string {
        return this.name;
    }

    get Message(): string {
        return this.guid;
    }

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

    GetValue() {
        return this.Name;
    }
}

class TestMessageArgs {
    hello: string = "";
}

export class SetFieldArgs {
    field: string;
    value: any;

    constructor(f: string, v: any) {
        this.field = f;
        this.value = v;
    }
}

export class GetFieldArgs {
    field: string;

    constructor(f: string) {
        this.field = f;
    }
}

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

export class DocumentTransfer implements Transferable {
    readonly type = Types.Document;
    _id: string;

    constructor(
        readonly obj: { type: Types; data: [string, string][]; _id: string }
    ) {
        this._id = obj._id;
    }
}

export class ImageTransfer implements Transferable {
    readonly type = Types.Image;

    constructor(readonly _id: string) { }
}

export class KeyTransfer implements Transferable {
    name: string;
    readonly _id: string;
    readonly type = Types.Key;

    constructor(i: string, n: string) {
        this.name = n;
        this._id = i;
    }
}

export class ListTransfer implements Transferable {
    type = Types.List;

    constructor(readonly _id: string) { }
}

export class NumberTransfer implements Transferable {
    readonly type = Types.Number;

    constructor(readonly value: number, readonly _id: string) { }
}

export class TextTransfer implements Transferable {
    value: string;
    readonly _id: string;
    readonly type = Types.Text;

    constructor(t: string, i: string) {
        this.value = t;
        this._id = i;
    }
}

export class RichTextTransfer implements Transferable {
    value: string;
    readonly _id: string;
    readonly type = Types.Text;

    constructor(t: string, i: string) {
        this.value = t;
        this._id = i;
    }
}

export interface Transferable {
    readonly _id: string;
    readonly type: Types;
}

export namespace MessageStore {
    export const Foo = new Message<string>("Foo");
    export const Bar = new Message<string>("Bar");
    export const AddDocument = new Message<DocumentTransfer>("Add Document");
    export const SetField = new Message<{ _id: string; data: any; type: Types }>(
        "Set Field"
    );
    export const GetField = new Message<string>("Get Field");
    export const GetFields = new Message<string[]>("Get Fields");
    export const GetDocument = new Message<string>("Get Document");
    export const DeleteAll = new Message<any>("Delete All");
}