-
Notifications
You must be signed in to change notification settings - Fork 41
/
Schema.ts
97 lines (77 loc) · 1.67 KB
/
Schema.ts
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
import { Schema, type, ArraySchema, MapSchema, filter } from "../src";
// interface IUser {
// name: string;
// }
// interface ResponseMessage {
// user: IUser,
// str: string;
// n: number;
// shortcode: {[id: string]: string};
// }
/**
* No filters example
*/
export class Player extends Schema {
@type("string")
name: string;
@type("number")
x: number;
@type("number")
y: number;
constructor (name?: string, x?: number, y?: number) {
super();
this.name = name;
this.x = x;
this.y = y;
}
}
export class State extends Schema {
@type('string')
fieldString: string;
@type('number') // varint
fieldNumber: number;
@type(Player)
player: Player;
@type([ Player ])
arrayOfPlayers: ArraySchema<Player>;
@type({ map: Player })
mapOfPlayers: MapSchema<Player>;
}
/**
* Deep example
*/
export class Position extends Schema {
@type("float32") x: number;
@type("float32") y: number;
@type("float32") z: number;
constructor (x: number, y: number, z: number) {
super();
this.x = x;
this.y = y;
this.z = z;
}
}
export class Another extends Schema {
@type(Position)
position: Position = new Position(0, 0, 0);
}
export class DeepEntity extends Schema {
@type("string")
name: string;
@type(Another)
another: Another = new Another();
}
export class DeepEntity2 extends DeepEntity {
}
export class DeepChild extends Schema {
@type(DeepEntity)
entity = new DeepEntity();
}
export class DeepMap extends Schema {
@type([DeepChild])
arrayOfChildren = new ArraySchema<DeepChild>();
}
export class DeepState extends Schema {
@type({ map: DeepMap })
map = new MapSchema<DeepMap>();
}