@dev-crew-berlin/enter-js-utils 0.5.3 → 0.5.4

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.
Files changed (103) hide show
  1. package/dist/api-client/api-base.js +160 -287
  2. package/dist/api-client/index.js +73 -190
  3. package/dist/lib/api-result.js +9 -13
  4. package/dist/lib/class-names.js +2 -12
  5. package/dist/lib/index.js +1 -2
  6. package/dist/lib/not-undefined.js +2 -3
  7. package/dist/lib/result.js +27 -23
  8. package/dist/lib/theme.js +17 -18
  9. package/dist/models/_helpers.js +64 -65
  10. package/dist/models/access-token.js +9 -6
  11. package/dist/models/attendee.js +109 -100
  12. package/dist/models/checkin-counts.js +7 -3
  13. package/dist/models/checkins.js +61 -69
  14. package/dist/models/event.js +1 -2
  15. package/dist/models/field-group.js +43 -43
  16. package/dist/models/field-value.js +1 -2
  17. package/dist/models/field.js +86 -41
  18. package/dist/models/index.js +1 -2
  19. package/dist/models/instance.js +109 -99
  20. package/dist/models/invite.js +18 -15
  21. package/dist/models/meta-field.js +8 -7
  22. package/dist/models/user.js +10 -9
  23. package/dist/models/variable.js +15 -14
  24. package/dist/ui/button.js +15 -29
  25. package/dist/ui/button.stories.js +17 -27
  26. package/dist/ui/checkin-count-indicator.js +67 -46
  27. package/dist/ui/checkin-count-indicator.stories.js +45 -47
  28. package/dist/ui/companion-info.js +14 -14
  29. package/dist/ui/companion-info.stories.js +59 -50
  30. package/dist/ui/fonts.js +6 -4
  31. package/dist/ui/guest-card.js +39 -30
  32. package/dist/ui/guest-card.stories.js +115 -104
  33. package/dist/ui/index.js +1 -2
  34. package/dist/ui/tag.js +9 -6
  35. package/package.json +7 -34
  36. package/dist/api-client/api-base.d.ts +0 -30
  37. package/dist/api-client/api-base.js.map +0 -1
  38. package/dist/api-client/index.d.ts +0 -75
  39. package/dist/api-client/index.js.map +0 -1
  40. package/dist/lib/api-result.d.ts +0 -25
  41. package/dist/lib/api-result.js.map +0 -1
  42. package/dist/lib/class-names.d.ts +0 -1
  43. package/dist/lib/class-names.js.map +0 -1
  44. package/dist/lib/index.d.ts +0 -5
  45. package/dist/lib/index.js.map +0 -1
  46. package/dist/lib/not-undefined.d.ts +0 -1
  47. package/dist/lib/not-undefined.js.map +0 -1
  48. package/dist/lib/result.d.ts +0 -33
  49. package/dist/lib/result.js.map +0 -1
  50. package/dist/lib/theme.d.ts +0 -18
  51. package/dist/lib/theme.js.map +0 -1
  52. package/dist/models/_helpers.d.ts +0 -23
  53. package/dist/models/_helpers.js.map +0 -1
  54. package/dist/models/access-token.d.ts +0 -11
  55. package/dist/models/access-token.js.map +0 -1
  56. package/dist/models/attendee.d.ts +0 -90
  57. package/dist/models/attendee.js.map +0 -1
  58. package/dist/models/checkin-counts.d.ts +0 -10
  59. package/dist/models/checkin-counts.js.map +0 -1
  60. package/dist/models/checkins.d.ts +0 -40
  61. package/dist/models/checkins.js.map +0 -1
  62. package/dist/models/event.d.ts +0 -40
  63. package/dist/models/event.js.map +0 -1
  64. package/dist/models/field-group.d.ts +0 -484
  65. package/dist/models/field-group.js.map +0 -1
  66. package/dist/models/field-value.d.ts +0 -2
  67. package/dist/models/field-value.js.map +0 -1
  68. package/dist/models/field.d.ts +0 -321
  69. package/dist/models/field.js.map +0 -1
  70. package/dist/models/index.d.ts +0 -14
  71. package/dist/models/index.js.map +0 -1
  72. package/dist/models/instance.d.ts +0 -78
  73. package/dist/models/instance.js.map +0 -1
  74. package/dist/models/invite.d.ts +0 -33
  75. package/dist/models/invite.js.map +0 -1
  76. package/dist/models/meta-field.d.ts +0 -7
  77. package/dist/models/meta-field.js.map +0 -1
  78. package/dist/models/user.d.ts +0 -18
  79. package/dist/models/user.js.map +0 -1
  80. package/dist/models/variable.d.ts +0 -27
  81. package/dist/models/variable.js.map +0 -1
  82. package/dist/ui/button.d.ts +0 -7
  83. package/dist/ui/button.js.map +0 -1
  84. package/dist/ui/button.stories.d.ts +0 -18
  85. package/dist/ui/button.stories.js.map +0 -1
  86. package/dist/ui/checkin-count-indicator.d.ts +0 -15
  87. package/dist/ui/checkin-count-indicator.js.map +0 -1
  88. package/dist/ui/checkin-count-indicator.stories.d.ts +0 -84
  89. package/dist/ui/checkin-count-indicator.stories.js.map +0 -1
  90. package/dist/ui/companion-info.d.ts +0 -15
  91. package/dist/ui/companion-info.js.map +0 -1
  92. package/dist/ui/companion-info.stories.d.ts +0 -44
  93. package/dist/ui/companion-info.stories.js.map +0 -1
  94. package/dist/ui/fonts.d.ts +0 -3
  95. package/dist/ui/fonts.js.map +0 -1
  96. package/dist/ui/guest-card.d.ts +0 -16
  97. package/dist/ui/guest-card.js.map +0 -1
  98. package/dist/ui/guest-card.stories.d.ts +0 -92
  99. package/dist/ui/guest-card.stories.js.map +0 -1
  100. package/dist/ui/index.d.ts +0 -6
  101. package/dist/ui/index.js.map +0 -1
  102. package/dist/ui/tag.d.ts +0 -7
  103. package/dist/ui/tag.js.map +0 -1
@@ -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
- var API = /** @class */ (function (_super) {
63
- __extends(API, _super);
64
- function API() {
65
- return _super !== null && _super.apply(this, arguments) || this;
66
- }
67
- API.prototype.getInstance = function (args) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- return __generator(this, function (_a) {
70
- return [2 /*return*/, this.get("instances/".concat(args.instanceId), parseInstance)];
71
- });
72
- });
73
- };
74
- API.prototype.getInstanceList = function () {
75
- return __awaiter(this, void 0, void 0, function () {
76
- return __generator(this, function (_a) {
77
- return [2 /*return*/, this.get("instances", parseInstanceList)];
78
- });
79
- });
80
- };
81
- API.prototype.getFields = function (args) {
82
- return __awaiter(this, void 0, void 0, function () {
83
- return __generator(this, function (_a) {
84
- return [2 /*return*/, this.get("instances/".concat(args.instanceId, "/fields"), parseFieldGroups)];
85
- });
86
- });
87
- };
88
- API.prototype.getCheckinCounts = function (args) {
89
- return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- return [2 /*return*/, this.get("instances/".concat(args.instanceId, "/checkins"), parseCheckinCounts)];
92
- });
93
- });
94
- };
95
- API.prototype.getAttendeeList = function (args) {
96
- return __awaiter(this, void 0, void 0, function () {
97
- return __generator(this, function (_a) {
98
- return [2 /*return*/, this.get("instances/".concat(args.instanceId, "/attendees"), parseAttendeeList)];
99
- });
100
- });
101
- };
102
- API.prototype.sendEmail = function (args) {
103
- return __awaiter(this, void 0, void 0, function () {
104
- var guestId;
105
- return __generator(this, function (_a) {
106
- guestId = args.collection === 'attendees' ? args.attendeeId : args.index;
107
- return [2 /*return*/, this.post("instances/".concat(args.instanceId, "/").concat(args.collection, "/").concat(guestId, "/emails/").concat(args.mailId), null, parseNoContent)];
108
- });
109
- });
110
- };
111
- API.prototype.getAttendeesByAuthCode = function (args) {
112
- return __awaiter(this, void 0, void 0, function () {
113
- var allAttendees;
114
- return __generator(this, function (_a) {
115
- switch (_a.label) {
116
- case 0: return [4 /*yield*/, this.getAttendeeList({
117
- instanceId: args.instanceId,
118
- })];
119
- case 1:
120
- allAttendees = _a.sent();
121
- if (!allAttendees.success)
122
- return [2 /*return*/, allAttendees];
123
- return [2 /*return*/, success(allAttendees.data.filter(function (attendee) { return attendee.auth === args.authCode; }))];
124
- }
125
- });
126
- });
127
- };
128
- API.prototype.getInviteByAuthCode = function (args) {
129
- return __awaiter(this, void 0, void 0, function () {
130
- return __generator(this, function (_a) {
131
- switch (_a.label) {
132
- case 0: return [4 /*yield*/, this.get("instances/".concat(args.instanceId, "/invites/").concat(args.authCode), parseInvite)];
133
- case 1: return [2 /*return*/, _a.sent()];
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
+ }
@@ -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
- return function (value) {
5
- var fefeResult = validate(value);
6
- if (isSuccess(fefeResult))
7
- return success(fefeResult.right);
8
- return failure([
9
- {
10
- type: 'validation-error',
11
- message: getErrorString(fefeResult.left),
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
+ }
@@ -1,13 +1,3 @@
1
1
  export function classNames(classNames) {
2
- return Object.entries(classNames)
3
- .filter(function (_a) {
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
@@ -2,5 +2,4 @@ export * from './result';
2
2
  export * as theme from './theme';
3
3
  export * from './not-undefined';
4
4
  export * from './api-result';
5
- export * from './class-names';
6
- //# sourceMappingURL=index.js.map
5
+ export * from './class-names';
@@ -1,4 +1,3 @@
1
1
  export function notUndefined(value) {
2
- return value !== undefined;
3
- }
4
- //# sourceMappingURL=not-undefined.js.map
2
+ return value !== undefined;
3
+ }
@@ -1,19 +1,24 @@
1
1
  export function success(data) {
2
- return { success: true, data: data };
2
+ return {
3
+ success: true,
4
+ data: data
5
+ };
3
6
  }
4
7
  export function failure(reason) {
5
- return { success: false, error: reason };
8
+ return {
9
+ success: false,
10
+ error: reason
11
+ };
6
12
  }
7
13
  export function asSuccess(result) {
8
- if (!result.success)
9
- return undefined;
10
- return result;
14
+ if (!result.success) return undefined;
15
+ return result;
11
16
  }
12
17
  export function asFailure(result) {
13
- if (result.success)
14
- return undefined;
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
- if (results.every(function (result) { return result.success; })) {
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
- success: false,
41
- error: results
42
- .map(function (result) { var _a; return (_a = asFailure(result)) === null || _a === void 0 ? void 0 : _a.error; })
43
- .filter(function (failure) { return failure !== undefined; }), // the typechecker does not resolve this so we just tell him its fine and hope there are no errors
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
- //# sourceMappingURL=result.js.map
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 var 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',
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 var fonts = {
16
- primary: 'PTSans, sans-serif',
17
- secondary: 'Iosevka, monospace',
18
- };
19
- //# sourceMappingURL=theme.js.map
15
+ export const fonts = {
16
+ primary: 'PTSans, sans-serif',
17
+ secondary: 'Iosevka, monospace'
18
+ };
@@ -1,5 +1,6 @@
1
- import { branchError, failure, isFailure, leafError, number, success, } from 'fefe';
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
- return function (value) {
16
- // make shure value is an js object
17
- // keep in mind lots of things in js are objects arrays, Sets…
18
- // so this does not tell us too much
19
- if (typeof value !== 'object' || value === null) {
20
- return failure(leafError(value, 'expected value to be an object'));
21
- }
22
- var validatedProperties = Object.entries(value).map(function (_a) {
23
- var key = _a[0], raw = _a[1];
24
- // make shure the key is of type string
25
- if (typeof key !== 'string') {
26
- return {
27
- key: key,
28
- result: failure(leafError([key, raw], 'expected key to be of type string')),
29
- };
30
- }
31
- // make shure the value is valid by passing it to the supplied validator
32
- return { key: key, result: validator(raw) };
33
- });
34
- // collect possible errors
35
- var errors = validatedProperties
36
- .filter(function (property) { return isFailure(property.result); })
37
- .map(function (property) {
38
- return {
39
- key: property.key,
40
- error: property.result.left,
41
- };
42
- });
43
- if (errors.length !== 0)
44
- return failure(branchError(value, errors));
45
- // flatten list of successfull results into single result
46
- return success(validatedProperties.reduce(function (a, b) {
47
- a[b.key] = b.result.right;
48
- return a;
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
- return function (value) {
54
- if (value !== constant) {
55
- return failure(leafError(value, "expect value to be ".concat(String(constant))));
56
- }
57
- return success(constant);
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
- return success('' + value);
64
+ return success('' + value);
62
65
  }
63
66
  export function parseTimestamp(value) {
64
- // js Date expects timestamp in mili seconds but we expect to parse a timestamp in seconds
65
- return success(new Date(value * 1000));
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
- if (defaultValue === void 0) { defaultValue = null; }
69
- return function (value) {
70
- if (value === null)
71
- return success(defaultValue);
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
- if (value === null || value === undefined)
77
- return success(null);
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
- return function (value) { return success(value); };
81
+ return value => success(value);
82
82
  }
83
- export var parseNoContent = apiValidator(noContent);
84
- export var positiveInteger = number({
85
- integer: true,
86
- min: 0,
87
- allowNaN: false,
88
- allowInfinity: false,
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
- var accessToken = object({
4
- accessToken: string(),
5
- expires: pipe(string()).pipe(parseDate({ iso: true })),
6
- }, { allowExcessProperties: true });
7
- export var parseAccessToken = apiValidator(accessToken);
8
- //# sourceMappingURL=access-token.js.map
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);