-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
91 lines (82 loc) · 2.52 KB
/
model.js
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
const adt = require('adt');
const adtCoerce = require('@quarterto/adt-coerce');
const dateIsInvalid = require('@quarterto/date-is-invalid');
const onlyInt = adtCoerce(parseInt, isNaN, 'an integer', 10);
const onlyFloat = adtCoerce(parseFloat, isNaN, 'a float', 10);
const toDate = input => new Date(onlyInt(input));
const onlyDate = adtCoerce(toDate, dateIsInvalid, 'a date');
exports.Stop = adt.newtype('Stop', {
stopPointName: adt.only(String, undefined),
stopId: adt.only(String, undefined),
stopCode1: adt.only(String, undefined),
stopCode2: adt.only(String, undefined),
stopPointType: adt.only(String, undefined),
towards: adt.only(String, undefined),
bearing: onlyInt,
stopPointIndicator: adt.only(String, undefined),
stopPointState: onlyInt,
latitude: onlyFloat,
longitude: onlyFloat
});
exports.Prediction = adt.newtype('Prediction', {
stopPointName: adt.only(String, undefined),
stopId: adt.only(String, undefined),
stopCode1: adt.only(String, undefined),
stopCode2: adt.only(String, undefined),
stopPointType: adt.only(String, undefined),
towards: adt.only(String, undefined),
bearing: onlyInt,
stopPointIndicator: adt.only(String, undefined),
stopPointState: onlyInt,
latitude: onlyFloat,
longitude: onlyFloat,
visitNumber: onlyInt,
lineID: adt.only(String),
lineName: adt.only(String),
directionId: onlyInt,
destinationText: adt.only(String),
destinationName: adt.only(String),
vehicleId: onlyInt,
tripId: onlyInt,
registrationNumber: adt.only(String),
estimatedTime: onlyDate,
expireTime: onlyDate
});
exports.FlexibleMessage = adt.newtype('FlexibleMessage', {
stopPointName: adt.only(String, undefined),
stopId: adt.only(String, undefined),
stopCode1: adt.only(String, undefined),
stopCode2: adt.only(String, undefined),
stopPointType: adt.only(String, undefined),
towards: adt.only(String, undefined),
bearing: onlyInt,
stopPointIndicator: adt.only(String, undefined),
stopPointState: onlyInt,
latitude: onlyFloat,
longitude: onlyFloat,
messageUUID: adt.only(String),
messageType: onlyInt,
messagePriority: onlyInt,
messageText: adt.only(String),
startTime: onlyDate,
expireTime: onlyDate
});
exports.BaseVersion = adt.newtype('BaseVersion', {
version: adt.only(String)
});
exports.URAVersion = adt.newtype('URAVersion', {
version: adt.only(String),
timeStamp: onlyDate
});
exports.responseTypes = {
0: exports.Stop,
1: exports.Prediction,
2: exports.FlexibleMessage,
3: exports.BaseVersion,
4: exports.URAVersion,
Stop: 0,
Prediction: 1,
FlexibleMessage: 2,
BaseVersion: 3,
URAVersion: 4
};