@dev-crew-berlin/enter-js-utils 0.5.3 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client/api-base.js +160 -287
- package/dist/api-client/index.js +73 -190
- package/dist/lib/api-result.js +9 -13
- package/dist/lib/class-names.js +2 -12
- package/dist/lib/index.js +1 -2
- package/dist/lib/not-undefined.js +2 -3
- package/dist/lib/result.js +27 -23
- package/dist/lib/theme.js +17 -18
- package/dist/models/_helpers.js +64 -65
- package/dist/models/access-token.js +9 -6
- package/dist/models/attendee.js +109 -100
- package/dist/models/checkin-counts.js +7 -3
- package/dist/models/checkins.js +61 -69
- package/dist/models/event.js +1 -2
- package/dist/models/field-group.js +43 -43
- package/dist/models/field-value.js +1 -2
- package/dist/models/field.js +86 -41
- package/dist/models/index.js +1 -2
- package/dist/models/instance.js +109 -99
- package/dist/models/invite.js +18 -15
- package/dist/models/meta-field.js +8 -7
- package/dist/models/user.js +10 -9
- package/dist/models/variable.js +15 -14
- package/dist/ui/button.js +15 -29
- package/dist/ui/button.stories.js +17 -27
- package/dist/ui/checkin-count-indicator.js +67 -46
- package/dist/ui/checkin-count-indicator.stories.js +45 -47
- package/dist/ui/companion-info.js +14 -14
- package/dist/ui/companion-info.stories.js +59 -50
- package/dist/ui/fonts.js +6 -4
- package/dist/ui/guest-card.js +39 -30
- package/dist/ui/guest-card.stories.js +115 -104
- package/dist/ui/index.js +1 -2
- package/dist/ui/tag.js +9 -6
- package/package.json +7 -34
- package/dist/api-client/api-base.js.map +0 -1
- package/dist/api-client/index.js.map +0 -1
- package/dist/lib/api-result.js.map +0 -1
- package/dist/lib/class-names.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/not-undefined.js.map +0 -1
- package/dist/lib/result.js.map +0 -1
- package/dist/lib/theme.js.map +0 -1
- package/dist/models/_helpers.js.map +0 -1
- package/dist/models/access-token.js.map +0 -1
- package/dist/models/attendee.js.map +0 -1
- package/dist/models/checkin-counts.js.map +0 -1
- package/dist/models/checkins.js.map +0 -1
- package/dist/models/event.js.map +0 -1
- package/dist/models/field-group.js.map +0 -1
- package/dist/models/field-value.js.map +0 -1
- package/dist/models/field.js.map +0 -1
- package/dist/models/index.js.map +0 -1
- package/dist/models/instance.js.map +0 -1
- package/dist/models/invite.js.map +0 -1
- package/dist/models/meta-field.js.map +0 -1
- package/dist/models/user.js.map +0 -1
- package/dist/models/variable.js.map +0 -1
- package/dist/ui/button.js.map +0 -1
- package/dist/ui/button.stories.js.map +0 -1
- package/dist/ui/checkin-count-indicator.js.map +0 -1
- package/dist/ui/checkin-count-indicator.stories.js.map +0 -1
- package/dist/ui/companion-info.js.map +0 -1
- package/dist/ui/companion-info.stories.js.map +0 -1
- package/dist/ui/fonts.js.map +0 -1
- package/dist/ui/guest-card.js.map +0 -1
- package/dist/ui/guest-card.stories.js.map +0 -1
- package/dist/ui/index.js.map +0 -1
- package/dist/ui/tag.js.map +0 -1
package/dist/api-client/index.js
CHANGED
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
32
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
1
|
import APIBase from './api-base';
|
|
53
2
|
import { success } from '../lib';
|
|
54
3
|
import { parseAttendee, parseAttendeeList } from '../models/attendee';
|
|
@@ -59,142 +8,76 @@ import { parseInvite } from '../models/invite';
|
|
|
59
8
|
import { parseUser } from '../models/user';
|
|
60
9
|
import { parseVariable, parseVariableList } from '../models/variable';
|
|
61
10
|
import { parseNoContent } from '../models/_helpers';
|
|
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
|
-
API.prototype.getAttendeeById = function (args) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
-
return __generator(this, function (_a) {
|
|
141
|
-
switch (_a.label) {
|
|
142
|
-
case 0: return [4 /*yield*/, this.get("instances/".concat(args.instanceId, "/attendees/").concat(args.attendeeId), parseAttendee)];
|
|
143
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
API.prototype.createEvents = function (args) {
|
|
149
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
return __generator(this, function (_a) {
|
|
151
|
-
return [2 /*return*/, this.post("events", args.events, parseNoContent)];
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
API.prototype.getUser = function () {
|
|
156
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
return __generator(this, function (_a) {
|
|
158
|
-
return [2 /*return*/, this.get('user', parseUser)];
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
API.prototype.patchUser = function (args) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
-
return __generator(this, function (_a) {
|
|
165
|
-
return [2 /*return*/, this.patch('user', args, parseNoContent)];
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
API.prototype.getAllVariables = function (args) {
|
|
170
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
-
return __generator(this, function (_a) {
|
|
172
|
-
return [2 /*return*/, this.get("instances/".concat(args.instanceId, "/variables"), parseVariableList)];
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
API.prototype.getVariableByName = function (args) {
|
|
177
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
-
return __generator(this, function (_a) {
|
|
179
|
-
return [2 /*return*/, this.get("instances/".concat(args.instanceId, "/variables/").concat(args.variableName), parseVariable)];
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
API.prototype.createVariable = function (args) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
return __generator(this, function (_a) {
|
|
186
|
-
return [2 /*return*/, this.post("instances/".concat(args.instanceId, "/variables"), args.variable, parseVariable)];
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
API.prototype.updateVariable = function (args) {
|
|
191
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
192
|
-
return __generator(this, function (_a) {
|
|
193
|
-
return [2 /*return*/, this.put("instances/".concat(args.instanceId, "/variables/").concat(args.variableName), args.update, parseVariable)];
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
return API;
|
|
198
|
-
}(APIBase));
|
|
199
|
-
export default API;
|
|
200
|
-
//# sourceMappingURL=index.js.map
|
|
11
|
+
export default class API extends APIBase {
|
|
12
|
+
async getInstance(args) {
|
|
13
|
+
return this.get(`instances/${args.instanceId}`, parseInstance);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async getInstanceList() {
|
|
17
|
+
return this.get(`instances`, parseInstanceList);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getFields(args) {
|
|
21
|
+
return this.get(`instances/${args.instanceId}/fields`, parseFieldGroups);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getCheckinCounts(args) {
|
|
25
|
+
return this.get(`instances/${args.instanceId}/checkins`, parseCheckinCounts);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async getAttendeeList(args) {
|
|
29
|
+
return this.get(`instances/${args.instanceId}/attendees`, parseAttendeeList);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async sendEmail(args) {
|
|
33
|
+
const guestId = args.collection === 'attendees' ? args.attendeeId : args.index;
|
|
34
|
+
return this.post(`instances/${args.instanceId}/${args.collection}/${guestId}/emails/${args.mailId}`, null, parseNoContent);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getAttendeesByAuthCode(args) {
|
|
38
|
+
// it is stupid to get all attendees here
|
|
39
|
+
// but here we would need a special endpoint that could get attendees by authcode
|
|
40
|
+
const allAttendees = await this.getAttendeeList({
|
|
41
|
+
instanceId: args.instanceId
|
|
42
|
+
});
|
|
43
|
+
if (!allAttendees.success) return allAttendees;
|
|
44
|
+
return success(allAttendees.data.filter(attendee => attendee.auth === args.authCode));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getInviteByAuthCode(args) {
|
|
48
|
+
return await this.get(`instances/${args.instanceId}/invites/${args.authCode}`, parseInvite);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async getAttendeeById(args) {
|
|
52
|
+
return await this.get(`instances/${args.instanceId}/attendees/${args.attendeeId}`, parseAttendee);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async createEvents(args) {
|
|
56
|
+
return this.post(`events`, args.events, parseNoContent);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getUser() {
|
|
60
|
+
return this.get('user', parseUser);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async patchUser(args) {
|
|
64
|
+
return this.patch('user', args, parseNoContent);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async getAllVariables(args) {
|
|
68
|
+
return this.get(`instances/${args.instanceId}/variables`, parseVariableList);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getVariableByName(args) {
|
|
72
|
+
return this.get(`instances/${args.instanceId}/variables/${args.variableName}`, parseVariable);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async createVariable(args) {
|
|
76
|
+
return this.post(`instances/${args.instanceId}/variables`, args.variable, parseVariable);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async updateVariable(args) {
|
|
80
|
+
return this.put(`instances/${args.instanceId}/variables/${args.variableName}`, args.update, parseVariable);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
package/dist/lib/api-result.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { isSuccess, getErrorString } from 'fefe';
|
|
2
2
|
import { success, failure } from './result';
|
|
3
3
|
export function apiValidator(validate) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
]);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=api-result.js.map
|
|
4
|
+
return value => {
|
|
5
|
+
const fefeResult = validate(value);
|
|
6
|
+
if (isSuccess(fefeResult)) return success(fefeResult.right);
|
|
7
|
+
return failure([{
|
|
8
|
+
type: 'validation-error',
|
|
9
|
+
message: getErrorString(fefeResult.left)
|
|
10
|
+
}]);
|
|
11
|
+
};
|
|
12
|
+
}
|
package/dist/lib/class-names.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
export function classNames(classNames) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var isActive = _a[1];
|
|
5
|
-
return isActive === true;
|
|
6
|
-
})
|
|
7
|
-
.map(function (_a) {
|
|
8
|
-
var className = _a[0];
|
|
9
|
-
return className;
|
|
10
|
-
})
|
|
11
|
-
.join(' ');
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=class-names.js.map
|
|
2
|
+
return Object.entries(classNames).filter(([, isActive]) => isActive === true).map(([className]) => className).join(' ');
|
|
3
|
+
}
|
package/dist/lib/index.js
CHANGED
package/dist/lib/result.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
export function success(data) {
|
|
2
|
-
|
|
2
|
+
return {
|
|
3
|
+
success: true,
|
|
4
|
+
data: data
|
|
5
|
+
};
|
|
3
6
|
}
|
|
4
7
|
export function failure(reason) {
|
|
5
|
-
|
|
8
|
+
return {
|
|
9
|
+
success: false,
|
|
10
|
+
error: reason
|
|
11
|
+
};
|
|
6
12
|
}
|
|
7
13
|
export function asSuccess(result) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return result;
|
|
14
|
+
if (!result.success) return undefined;
|
|
15
|
+
return result;
|
|
11
16
|
}
|
|
12
17
|
export function asFailure(result) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return result;
|
|
18
|
+
if (result.success) return undefined;
|
|
19
|
+
return result;
|
|
16
20
|
}
|
|
21
|
+
|
|
17
22
|
/**
|
|
18
23
|
* Takes a list of Results and creates one single result out of it
|
|
19
24
|
*
|
|
@@ -27,20 +32,19 @@ export function asFailure(result) {
|
|
|
27
32
|
* @returns
|
|
28
33
|
*/
|
|
29
34
|
export function combineResults(results) {
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
success: true,
|
|
33
|
-
data: results.map(
|
|
34
|
-
// the if statement checks that every result is a success so we can force this here
|
|
35
|
-
function (success) { return asSuccess(success).data; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
36
|
-
), // also the typechecker does not resolve this so we just tell him its fine and hope there are no errors
|
|
37
|
-
};
|
|
38
|
-
}
|
|
35
|
+
if (results.every(result => result.success)) {
|
|
39
36
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
success: true,
|
|
38
|
+
data: results.map( // the if statement checks that every result is a success so we can force this here
|
|
39
|
+
success => asSuccess(success).data // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
40
|
+
) // also the typechecker does not resolve this so we just tell him its fine and hope there are no errors
|
|
41
|
+
|
|
44
42
|
};
|
|
45
|
-
}
|
|
46
|
-
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
error: results.map(result => asFailure(result)?.error).filter(failure => failure !== undefined) // the typechecker does not resolve this so we just tell him its fine and hope there are no errors
|
|
48
|
+
|
|
49
|
+
};
|
|
50
|
+
}
|
package/dist/lib/theme.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
export const colors = {
|
|
2
|
+
enterDarkGrey: '#483E47',
|
|
3
|
+
enterLightGrey: '#EEE',
|
|
4
|
+
enterMediumGrey: '#A09999',
|
|
5
|
+
enterGrey: '#D8D8D8',
|
|
6
|
+
enterBackground: '#F8FAFB',
|
|
7
|
+
enterModalBackground: '#FFFEFC',
|
|
8
|
+
enterError: '#CE1E3D',
|
|
9
|
+
enterRed: '#FF5555',
|
|
10
|
+
enterCyan: '#74ACBC',
|
|
11
|
+
enterGreen: '#89B859',
|
|
12
|
+
enterYellow: '#E7C700',
|
|
13
|
+
enterPink: '#E66084'
|
|
14
14
|
};
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=theme.js.map
|
|
15
|
+
export const fonts = {
|
|
16
|
+
primary: 'PTSans, sans-serif',
|
|
17
|
+
secondary: 'Iosevka, monospace'
|
|
18
|
+
};
|
package/dist/models/_helpers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { branchError, failure, isFailure, leafError, number, success
|
|
1
|
+
import { branchError, failure, isFailure, leafError, number, success } from 'fefe';
|
|
2
2
|
import { apiValidator } from '../lib';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* creates a validator that tries to parse a unkown value to
|
|
5
6
|
* a Dictionary.
|
|
@@ -12,79 +13,77 @@ import { apiValidator } from '../lib';
|
|
|
12
13
|
* @param validator the validator for the value of the record
|
|
13
14
|
*/
|
|
14
15
|
export function dictionary(validator) {
|
|
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
|
-
};
|
|
16
|
+
return value => {
|
|
17
|
+
// make shure value is an js object
|
|
18
|
+
// keep in mind lots of things in js are objects arrays, Sets…
|
|
19
|
+
// so this does not tell us too much
|
|
20
|
+
if (typeof value !== 'object' || value === null) {
|
|
21
|
+
return failure(leafError(value, 'expected value to be an object'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const validatedProperties = Object.entries(value).map(([key, raw]) => {
|
|
25
|
+
// make shure the key is of type string
|
|
26
|
+
if (typeof key !== 'string') {
|
|
27
|
+
return {
|
|
28
|
+
key,
|
|
29
|
+
result: failure(leafError([key, raw], 'expected key to be of type string'))
|
|
30
|
+
};
|
|
31
|
+
} // make shure the value is valid by passing it to the supplied validator
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
key,
|
|
36
|
+
result: validator(raw)
|
|
37
|
+
};
|
|
38
|
+
}); // collect possible errors
|
|
39
|
+
|
|
40
|
+
const errors = validatedProperties.filter(property => isFailure(property.result)).map(property => {
|
|
41
|
+
return {
|
|
42
|
+
key: property.key,
|
|
43
|
+
error: property.result.left
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
if (errors.length !== 0) return failure(branchError(value, errors)); // flatten list of successfull results into single result
|
|
47
|
+
|
|
48
|
+
return success(validatedProperties.reduce((a, b) => {
|
|
49
|
+
a[b.key] = b.result.right;
|
|
50
|
+
return a;
|
|
51
|
+
}, {}));
|
|
52
|
+
};
|
|
51
53
|
}
|
|
52
54
|
export function constant(constant) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
return value => {
|
|
56
|
+
if (value !== constant) {
|
|
57
|
+
return failure(leafError(value, `expect value to be ${String(constant)}`));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return success(constant);
|
|
61
|
+
};
|
|
59
62
|
}
|
|
60
63
|
export function toString(value) {
|
|
61
|
-
|
|
64
|
+
return success('' + value);
|
|
62
65
|
}
|
|
63
66
|
export function parseTimestamp(value) {
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
// js Date expects timestamp in mili seconds but we expect to parse a timestamp in seconds
|
|
68
|
+
return success(new Date(value * 1000));
|
|
66
69
|
}
|
|
67
|
-
export function maybe(validator, defaultValue) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return validator(value);
|
|
73
|
-
};
|
|
70
|
+
export function maybe(validator, defaultValue = null) {
|
|
71
|
+
return value => {
|
|
72
|
+
if (value === null) return success(defaultValue);
|
|
73
|
+
return validator(value);
|
|
74
|
+
};
|
|
74
75
|
}
|
|
75
76
|
export function noContent(value) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return failure(leafError(value, 'expected value to be empty'));
|
|
77
|
+
if (value === null || value === undefined) return success(null);
|
|
78
|
+
return failure(leafError(value, 'expected value to be empty'));
|
|
79
79
|
}
|
|
80
80
|
export function unknown() {
|
|
81
|
-
|
|
81
|
+
return value => success(value);
|
|
82
82
|
}
|
|
83
|
-
export
|
|
84
|
-
export
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
//# sourceMappingURL=_helpers.js.map
|
|
83
|
+
export const parseNoContent = apiValidator(noContent);
|
|
84
|
+
export const positiveInteger = number({
|
|
85
|
+
integer: true,
|
|
86
|
+
min: 0,
|
|
87
|
+
allowNaN: false,
|
|
88
|
+
allowInfinity: false
|
|
89
|
+
});
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { object, parseDate, pipe, string } from 'fefe';
|
|
2
2
|
import { apiValidator } from '../lib';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const accessToken = object({
|
|
4
|
+
accessToken: string(),
|
|
5
|
+
expires: pipe(string()).pipe(parseDate({
|
|
6
|
+
iso: true
|
|
7
|
+
}))
|
|
8
|
+
}, {
|
|
9
|
+
allowExcessProperties: true
|
|
10
|
+
});
|
|
11
|
+
export const parseAccessToken = apiValidator(accessToken);
|