@flarehr/apollo-super-selection 4.46.37542 → 4.48.40560
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/lib/apollo-super-selection/apollo-super-selection.esm.js +1 -1
- package/dist/lib/apollo-super-selection/p-3f846618.entry.js +14 -0
- package/dist/lib/apollo-super-selection/p-551a0927.system.entry.js +69 -0
- package/dist/lib/apollo-super-selection/p-bdcfc026.system.js +1 -1
- package/dist/lib/cjs/sss-button_40.cjs.entry.js +1600 -1545
- package/dist/lib/collection/components/super-selection-app/api/super-selection.api.dto.js +14 -0
- package/dist/lib/collection/components/super-selection-app/api/super-selection.api.js +1 -0
- package/dist/lib/collection/components/super-selection-app/consent/consent.js +10 -1
- package/dist/lib/collection/components/super-selection-app/existing-choice/existing-choice.js +16 -3
- package/dist/lib/collection/components/super-selection-app/funds/constants.js +4 -0
- package/dist/lib/collection/components/super-selection-app/services/existing-super-choice-info.service.js +14 -2
- package/dist/lib/collection/components/super-selection-app/services/super-selection-app.service.js +4 -1
- package/dist/lib/collection/components/super-selection-app/services/super-selection.store.js +1 -1
- package/dist/lib/collection/components/super-selection-app/super-selection-app.js +7 -2
- package/dist/lib/esm/sss-button_40.entry.js +1600 -1545
- package/dist/lib/esm-es5/sss-button_40.entry.js +3 -3
- package/dist/lib/types/components/super-selection-app/api/super-selection-events.model.d.ts +3 -1
- package/dist/lib/types/components/super-selection-app/api/super-selection.api.dto.d.ts +17 -1
- package/dist/lib/types/components/super-selection-app/funds/constants.d.ts +1 -0
- package/dist/lib/types/components/super-selection-app/services/existing-super-choice-info.service.d.ts +8 -1
- package/dist/lib/types/components/super-selection-app/services/super-selection-app.service.d.ts +1 -0
- package/dist/lib/types/components/super-selection-app/services/super-selection.store.d.ts +1 -1
- package/package.json +1 -1
- package/dist/lib/apollo-super-selection/p-dbf92bab.system.entry.js +0 -69
- package/dist/lib/apollo-super-selection/p-dea3ba3b.entry.js +0 -14
|
@@ -260,7 +260,7 @@ class TapSubscriber extends Subscriber {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
const AppVersion = '4.
|
|
263
|
+
const AppVersion = '4.48.40560';
|
|
264
264
|
|
|
265
265
|
// -------------------------------------------------------------------------------------
|
|
266
266
|
// guards
|
|
@@ -963,1217 +963,372 @@ const Button = class {
|
|
|
963
963
|
}
|
|
964
964
|
};
|
|
965
965
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
return __assign$1.apply(this, arguments);
|
|
976
|
-
};
|
|
977
|
-
var __spreadArrays = (undefined && undefined.__spreadArrays) || function () {
|
|
978
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
979
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
980
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
981
|
-
r[k] = a[j];
|
|
982
|
-
return r;
|
|
983
|
-
};
|
|
984
|
-
var mix = function (one, two, mergeArrays) {
|
|
985
|
-
if (mergeArrays === void 0) { mergeArrays = false; }
|
|
986
|
-
if (!one || !two || typeof one !== "object" || typeof two !== "object")
|
|
987
|
-
return one;
|
|
988
|
-
var clone = __assign$1({}, one);
|
|
989
|
-
for (var prop in two) {
|
|
990
|
-
if (two.hasOwnProperty(prop)) {
|
|
991
|
-
if (two[prop] instanceof Array && one[prop] instanceof Array) {
|
|
992
|
-
clone[prop] = mergeArrays ? __spreadArrays(one[prop], two[prop]) : two[prop];
|
|
993
|
-
}
|
|
994
|
-
else if (typeof two[prop] === "object" && typeof one[prop] === "object") {
|
|
995
|
-
clone[prop] = mix(one[prop], two[prop], mergeArrays);
|
|
996
|
-
}
|
|
997
|
-
else {
|
|
998
|
-
clone[prop] = two[prop];
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
return clone;
|
|
1003
|
-
};
|
|
966
|
+
function createCommonjsModule(fn, basedir, module) {
|
|
967
|
+
return module = {
|
|
968
|
+
path: basedir,
|
|
969
|
+
exports: {},
|
|
970
|
+
require: function (path, base) {
|
|
971
|
+
return commonjsRequire();
|
|
972
|
+
}
|
|
973
|
+
}, fn(module, module.exports), module.exports;
|
|
974
|
+
}
|
|
1004
975
|
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
1009
|
-
r[k] = a[j];
|
|
1010
|
-
return r;
|
|
1011
|
-
};
|
|
1012
|
-
var config = {
|
|
1013
|
-
// Default options
|
|
1014
|
-
defaults: {},
|
|
1015
|
-
// Error type
|
|
1016
|
-
errorType: null,
|
|
1017
|
-
// Polyfills
|
|
1018
|
-
polyfills: {
|
|
1019
|
-
fetch: null,
|
|
1020
|
-
FormData: null,
|
|
1021
|
-
URLSearchParams: null,
|
|
1022
|
-
performance: null,
|
|
1023
|
-
PerformanceObserver: null,
|
|
1024
|
-
AbortController: null
|
|
1025
|
-
},
|
|
1026
|
-
polyfill: function (p, _a) {
|
|
1027
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.doThrow, doThrow = _c === void 0 ? true : _c, _d = _b.instance, instance = _d === void 0 ? false : _d;
|
|
1028
|
-
var args = [];
|
|
1029
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1030
|
-
args[_i - 2] = arguments[_i];
|
|
1031
|
-
}
|
|
1032
|
-
var res = this.polyfills[p] ||
|
|
1033
|
-
(typeof self !== "undefined" ? self[p] : null) ||
|
|
1034
|
-
(typeof global !== "undefined" ? global[p] : null);
|
|
1035
|
-
if (doThrow && !res)
|
|
1036
|
-
throw new Error(p + " is not defined");
|
|
1037
|
-
return instance && res ? new (res.bind.apply(res, __spreadArrays$1([void 0], args)))() : res;
|
|
1038
|
-
}
|
|
1039
|
-
};
|
|
976
|
+
function commonjsRequire () {
|
|
977
|
+
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
978
|
+
}
|
|
1040
979
|
|
|
1041
|
-
var
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
980
|
+
var _function = createCommonjsModule(function (module, exports) {
|
|
981
|
+
/**
|
|
982
|
+
* @since 2.0.0
|
|
983
|
+
*/
|
|
984
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
985
|
+
exports.bindTo_ = exports.bind_ = exports.hole = exports.pipe = exports.untupled = exports.tupled = exports.absurd = exports.decrement = exports.increment = exports.tuple = exports.flow = exports.flip = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.not = exports.unsafeCoerce = exports.identity = void 0;
|
|
986
|
+
/**
|
|
987
|
+
* @since 2.0.0
|
|
988
|
+
*/
|
|
989
|
+
function identity(a) {
|
|
990
|
+
return a;
|
|
991
|
+
}
|
|
992
|
+
exports.identity = identity;
|
|
993
|
+
/**
|
|
994
|
+
* @since 2.0.0
|
|
995
|
+
*/
|
|
996
|
+
exports.unsafeCoerce = identity;
|
|
997
|
+
/**
|
|
998
|
+
* @since 2.0.0
|
|
999
|
+
*/
|
|
1000
|
+
function not(predicate) {
|
|
1001
|
+
return function (a) { return !predicate(a); };
|
|
1002
|
+
}
|
|
1003
|
+
exports.not = not;
|
|
1004
|
+
/**
|
|
1005
|
+
* @since 2.0.0
|
|
1006
|
+
*/
|
|
1007
|
+
function constant(a) {
|
|
1008
|
+
return function () { return a; };
|
|
1009
|
+
}
|
|
1010
|
+
exports.constant = constant;
|
|
1011
|
+
/**
|
|
1012
|
+
* A thunk that returns always `true`.
|
|
1013
|
+
*
|
|
1014
|
+
* @since 2.0.0
|
|
1015
|
+
*/
|
|
1016
|
+
exports.constTrue =
|
|
1017
|
+
/*#__PURE__*/
|
|
1018
|
+
constant(true);
|
|
1019
|
+
/**
|
|
1020
|
+
* A thunk that returns always `false`.
|
|
1021
|
+
*
|
|
1022
|
+
* @since 2.0.0
|
|
1023
|
+
*/
|
|
1024
|
+
exports.constFalse =
|
|
1025
|
+
/*#__PURE__*/
|
|
1026
|
+
constant(false);
|
|
1027
|
+
/**
|
|
1028
|
+
* A thunk that returns always `null`.
|
|
1029
|
+
*
|
|
1030
|
+
* @since 2.0.0
|
|
1031
|
+
*/
|
|
1032
|
+
exports.constNull =
|
|
1033
|
+
/*#__PURE__*/
|
|
1034
|
+
constant(null);
|
|
1035
|
+
/**
|
|
1036
|
+
* A thunk that returns always `undefined`.
|
|
1037
|
+
*
|
|
1038
|
+
* @since 2.0.0
|
|
1039
|
+
*/
|
|
1040
|
+
exports.constUndefined =
|
|
1041
|
+
/*#__PURE__*/
|
|
1042
|
+
constant(undefined);
|
|
1043
|
+
/**
|
|
1044
|
+
* A thunk that returns always `void`.
|
|
1045
|
+
*
|
|
1046
|
+
* @since 2.0.0
|
|
1047
|
+
*/
|
|
1048
|
+
exports.constVoid = exports.constUndefined;
|
|
1049
|
+
// TODO: remove in v3
|
|
1050
|
+
/**
|
|
1051
|
+
* Flips the order of the arguments of a function of two arguments.
|
|
1052
|
+
*
|
|
1053
|
+
* @since 2.0.0
|
|
1054
|
+
*/
|
|
1055
|
+
function flip(f) {
|
|
1056
|
+
return function (b, a) { return f(a, b); };
|
|
1057
|
+
}
|
|
1058
|
+
exports.flip = flip;
|
|
1059
|
+
function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
|
|
1060
|
+
switch (arguments.length) {
|
|
1061
|
+
case 1:
|
|
1062
|
+
return ab;
|
|
1063
|
+
case 2:
|
|
1064
|
+
return function () {
|
|
1065
|
+
return bc(ab.apply(this, arguments));
|
|
1066
|
+
};
|
|
1067
|
+
case 3:
|
|
1068
|
+
return function () {
|
|
1069
|
+
return cd(bc(ab.apply(this, arguments)));
|
|
1070
|
+
};
|
|
1071
|
+
case 4:
|
|
1072
|
+
return function () {
|
|
1073
|
+
return de(cd(bc(ab.apply(this, arguments))));
|
|
1074
|
+
};
|
|
1075
|
+
case 5:
|
|
1076
|
+
return function () {
|
|
1077
|
+
return ef(de(cd(bc(ab.apply(this, arguments)))));
|
|
1078
|
+
};
|
|
1079
|
+
case 6:
|
|
1080
|
+
return function () {
|
|
1081
|
+
return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
|
|
1082
|
+
};
|
|
1083
|
+
case 7:
|
|
1084
|
+
return function () {
|
|
1085
|
+
return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
|
|
1086
|
+
};
|
|
1087
|
+
case 8:
|
|
1088
|
+
return function () {
|
|
1089
|
+
return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
|
|
1090
|
+
};
|
|
1091
|
+
case 9:
|
|
1092
|
+
return function () {
|
|
1093
|
+
return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
|
|
1094
|
+
};
|
|
1069
1095
|
}
|
|
1070
|
-
return
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
if (!lazyObserver(_performance, _observer))
|
|
1081
|
-
return;
|
|
1082
|
-
if (!onMatch(_performance, name, callback, _performance)) {
|
|
1083
|
-
if (perfs.callbacks.size < 1)
|
|
1084
|
-
perfs.observer.observe({ entryTypes: ["resource", "measure"] });
|
|
1085
|
-
perfs.callbacks.set(name, callback);
|
|
1086
|
-
}
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
exports.flow = flow;
|
|
1099
|
+
/**
|
|
1100
|
+
* @since 2.0.0
|
|
1101
|
+
*/
|
|
1102
|
+
function tuple() {
|
|
1103
|
+
var t = [];
|
|
1104
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1105
|
+
t[_i] = arguments[_i];
|
|
1087
1106
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1107
|
+
return t;
|
|
1108
|
+
}
|
|
1109
|
+
exports.tuple = tuple;
|
|
1110
|
+
/**
|
|
1111
|
+
* @since 2.0.0
|
|
1112
|
+
*/
|
|
1113
|
+
function increment(n) {
|
|
1114
|
+
return n + 1;
|
|
1115
|
+
}
|
|
1116
|
+
exports.increment = increment;
|
|
1117
|
+
/**
|
|
1118
|
+
* @since 2.0.0
|
|
1119
|
+
*/
|
|
1120
|
+
function decrement(n) {
|
|
1121
|
+
return n - 1;
|
|
1122
|
+
}
|
|
1123
|
+
exports.decrement = decrement;
|
|
1124
|
+
/**
|
|
1125
|
+
* @since 2.0.0
|
|
1126
|
+
*/
|
|
1127
|
+
function absurd(_) {
|
|
1128
|
+
throw new Error('Called `absurd` function which should be uncallable');
|
|
1129
|
+
}
|
|
1130
|
+
exports.absurd = absurd;
|
|
1131
|
+
/**
|
|
1132
|
+
* Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* import { tupled } from 'fp-ts/function'
|
|
1136
|
+
*
|
|
1137
|
+
* const add = tupled((x: number, y: number): number => x + y)
|
|
1138
|
+
*
|
|
1139
|
+
* assert.strictEqual(add([1, 2]), 3)
|
|
1140
|
+
*
|
|
1141
|
+
* @since 2.4.0
|
|
1142
|
+
*/
|
|
1143
|
+
function tupled(f) {
|
|
1144
|
+
return function (a) { return f.apply(void 0, a); };
|
|
1145
|
+
}
|
|
1146
|
+
exports.tupled = tupled;
|
|
1147
|
+
/**
|
|
1148
|
+
* Inverse function of `tupled`
|
|
1149
|
+
*
|
|
1150
|
+
* @since 2.4.0
|
|
1151
|
+
*/
|
|
1152
|
+
function untupled(f) {
|
|
1153
|
+
return function () {
|
|
1154
|
+
var a = [];
|
|
1155
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1156
|
+
a[_i] = arguments[_i];
|
|
1157
|
+
}
|
|
1158
|
+
return f(a);
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
exports.untupled = untupled;
|
|
1162
|
+
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr, rs, st) {
|
|
1163
|
+
switch (arguments.length) {
|
|
1164
|
+
case 1:
|
|
1165
|
+
return a;
|
|
1166
|
+
case 2:
|
|
1167
|
+
return ab(a);
|
|
1168
|
+
case 3:
|
|
1169
|
+
return bc(ab(a));
|
|
1170
|
+
case 4:
|
|
1171
|
+
return cd(bc(ab(a)));
|
|
1172
|
+
case 5:
|
|
1173
|
+
return de(cd(bc(ab(a))));
|
|
1174
|
+
case 6:
|
|
1175
|
+
return ef(de(cd(bc(ab(a)))));
|
|
1176
|
+
case 7:
|
|
1177
|
+
return fg(ef(de(cd(bc(ab(a))))));
|
|
1178
|
+
case 8:
|
|
1179
|
+
return gh(fg(ef(de(cd(bc(ab(a)))))));
|
|
1180
|
+
case 9:
|
|
1181
|
+
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
|
|
1182
|
+
case 10:
|
|
1183
|
+
return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
|
|
1184
|
+
case 11:
|
|
1185
|
+
return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
|
|
1186
|
+
case 12:
|
|
1187
|
+
return kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))));
|
|
1188
|
+
case 13:
|
|
1189
|
+
return lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))));
|
|
1190
|
+
case 14:
|
|
1191
|
+
return mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))));
|
|
1192
|
+
case 15:
|
|
1193
|
+
return no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))));
|
|
1194
|
+
case 16:
|
|
1195
|
+
return op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))));
|
|
1196
|
+
case 17:
|
|
1197
|
+
return pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))));
|
|
1198
|
+
case 18:
|
|
1199
|
+
return qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))));
|
|
1200
|
+
case 19:
|
|
1201
|
+
return rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))))));
|
|
1202
|
+
case 20:
|
|
1203
|
+
return st(rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))))));
|
|
1204
|
+
}
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
exports.pipe = pipe;
|
|
1208
|
+
/**
|
|
1209
|
+
* Type hole simulation
|
|
1210
|
+
*
|
|
1211
|
+
* @since 2.7.0
|
|
1212
|
+
*/
|
|
1213
|
+
exports.hole = absurd;
|
|
1214
|
+
/**
|
|
1215
|
+
* @internal
|
|
1216
|
+
*/
|
|
1217
|
+
var bind_ = function (a, name, b) {
|
|
1218
|
+
var _a;
|
|
1219
|
+
return Object.assign({}, a, (_a = {}, _a[name] = b, _a));
|
|
1220
|
+
};
|
|
1221
|
+
exports.bind_ = bind_;
|
|
1222
|
+
/**
|
|
1223
|
+
* @internal
|
|
1224
|
+
*/
|
|
1225
|
+
var bindTo_ = function (name) { return function (b) {
|
|
1226
|
+
var _a;
|
|
1227
|
+
return (_a = {}, _a[name] = b, _a);
|
|
1098
1228
|
}; };
|
|
1229
|
+
exports.bindTo_ = bindTo_;
|
|
1230
|
+
});
|
|
1099
1231
|
|
|
1100
|
-
var
|
|
1101
|
-
|
|
1102
|
-
|
|
1232
|
+
var Option = createCommonjsModule(function (module, exports) {
|
|
1233
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1234
|
+
exports.getApplySemigroup = exports.getOrd = exports.getEq = exports.getShow = exports.URI = exports.wilt = exports.wither = exports.sequence = exports.traverse = exports.partitionMap = exports.partition = exports.filterMap = exports.filter = exports.separate = exports.compact = exports.reduceRight = exports.foldMap = exports.reduce = exports.duplicate = exports.extend = exports.throwError = exports.zero = exports.alt = exports.altW = exports.flatten = exports.chainFirst = exports.chain = exports.of = exports.apSecond = exports.apFirst = exports.ap = exports.map = exports.chainNullableK = exports.mapNullable = exports.fromNullableK = exports.getOrElse = exports.getOrElseW = exports.toUndefined = exports.toNullable = exports.fold = exports.fromEither = exports.getRight = exports.getLeft = exports.tryCatch = exports.fromPredicate = exports.fromNullable = exports.some = exports.none = exports.isNone = exports.isSome = void 0;
|
|
1235
|
+
exports.sequenceArray = exports.traverseArray = exports.traverseArrayWithIndex = exports.apS = exports.bind = exports.bindTo = exports.Do = exports.getRefinement = exports.exists = exports.elem = exports.option = exports.MonadThrow = exports.Witherable = exports.Traversable = exports.Filterable = exports.Compactable = exports.Extend = exports.Alternative = exports.Alt = exports.Foldable = exports.Monad = exports.Applicative = exports.Functor = exports.getMonoid = exports.getLastMonoid = exports.getFirstMonoid = exports.getApplyMonoid = void 0;
|
|
1236
|
+
|
|
1237
|
+
// -------------------------------------------------------------------------------------
|
|
1238
|
+
// guards
|
|
1239
|
+
// -------------------------------------------------------------------------------------
|
|
1240
|
+
/**
|
|
1241
|
+
* Returns `true` if the option is an instance of `Some`, `false` otherwise.
|
|
1242
|
+
*
|
|
1243
|
+
* @example
|
|
1244
|
+
* import { some, none, isSome } from 'fp-ts/Option'
|
|
1245
|
+
*
|
|
1246
|
+
* assert.strictEqual(isSome(some(1)), true)
|
|
1247
|
+
* assert.strictEqual(isSome(none), false)
|
|
1248
|
+
*
|
|
1249
|
+
* @category guards
|
|
1250
|
+
* @since 2.0.0
|
|
1251
|
+
*/
|
|
1252
|
+
var isSome = function (fa) { return fa._tag === 'Some'; };
|
|
1253
|
+
exports.isSome = isSome;
|
|
1254
|
+
/**
|
|
1255
|
+
* Returns `true` if the option is `None`, `false` otherwise.
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* import { some, none, isNone } from 'fp-ts/Option'
|
|
1259
|
+
*
|
|
1260
|
+
* assert.strictEqual(isNone(some(1)), false)
|
|
1261
|
+
* assert.strictEqual(isNone(none), true)
|
|
1262
|
+
*
|
|
1263
|
+
* @category guards
|
|
1264
|
+
* @since 2.0.0
|
|
1265
|
+
*/
|
|
1266
|
+
var isNone = function (fa) { return fa._tag === 'None'; };
|
|
1267
|
+
exports.isNone = isNone;
|
|
1268
|
+
// -------------------------------------------------------------------------------------
|
|
1269
|
+
// constructors
|
|
1270
|
+
// -------------------------------------------------------------------------------------
|
|
1271
|
+
/**
|
|
1272
|
+
* `None` doesn't have a constructor, instead you can use it directly as a value. Represents a missing value.
|
|
1273
|
+
*
|
|
1274
|
+
* @category constructors
|
|
1275
|
+
* @since 2.0.0
|
|
1276
|
+
*/
|
|
1277
|
+
exports.none = { _tag: 'None' };
|
|
1278
|
+
/**
|
|
1279
|
+
* Constructs a `Some`. Represents an optional value that exists.
|
|
1280
|
+
*
|
|
1281
|
+
* @category constructors
|
|
1282
|
+
* @since 2.0.0
|
|
1283
|
+
*/
|
|
1284
|
+
var some = function (a) { return ({ _tag: 'Some', value: a }); };
|
|
1285
|
+
exports.some = some;
|
|
1286
|
+
/**
|
|
1287
|
+
* Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise
|
|
1288
|
+
* returns the value wrapped in a `Some`.
|
|
1289
|
+
*
|
|
1290
|
+
* @example
|
|
1291
|
+
* import { none, some, fromNullable } from 'fp-ts/Option'
|
|
1292
|
+
*
|
|
1293
|
+
* assert.deepStrictEqual(fromNullable(undefined), none)
|
|
1294
|
+
* assert.deepStrictEqual(fromNullable(null), none)
|
|
1295
|
+
* assert.deepStrictEqual(fromNullable(1), some(1))
|
|
1296
|
+
*
|
|
1297
|
+
* @category constructors
|
|
1298
|
+
* @since 2.0.0
|
|
1299
|
+
*/
|
|
1300
|
+
function fromNullable(a) {
|
|
1301
|
+
return a == null ? exports.none : exports.some(a);
|
|
1302
|
+
}
|
|
1303
|
+
exports.fromNullable = fromNullable;
|
|
1304
|
+
function fromPredicate(predicate) {
|
|
1305
|
+
return function (a) { return (predicate(a) ? exports.some(a) : exports.none); };
|
|
1306
|
+
}
|
|
1307
|
+
exports.fromPredicate = fromPredicate;
|
|
1308
|
+
/**
|
|
1309
|
+
* Transforms an exception into an `Option`. If `f` throws, returns `None`, otherwise returns the output wrapped in a
|
|
1310
|
+
* `Some`.
|
|
1311
|
+
*
|
|
1312
|
+
* @example
|
|
1313
|
+
* import { none, some, tryCatch } from 'fp-ts/Option'
|
|
1314
|
+
*
|
|
1315
|
+
* assert.deepStrictEqual(
|
|
1316
|
+
* tryCatch(() => {
|
|
1317
|
+
* throw new Error()
|
|
1318
|
+
* }),
|
|
1319
|
+
* none
|
|
1320
|
+
* )
|
|
1321
|
+
* assert.deepStrictEqual(tryCatch(() => 1), some(1))
|
|
1322
|
+
*
|
|
1323
|
+
* @category constructors
|
|
1324
|
+
* @since 2.0.0
|
|
1325
|
+
*/
|
|
1326
|
+
function tryCatch(f) {
|
|
1327
|
+
try {
|
|
1328
|
+
return exports.some(f());
|
|
1103
1329
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
var resolver = function (wretcher) {
|
|
1107
|
-
var url = wretcher._url, _catchers = wretcher._catchers, resolvers = wretcher._resolvers, middlewares = wretcher._middlewares, opts = wretcher._options;
|
|
1108
|
-
var catchers = new Map(_catchers);
|
|
1109
|
-
var finalOptions = mix(config.defaults, opts);
|
|
1110
|
-
var fetchController = config.polyfill("AbortController", { doThrow: false, instance: true });
|
|
1111
|
-
if (!finalOptions["signal"] && fetchController) {
|
|
1112
|
-
finalOptions["signal"] = fetchController.signal;
|
|
1113
|
-
}
|
|
1114
|
-
// Request timeout
|
|
1115
|
-
var timeout = {
|
|
1116
|
-
ref: null,
|
|
1117
|
-
clear: function () {
|
|
1118
|
-
if (timeout.ref) {
|
|
1119
|
-
clearTimeout(timeout.ref);
|
|
1120
|
-
timeout.ref = null;
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
// The generated fetch request
|
|
1125
|
-
var fetchRequest = middlewareHelper(middlewares)(config.polyfill("fetch"))(url, finalOptions);
|
|
1126
|
-
// Throws on an http error
|
|
1127
|
-
var throwingPromise = fetchRequest
|
|
1128
|
-
.catch(function (error) {
|
|
1129
|
-
throw new WretchErrorWrapper(error);
|
|
1130
|
-
})
|
|
1131
|
-
.then(function (response) {
|
|
1132
|
-
timeout.clear();
|
|
1133
|
-
if (!response.ok) {
|
|
1134
|
-
return response[config.errorType || "text"]().then(function (msg) {
|
|
1135
|
-
// Enhances the error object
|
|
1136
|
-
var err = new Error(msg);
|
|
1137
|
-
err[config.errorType || "text"] = msg;
|
|
1138
|
-
err["status"] = response.status;
|
|
1139
|
-
err["response"] = response;
|
|
1140
|
-
throw err;
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
return response;
|
|
1144
|
-
});
|
|
1145
|
-
// Wraps the Promise in order to dispatch the error to a matching catcher
|
|
1146
|
-
var catchersWrapper = function (promise) {
|
|
1147
|
-
return promise.catch(function (err) {
|
|
1148
|
-
timeout.clear();
|
|
1149
|
-
var error = err instanceof WretchErrorWrapper ? err.error : err;
|
|
1150
|
-
if (err instanceof WretchErrorWrapper && catchers.has("__fromFetch"))
|
|
1151
|
-
return catchers.get("__fromFetch")(error, wretcher);
|
|
1152
|
-
else if (catchers.has(error.status))
|
|
1153
|
-
return catchers.get(error.status)(error, wretcher);
|
|
1154
|
-
else if (catchers.has(error.name))
|
|
1155
|
-
return catchers.get(error.name)(error, wretcher);
|
|
1156
|
-
else
|
|
1157
|
-
throw error;
|
|
1158
|
-
});
|
|
1159
|
-
};
|
|
1160
|
-
var bodyParser = function (funName) { return function (cb) { return funName ?
|
|
1161
|
-
// If a callback is provided, then callback with the body result otherwise return the parsed body itself.
|
|
1162
|
-
catchersWrapper(throwingPromise.then(function (_) { return _ && _[funName](); }).then(function (_) { return cb ? cb(_) : _; })) :
|
|
1163
|
-
// No body parsing method - return the response
|
|
1164
|
-
catchersWrapper(throwingPromise.then(function (_) { return cb ? cb(_) : _; })); }; };
|
|
1165
|
-
var responseChain = {
|
|
1166
|
-
/**
|
|
1167
|
-
* Retrieves the raw result as a promise.
|
|
1168
|
-
*/
|
|
1169
|
-
res: bodyParser(null),
|
|
1170
|
-
/**
|
|
1171
|
-
* Retrieves the result as a parsed JSON object.
|
|
1172
|
-
*/
|
|
1173
|
-
json: bodyParser("json"),
|
|
1174
|
-
/**
|
|
1175
|
-
* Retrieves the result as a Blob object.
|
|
1176
|
-
*/
|
|
1177
|
-
blob: bodyParser("blob"),
|
|
1178
|
-
/**
|
|
1179
|
-
* Retrieves the result as a FormData object.
|
|
1180
|
-
*/
|
|
1181
|
-
formData: bodyParser("formData"),
|
|
1182
|
-
/**
|
|
1183
|
-
* Retrieves the result as an ArrayBuffer object.
|
|
1184
|
-
*/
|
|
1185
|
-
arrayBuffer: bodyParser("arrayBuffer"),
|
|
1186
|
-
/**
|
|
1187
|
-
* Retrieves the result as a string.
|
|
1188
|
-
*/
|
|
1189
|
-
text: bodyParser("text"),
|
|
1190
|
-
/**
|
|
1191
|
-
* Performs a callback on the API performance timings of the request.
|
|
1192
|
-
*
|
|
1193
|
-
* Warning: Still experimental on browsers and node.js
|
|
1194
|
-
*/
|
|
1195
|
-
perfs: function (cb) {
|
|
1196
|
-
fetchRequest.then(function (res) { return perfs.observe(res.url, cb); });
|
|
1197
|
-
return responseChain;
|
|
1198
|
-
},
|
|
1199
|
-
/**
|
|
1200
|
-
* Aborts the request after a fixed time.
|
|
1201
|
-
*
|
|
1202
|
-
* @param time Time in milliseconds
|
|
1203
|
-
* @param controller A custom controller
|
|
1204
|
-
*/
|
|
1205
|
-
setTimeout: function (time, controller) {
|
|
1206
|
-
if (controller === void 0) { controller = fetchController; }
|
|
1207
|
-
timeout.clear();
|
|
1208
|
-
timeout.ref = setTimeout(function () { return controller.abort(); }, time);
|
|
1209
|
-
return responseChain;
|
|
1210
|
-
},
|
|
1211
|
-
/**
|
|
1212
|
-
* Returns the automatically generated AbortController alongside the current wretch response as a pair.
|
|
1213
|
-
*/
|
|
1214
|
-
controller: function () { return [fetchController, responseChain]; },
|
|
1215
|
-
/**
|
|
1216
|
-
* Catches an http response with a specific error code or name and performs a callback.
|
|
1217
|
-
*/
|
|
1218
|
-
error: function (errorId, cb) {
|
|
1219
|
-
catchers.set(errorId, cb);
|
|
1220
|
-
return responseChain;
|
|
1221
|
-
},
|
|
1222
|
-
/**
|
|
1223
|
-
* Catches a bad request (http code 400) and performs a callback.
|
|
1224
|
-
*/
|
|
1225
|
-
badRequest: function (cb) { return responseChain.error(400, cb); },
|
|
1226
|
-
/**
|
|
1227
|
-
* Catches an unauthorized request (http code 401) and performs a callback.
|
|
1228
|
-
*/
|
|
1229
|
-
unauthorized: function (cb) { return responseChain.error(401, cb); },
|
|
1230
|
-
/**
|
|
1231
|
-
* Catches a forbidden request (http code 403) and performs a callback.
|
|
1232
|
-
*/
|
|
1233
|
-
forbidden: function (cb) { return responseChain.error(403, cb); },
|
|
1234
|
-
/**
|
|
1235
|
-
* Catches a "not found" request (http code 404) and performs a callback.
|
|
1236
|
-
*/
|
|
1237
|
-
notFound: function (cb) { return responseChain.error(404, cb); },
|
|
1238
|
-
/**
|
|
1239
|
-
* Catches a timeout (http code 408) and performs a callback.
|
|
1240
|
-
*/
|
|
1241
|
-
timeout: function (cb) { return responseChain.error(408, cb); },
|
|
1242
|
-
/**
|
|
1243
|
-
* Catches an internal server error (http code 500) and performs a callback.
|
|
1244
|
-
*/
|
|
1245
|
-
internalError: function (cb) { return responseChain.error(500, cb); },
|
|
1246
|
-
/**
|
|
1247
|
-
* Catches errors thrown when calling the fetch function and performs a callback.
|
|
1248
|
-
*/
|
|
1249
|
-
fetchError: function (cb) { return responseChain.error("__fromFetch", cb); },
|
|
1250
|
-
/**
|
|
1251
|
-
* Catches an AbortError and performs a callback.
|
|
1252
|
-
*/
|
|
1253
|
-
onAbort: function (cb) { return responseChain.error("AbortError", cb); }
|
|
1254
|
-
};
|
|
1255
|
-
return resolvers.reduce(function (chain, r) { return r(chain, wretcher); }, responseChain);
|
|
1256
|
-
};
|
|
1257
|
-
|
|
1258
|
-
var __assign$2 = (undefined && undefined.__assign) || function () {
|
|
1259
|
-
__assign$2 = Object.assign || function(t) {
|
|
1260
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1261
|
-
s = arguments[i];
|
|
1262
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1263
|
-
t[p] = s[p];
|
|
1264
|
-
}
|
|
1265
|
-
return t;
|
|
1266
|
-
};
|
|
1267
|
-
return __assign$2.apply(this, arguments);
|
|
1268
|
-
};
|
|
1269
|
-
var __spreadArrays$2 = (undefined && undefined.__spreadArrays) || function () {
|
|
1270
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
1271
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
1272
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
1273
|
-
r[k] = a[j];
|
|
1274
|
-
return r;
|
|
1275
|
-
};
|
|
1276
|
-
var JSON_MIME = "application/json";
|
|
1277
|
-
var CONTENT_TYPE_HEADER = "Content-Type";
|
|
1278
|
-
/**
|
|
1279
|
-
* The Wretcher class used to perform easy fetch requests.
|
|
1280
|
-
*
|
|
1281
|
-
* Immutability : almost every method of this class return a fresh Wretcher object.
|
|
1282
|
-
*/
|
|
1283
|
-
var Wretcher = /** @class */ (function () {
|
|
1284
|
-
function Wretcher(_url, _options, _catchers, _resolvers, _middlewares, _deferredChain) {
|
|
1285
|
-
if (_catchers === void 0) { _catchers = new Map(); }
|
|
1286
|
-
if (_resolvers === void 0) { _resolvers = []; }
|
|
1287
|
-
if (_middlewares === void 0) { _middlewares = []; }
|
|
1288
|
-
if (_deferredChain === void 0) { _deferredChain = []; }
|
|
1289
|
-
this._url = _url;
|
|
1290
|
-
this._options = _options;
|
|
1291
|
-
this._catchers = _catchers;
|
|
1292
|
-
this._resolvers = _resolvers;
|
|
1293
|
-
this._middlewares = _middlewares;
|
|
1294
|
-
this._deferredChain = _deferredChain;
|
|
1295
|
-
}
|
|
1296
|
-
Wretcher.factory = function (url, options) {
|
|
1297
|
-
if (url === void 0) { url = ""; }
|
|
1298
|
-
if (options === void 0) { options = {}; }
|
|
1299
|
-
return new Wretcher(url, options);
|
|
1300
|
-
};
|
|
1301
|
-
Wretcher.prototype.selfFactory = function (_a) {
|
|
1302
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.url, url = _c === void 0 ? this._url : _c, _d = _b.options, options = _d === void 0 ? this._options : _d, _e = _b.catchers, catchers = _e === void 0 ? this._catchers : _e, _f = _b.resolvers, resolvers = _f === void 0 ? this._resolvers : _f, _g = _b.middlewares, middlewares = _g === void 0 ? this._middlewares : _g, _h = _b.deferredChain, deferredChain = _h === void 0 ? this._deferredChain : _h;
|
|
1303
|
-
return new Wretcher(url, __assign$2({}, options), new Map(catchers), __spreadArrays$2(resolvers), __spreadArrays$2(middlewares), __spreadArrays$2(deferredChain));
|
|
1304
|
-
};
|
|
1305
|
-
/**
|
|
1306
|
-
* Sets the default fetch options used for every subsequent fetch call.
|
|
1307
|
-
* @param options New default options
|
|
1308
|
-
* @param mixin If true, mixes in instead of replacing the existing options
|
|
1309
|
-
*/
|
|
1310
|
-
Wretcher.prototype.defaults = function (options, mixin) {
|
|
1311
|
-
if (mixin === void 0) { mixin = false; }
|
|
1312
|
-
config.defaults = mixin ? mix(config.defaults, options) : options;
|
|
1313
|
-
return this;
|
|
1314
|
-
};
|
|
1315
|
-
/**
|
|
1316
|
-
* Sets the method (text, json ...) used to parse the data contained in the response body in case of an HTTP error.
|
|
1317
|
-
*
|
|
1318
|
-
* Persists for every subsequent requests.
|
|
1319
|
-
*
|
|
1320
|
-
* Default is "text".
|
|
1321
|
-
*/
|
|
1322
|
-
Wretcher.prototype.errorType = function (method) {
|
|
1323
|
-
config.errorType = method;
|
|
1324
|
-
return this;
|
|
1325
|
-
};
|
|
1326
|
-
/**
|
|
1327
|
-
* Sets the non-global polyfills which will be used for every subsequent calls.
|
|
1328
|
-
*
|
|
1329
|
-
* Needed for libraries like [fetch-ponyfill](https://github.com/qubyte/fetch-ponyfill).
|
|
1330
|
-
*
|
|
1331
|
-
* @param polyfills An object containing the polyfills.
|
|
1332
|
-
*/
|
|
1333
|
-
Wretcher.prototype.polyfills = function (polyfills) {
|
|
1334
|
-
config.polyfills = __assign$2(__assign$2({}, config.polyfills), polyfills);
|
|
1335
|
-
return this;
|
|
1336
|
-
};
|
|
1337
|
-
/**
|
|
1338
|
-
* Returns a new Wretcher object with the argument url appended and the same options.
|
|
1339
|
-
* @param url String url
|
|
1340
|
-
* @param replace Boolean If true, replaces the current url instead of appending
|
|
1341
|
-
*/
|
|
1342
|
-
Wretcher.prototype.url = function (url, replace) {
|
|
1343
|
-
if (replace === void 0) { replace = false; }
|
|
1344
|
-
if (replace)
|
|
1345
|
-
return this.selfFactory({ url: url });
|
|
1346
|
-
var split = this._url.split("?");
|
|
1347
|
-
return this.selfFactory({
|
|
1348
|
-
url: split.length > 1 ?
|
|
1349
|
-
split[0] + url + "?" + split[1] :
|
|
1350
|
-
this._url + url
|
|
1351
|
-
});
|
|
1352
|
-
};
|
|
1353
|
-
/**
|
|
1354
|
-
* Returns a new Wretcher object with the same url and new options.
|
|
1355
|
-
* @param options New options
|
|
1356
|
-
* @param mixin If true, mixes in instead of replacing the existing options
|
|
1357
|
-
*/
|
|
1358
|
-
Wretcher.prototype.options = function (options, mixin) {
|
|
1359
|
-
if (mixin === void 0) { mixin = true; }
|
|
1360
|
-
return this.selfFactory({ options: mixin ? mix(this._options, options) : options });
|
|
1361
|
-
};
|
|
1362
|
-
/**
|
|
1363
|
-
* Converts a javascript object to query parameters,
|
|
1364
|
-
* then appends this query string to the current url.
|
|
1365
|
-
*
|
|
1366
|
-
* If given a string, use the string as the query verbatim.
|
|
1367
|
-
*
|
|
1368
|
-
* ```
|
|
1369
|
-
* let w = wretch("http://example.com") // url is http://example.com
|
|
1370
|
-
*
|
|
1371
|
-
* // Chain query calls
|
|
1372
|
-
* w = w.query({ a: 1, b : 2 }) // url is now http://example.com?a=1&b=2
|
|
1373
|
-
* w = w.query("foo-bar-baz-woz") // url is now http://example.com?a=1&b=2&foo-bar-baz-woz
|
|
1374
|
-
*
|
|
1375
|
-
* // Pass true as the second argument to replace existing query parameters
|
|
1376
|
-
* w = w.query("c=3&d=4", true) // url is now http://example.com?c=3&d=4
|
|
1377
|
-
* ```
|
|
1378
|
-
*
|
|
1379
|
-
* @param qp An object which will be converted, or a string which will be used verbatim.
|
|
1380
|
-
*/
|
|
1381
|
-
Wretcher.prototype.query = function (qp, replace) {
|
|
1382
|
-
if (replace === void 0) { replace = false; }
|
|
1383
|
-
return this.selfFactory({ url: appendQueryParams(this._url, qp, replace) });
|
|
1384
|
-
};
|
|
1385
|
-
/**
|
|
1386
|
-
* Set request headers.
|
|
1387
|
-
* @param headerValues An object containing header keys and values
|
|
1388
|
-
*/
|
|
1389
|
-
Wretcher.prototype.headers = function (headerValues) {
|
|
1390
|
-
return this.selfFactory({ options: mix(this._options, { headers: headerValues || {} }) });
|
|
1391
|
-
};
|
|
1392
|
-
/**
|
|
1393
|
-
* Shortcut to set the "Accept" header.
|
|
1394
|
-
* @param headerValue Header value
|
|
1395
|
-
*/
|
|
1396
|
-
Wretcher.prototype.accept = function (headerValue) {
|
|
1397
|
-
return this.headers({ Accept: headerValue });
|
|
1398
|
-
};
|
|
1399
|
-
/**
|
|
1400
|
-
* Shortcut to set the "Content-Type" header.
|
|
1401
|
-
* @param headerValue Header value
|
|
1402
|
-
*/
|
|
1403
|
-
Wretcher.prototype.content = function (headerValue) {
|
|
1404
|
-
var _a;
|
|
1405
|
-
return this.headers((_a = {}, _a[CONTENT_TYPE_HEADER] = headerValue, _a));
|
|
1406
|
-
};
|
|
1407
|
-
/**
|
|
1408
|
-
* Shortcut to set the "Authorization" header.
|
|
1409
|
-
* @param headerValue Header value
|
|
1410
|
-
*/
|
|
1411
|
-
Wretcher.prototype.auth = function (headerValue) {
|
|
1412
|
-
return this.headers({ Authorization: headerValue });
|
|
1413
|
-
};
|
|
1414
|
-
/**
|
|
1415
|
-
* Adds a default catcher which will be called on every subsequent request error when the error code matches.
|
|
1416
|
-
* @param errorId Error code or name
|
|
1417
|
-
* @param catcher: The catcher method
|
|
1418
|
-
*/
|
|
1419
|
-
Wretcher.prototype.catcher = function (errorId, catcher) {
|
|
1420
|
-
var newMap = new Map(this._catchers);
|
|
1421
|
-
newMap.set(errorId, catcher);
|
|
1422
|
-
return this.selfFactory({ catchers: newMap });
|
|
1423
|
-
};
|
|
1424
|
-
/**
|
|
1425
|
-
* Associates a custom signal with the request.
|
|
1426
|
-
* @param controller : An AbortController
|
|
1427
|
-
*/
|
|
1428
|
-
Wretcher.prototype.signal = function (controller) {
|
|
1429
|
-
return this.selfFactory({ options: __assign$2(__assign$2({}, this._options), { signal: controller.signal }) });
|
|
1430
|
-
};
|
|
1431
|
-
/**
|
|
1432
|
-
* Program a resolver to perform response chain tasks automatically.
|
|
1433
|
-
* @param doResolve : Resolver callback
|
|
1434
|
-
*/
|
|
1435
|
-
Wretcher.prototype.resolve = function (doResolve, clear) {
|
|
1436
|
-
if (clear === void 0) { clear = false; }
|
|
1437
|
-
return this.selfFactory({ resolvers: clear ? [doResolve] : __spreadArrays$2(this._resolvers, [doResolve]) });
|
|
1438
|
-
};
|
|
1439
|
-
/**
|
|
1440
|
-
* Defer wretcher methods that will be chained and called just before the request is performed.
|
|
1441
|
-
*/
|
|
1442
|
-
Wretcher.prototype.defer = function (callback, clear) {
|
|
1443
|
-
if (clear === void 0) { clear = false; }
|
|
1444
|
-
return this.selfFactory({
|
|
1445
|
-
deferredChain: clear ? [callback] : __spreadArrays$2(this._deferredChain, [callback])
|
|
1446
|
-
});
|
|
1447
|
-
};
|
|
1448
|
-
/**
|
|
1449
|
-
* Add middlewares to intercept a request before being sent.
|
|
1450
|
-
*/
|
|
1451
|
-
Wretcher.prototype.middlewares = function (middlewares, clear) {
|
|
1452
|
-
if (clear === void 0) { clear = false; }
|
|
1453
|
-
return this.selfFactory({
|
|
1454
|
-
middlewares: clear ? middlewares : __spreadArrays$2(this._middlewares, middlewares)
|
|
1455
|
-
});
|
|
1456
|
-
};
|
|
1457
|
-
Wretcher.prototype.method = function (method, options, body) {
|
|
1458
|
-
if (options === void 0) { options = {}; }
|
|
1459
|
-
if (body === void 0) { body = null; }
|
|
1460
|
-
var headers = this._options.headers;
|
|
1461
|
-
var baseWretcher = !body ? this :
|
|
1462
|
-
typeof body === "object" && (!headers ||
|
|
1463
|
-
Object.entries(headers).every(function (_a) {
|
|
1464
|
-
var k = _a[0], v = _a[1];
|
|
1465
|
-
return k.toLowerCase() !== CONTENT_TYPE_HEADER.toLowerCase() ||
|
|
1466
|
-
v.startsWith(JSON_MIME);
|
|
1467
|
-
})) ? this.json(body) :
|
|
1468
|
-
this.body(body);
|
|
1469
|
-
baseWretcher = baseWretcher.options(__assign$2(__assign$2({}, options), { method: method }));
|
|
1470
|
-
var deferredWretcher = baseWretcher._deferredChain.reduce(function (acc, curr) { return curr(acc, acc._url, acc._options); }, baseWretcher);
|
|
1471
|
-
return resolver(deferredWretcher);
|
|
1472
|
-
};
|
|
1473
|
-
/**
|
|
1474
|
-
* Performs a get request.
|
|
1475
|
-
*/
|
|
1476
|
-
Wretcher.prototype.get = function (options) {
|
|
1477
|
-
return this.method("GET", options);
|
|
1478
|
-
};
|
|
1479
|
-
/**
|
|
1480
|
-
* Performs a delete request.
|
|
1481
|
-
*/
|
|
1482
|
-
Wretcher.prototype.delete = function (options) {
|
|
1483
|
-
return this.method("DELETE", options);
|
|
1484
|
-
};
|
|
1485
|
-
/**
|
|
1486
|
-
* Performs a put request.
|
|
1487
|
-
*/
|
|
1488
|
-
Wretcher.prototype.put = function (body, options) {
|
|
1489
|
-
return this.method("PUT", options, body);
|
|
1490
|
-
};
|
|
1491
|
-
/**
|
|
1492
|
-
* Performs a post request.
|
|
1493
|
-
*/
|
|
1494
|
-
Wretcher.prototype.post = function (body, options) {
|
|
1495
|
-
return this.method("POST", options, body);
|
|
1496
|
-
};
|
|
1497
|
-
/**
|
|
1498
|
-
* Performs a patch request.
|
|
1499
|
-
*/
|
|
1500
|
-
Wretcher.prototype.patch = function (body, options) {
|
|
1501
|
-
return this.method("PATCH", options, body);
|
|
1502
|
-
};
|
|
1503
|
-
/**
|
|
1504
|
-
* Performs a head request.
|
|
1505
|
-
*/
|
|
1506
|
-
Wretcher.prototype.head = function (options) {
|
|
1507
|
-
return this.method("HEAD", options);
|
|
1508
|
-
};
|
|
1509
|
-
/**
|
|
1510
|
-
* Performs an options request
|
|
1511
|
-
*/
|
|
1512
|
-
Wretcher.prototype.opts = function (options) {
|
|
1513
|
-
return this.method("OPTIONS", options);
|
|
1514
|
-
};
|
|
1515
|
-
/**
|
|
1516
|
-
* Replay a request.
|
|
1517
|
-
*/
|
|
1518
|
-
Wretcher.prototype.replay = function (options) {
|
|
1519
|
-
return this.method(this._options.method, options);
|
|
1520
|
-
};
|
|
1521
|
-
/**
|
|
1522
|
-
* Sets the request body with any content.
|
|
1523
|
-
* @param contents The body contents
|
|
1524
|
-
*/
|
|
1525
|
-
Wretcher.prototype.body = function (contents) {
|
|
1526
|
-
return this.selfFactory({ options: __assign$2(__assign$2({}, this._options), { body: contents }) });
|
|
1527
|
-
};
|
|
1528
|
-
/**
|
|
1529
|
-
* Sets the content type header, stringifies an object and sets the request body.
|
|
1530
|
-
* @param jsObject An object which will be serialized into a JSON
|
|
1531
|
-
*/
|
|
1532
|
-
Wretcher.prototype.json = function (jsObject) {
|
|
1533
|
-
var _a;
|
|
1534
|
-
var preservedContentType = (_a = Object.entries(this._options.headers || {}).find(function (_a) {
|
|
1535
|
-
var k = _a[0], v = _a[1];
|
|
1536
|
-
return k.toLowerCase() === CONTENT_TYPE_HEADER.toLowerCase() && v.startsWith(JSON_MIME);
|
|
1537
|
-
})) === null || _a === void 0 ? void 0 : _a[1];
|
|
1538
|
-
return this.content(preservedContentType || JSON_MIME).body(JSON.stringify(jsObject));
|
|
1539
|
-
};
|
|
1540
|
-
/**
|
|
1541
|
-
* Converts the javascript object to a FormData and sets the request body.
|
|
1542
|
-
* @param formObject An object which will be converted to a FormData
|
|
1543
|
-
* @param recursive If `true`, will recurse through all nested objects
|
|
1544
|
-
* Can be set as an array of string to exclude specific keys.
|
|
1545
|
-
* See https://github.com/elbywan/wretch/issues/68 for more details.
|
|
1546
|
-
*/
|
|
1547
|
-
Wretcher.prototype.formData = function (formObject, recursive) {
|
|
1548
|
-
if (recursive === void 0) { recursive = false; }
|
|
1549
|
-
return this.body(convertFormData(formObject, recursive));
|
|
1550
|
-
};
|
|
1551
|
-
/**
|
|
1552
|
-
* Converts the input to an url encoded string and sets the content-type header and body.
|
|
1553
|
-
* If the input argument is already a string, skips the conversion part.
|
|
1554
|
-
*
|
|
1555
|
-
* @param input An object to convert into an url encoded string or an already encoded string
|
|
1556
|
-
*/
|
|
1557
|
-
Wretcher.prototype.formUrl = function (input) {
|
|
1558
|
-
return this
|
|
1559
|
-
.body(typeof input === "string" ? input : convertFormUrl(input))
|
|
1560
|
-
.content("application/x-www-form-urlencoded");
|
|
1561
|
-
};
|
|
1562
|
-
return Wretcher;
|
|
1563
|
-
}());
|
|
1564
|
-
// Internal helpers
|
|
1565
|
-
var appendQueryParams = function (url, qp, replace) {
|
|
1566
|
-
var queryString;
|
|
1567
|
-
if (typeof qp === "string") {
|
|
1568
|
-
queryString = qp;
|
|
1569
|
-
}
|
|
1570
|
-
else {
|
|
1571
|
-
var usp = config.polyfill("URLSearchParams", { instance: true });
|
|
1572
|
-
for (var key in qp) {
|
|
1573
|
-
if (qp[key] instanceof Array) {
|
|
1574
|
-
for (var _i = 0, _a = qp[key]; _i < _a.length; _i++) {
|
|
1575
|
-
var val = _a[_i];
|
|
1576
|
-
usp.append(key, val);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
else {
|
|
1580
|
-
usp.append(key, qp[key]);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
queryString = usp.toString();
|
|
1584
|
-
}
|
|
1585
|
-
var split = url.split("?");
|
|
1586
|
-
if (replace || split.length < 2)
|
|
1587
|
-
return split[0] + "?" + queryString;
|
|
1588
|
-
return url + "&" + queryString;
|
|
1589
|
-
};
|
|
1590
|
-
function convertFormData(formObject, recursive, formData, ancestors) {
|
|
1591
|
-
if (recursive === void 0) { recursive = false; }
|
|
1592
|
-
if (formData === void 0) { formData = config.polyfill("FormData", { instance: true }); }
|
|
1593
|
-
if (ancestors === void 0) { ancestors = []; }
|
|
1594
|
-
Object.entries(formObject).forEach(function (_a) {
|
|
1595
|
-
var key = _a[0], value = _a[1];
|
|
1596
|
-
var formKey = ancestors.reduce(function (acc, ancestor) { return (acc ? acc + "[" + ancestor + "]" : ancestor); }, null);
|
|
1597
|
-
formKey = formKey ? formKey + "[" + key + "]" : key;
|
|
1598
|
-
if (value instanceof Array) {
|
|
1599
|
-
for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
|
|
1600
|
-
var item = value_1[_i];
|
|
1601
|
-
formData.append(formKey + "[]", item);
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
else if (recursive &&
|
|
1605
|
-
typeof value === "object" &&
|
|
1606
|
-
(!(recursive instanceof Array) ||
|
|
1607
|
-
!recursive.includes(key))) {
|
|
1608
|
-
if (value !== null) {
|
|
1609
|
-
convertFormData(value, recursive, formData, __spreadArrays$2(ancestors, [key]));
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
else {
|
|
1613
|
-
formData.append(formKey, value);
|
|
1614
|
-
}
|
|
1615
|
-
});
|
|
1616
|
-
return formData;
|
|
1617
|
-
}
|
|
1618
|
-
function encodeQueryValue(key, value) {
|
|
1619
|
-
return encodeURIComponent(key) +
|
|
1620
|
-
"=" +
|
|
1621
|
-
encodeURIComponent(typeof value === "object" ?
|
|
1622
|
-
JSON.stringify(value) :
|
|
1623
|
-
"" + value);
|
|
1624
|
-
}
|
|
1625
|
-
function convertFormUrl(formObject) {
|
|
1626
|
-
return Object.keys(formObject)
|
|
1627
|
-
.map(function (key) {
|
|
1628
|
-
var value = formObject[key];
|
|
1629
|
-
if (value instanceof Array) {
|
|
1630
|
-
return value.map(function (v) { return encodeQueryValue(key, v); }).join("&");
|
|
1631
|
-
}
|
|
1632
|
-
return encodeQueryValue(key, value);
|
|
1633
|
-
})
|
|
1634
|
-
.join("&");
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
var factory = Wretcher.factory;
|
|
1638
|
-
factory["default"] = Wretcher.factory;
|
|
1639
|
-
|
|
1640
|
-
const appendToMap = (map, propName, value) => {
|
|
1641
|
-
const items = map.get(propName);
|
|
1642
|
-
if (!items) {
|
|
1643
|
-
map.set(propName, [value]);
|
|
1644
|
-
}
|
|
1645
|
-
else if (!items.includes(value)) {
|
|
1646
|
-
items.push(value);
|
|
1647
|
-
}
|
|
1648
|
-
};
|
|
1649
|
-
const debounce = (fn, ms) => {
|
|
1650
|
-
let timeoutId;
|
|
1651
|
-
return (...args) => {
|
|
1652
|
-
if (timeoutId) {
|
|
1653
|
-
clearTimeout(timeoutId);
|
|
1654
|
-
}
|
|
1655
|
-
timeoutId = setTimeout(() => {
|
|
1656
|
-
timeoutId = 0;
|
|
1657
|
-
fn(...args);
|
|
1658
|
-
}, ms);
|
|
1659
|
-
};
|
|
1660
|
-
};
|
|
1661
|
-
|
|
1662
|
-
/**
|
|
1663
|
-
* Check if a possible element isConnected.
|
|
1664
|
-
* The property might not be there, so we check for it.
|
|
1665
|
-
*
|
|
1666
|
-
* We want it to return true if isConnected is not a property,
|
|
1667
|
-
* otherwise we would remove these elements and would not update.
|
|
1668
|
-
*
|
|
1669
|
-
* Better leak in Edge than to be useless.
|
|
1670
|
-
*/
|
|
1671
|
-
const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
|
|
1672
|
-
const cleanupElements = debounce((map) => {
|
|
1673
|
-
for (let key of map.keys()) {
|
|
1674
|
-
map.set(key, map.get(key).filter(isConnected));
|
|
1675
|
-
}
|
|
1676
|
-
}, 2000);
|
|
1677
|
-
const stencilSubscription = ({ on }) => {
|
|
1678
|
-
const elmsToUpdate = new Map();
|
|
1679
|
-
if (typeof getRenderingRef === 'function') {
|
|
1680
|
-
// If we are not in a stencil project, we do nothing.
|
|
1681
|
-
// This function is not really exported by @stencil/core.
|
|
1682
|
-
on('dispose', () => {
|
|
1683
|
-
elmsToUpdate.clear();
|
|
1684
|
-
});
|
|
1685
|
-
on('get', (propName) => {
|
|
1686
|
-
const elm = getRenderingRef();
|
|
1687
|
-
if (elm) {
|
|
1688
|
-
appendToMap(elmsToUpdate, propName, elm);
|
|
1689
|
-
}
|
|
1690
|
-
});
|
|
1691
|
-
on('set', (propName) => {
|
|
1692
|
-
const elements = elmsToUpdate.get(propName);
|
|
1693
|
-
if (elements) {
|
|
1694
|
-
elmsToUpdate.set(propName, elements.filter(forceUpdate));
|
|
1695
|
-
}
|
|
1696
|
-
cleanupElements(elmsToUpdate);
|
|
1697
|
-
});
|
|
1698
|
-
on('reset', () => {
|
|
1699
|
-
elmsToUpdate.forEach((elms) => elms.forEach(forceUpdate));
|
|
1700
|
-
cleanupElements(elmsToUpdate);
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
|
|
1705
|
-
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
1706
|
-
let states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));
|
|
1707
|
-
const handlers = {
|
|
1708
|
-
dispose: [],
|
|
1709
|
-
get: [],
|
|
1710
|
-
set: [],
|
|
1711
|
-
reset: [],
|
|
1712
|
-
};
|
|
1713
|
-
const reset = () => {
|
|
1714
|
-
states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));
|
|
1715
|
-
handlers.reset.forEach((cb) => cb());
|
|
1716
|
-
};
|
|
1717
|
-
const dispose = () => {
|
|
1718
|
-
// Call first dispose as resetting the state would
|
|
1719
|
-
// cause less updates ;)
|
|
1720
|
-
handlers.dispose.forEach((cb) => cb());
|
|
1721
|
-
reset();
|
|
1722
|
-
};
|
|
1723
|
-
const get = (propName) => {
|
|
1724
|
-
handlers.get.forEach((cb) => cb(propName));
|
|
1725
|
-
return states.get(propName);
|
|
1726
|
-
};
|
|
1727
|
-
const set = (propName, value) => {
|
|
1728
|
-
const oldValue = states.get(propName);
|
|
1729
|
-
if (shouldUpdate(value, oldValue, propName)) {
|
|
1730
|
-
states.set(propName, value);
|
|
1731
|
-
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
1732
|
-
}
|
|
1733
|
-
};
|
|
1734
|
-
const state = (typeof Proxy === 'undefined'
|
|
1735
|
-
? {}
|
|
1736
|
-
: new Proxy(defaultState, {
|
|
1737
|
-
get(_, propName) {
|
|
1738
|
-
return get(propName);
|
|
1739
|
-
},
|
|
1740
|
-
ownKeys(_) {
|
|
1741
|
-
return Array.from(states.keys());
|
|
1742
|
-
},
|
|
1743
|
-
getOwnPropertyDescriptor() {
|
|
1744
|
-
return {
|
|
1745
|
-
enumerable: true,
|
|
1746
|
-
configurable: true,
|
|
1747
|
-
};
|
|
1748
|
-
},
|
|
1749
|
-
has(_, propName) {
|
|
1750
|
-
return states.has(propName);
|
|
1751
|
-
},
|
|
1752
|
-
set(_, propName, value) {
|
|
1753
|
-
set(propName, value);
|
|
1754
|
-
return true;
|
|
1755
|
-
},
|
|
1756
|
-
}));
|
|
1757
|
-
const on = (eventName, callback) => {
|
|
1758
|
-
handlers[eventName].push(callback);
|
|
1759
|
-
return () => {
|
|
1760
|
-
removeFromArray(handlers[eventName], callback);
|
|
1761
|
-
};
|
|
1762
|
-
};
|
|
1763
|
-
const onChange = (propName, cb) => {
|
|
1764
|
-
const unSet = on('set', (key, newValue) => {
|
|
1765
|
-
if (key === propName) {
|
|
1766
|
-
cb(newValue);
|
|
1767
|
-
}
|
|
1768
|
-
});
|
|
1769
|
-
const unReset = on('reset', () => cb(defaultState[propName]));
|
|
1770
|
-
return () => {
|
|
1771
|
-
unSet();
|
|
1772
|
-
unReset();
|
|
1773
|
-
};
|
|
1774
|
-
};
|
|
1775
|
-
const use = (...subscriptions) => subscriptions.forEach((subscription) => {
|
|
1776
|
-
if (subscription.set) {
|
|
1777
|
-
on('set', subscription.set);
|
|
1778
|
-
}
|
|
1779
|
-
if (subscription.get) {
|
|
1780
|
-
on('get', subscription.get);
|
|
1781
|
-
}
|
|
1782
|
-
if (subscription.reset) {
|
|
1783
|
-
on('reset', subscription.reset);
|
|
1784
|
-
}
|
|
1785
|
-
});
|
|
1786
|
-
return {
|
|
1787
|
-
state,
|
|
1788
|
-
get,
|
|
1789
|
-
set,
|
|
1790
|
-
on,
|
|
1791
|
-
onChange,
|
|
1792
|
-
use,
|
|
1793
|
-
dispose,
|
|
1794
|
-
reset,
|
|
1795
|
-
};
|
|
1796
|
-
};
|
|
1797
|
-
const removeFromArray = (array, item) => {
|
|
1798
|
-
const index = array.indexOf(item);
|
|
1799
|
-
if (index >= 0) {
|
|
1800
|
-
array[index] = array[array.length - 1];
|
|
1801
|
-
array.length--;
|
|
1802
|
-
}
|
|
1803
|
-
};
|
|
1804
|
-
|
|
1805
|
-
const createStore = (defaultState, shouldUpdate) => {
|
|
1806
|
-
const map = createObservableMap(defaultState, shouldUpdate);
|
|
1807
|
-
stencilSubscription(map);
|
|
1808
|
-
return map;
|
|
1809
|
-
};
|
|
1810
|
-
|
|
1811
|
-
function createCommonjsModule(fn, basedir, module) {
|
|
1812
|
-
return module = {
|
|
1813
|
-
path: basedir,
|
|
1814
|
-
exports: {},
|
|
1815
|
-
require: function (path, base) {
|
|
1816
|
-
return commonjsRequire();
|
|
1817
|
-
}
|
|
1818
|
-
}, fn(module, module.exports), module.exports;
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
function commonjsRequire () {
|
|
1822
|
-
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
var _function = createCommonjsModule(function (module, exports) {
|
|
1826
|
-
/**
|
|
1827
|
-
* @since 2.0.0
|
|
1828
|
-
*/
|
|
1829
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1830
|
-
exports.bindTo_ = exports.bind_ = exports.hole = exports.pipe = exports.untupled = exports.tupled = exports.absurd = exports.decrement = exports.increment = exports.tuple = exports.flow = exports.flip = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.not = exports.unsafeCoerce = exports.identity = void 0;
|
|
1831
|
-
/**
|
|
1832
|
-
* @since 2.0.0
|
|
1833
|
-
*/
|
|
1834
|
-
function identity(a) {
|
|
1835
|
-
return a;
|
|
1836
|
-
}
|
|
1837
|
-
exports.identity = identity;
|
|
1838
|
-
/**
|
|
1839
|
-
* @since 2.0.0
|
|
1840
|
-
*/
|
|
1841
|
-
exports.unsafeCoerce = identity;
|
|
1842
|
-
/**
|
|
1843
|
-
* @since 2.0.0
|
|
1844
|
-
*/
|
|
1845
|
-
function not(predicate) {
|
|
1846
|
-
return function (a) { return !predicate(a); };
|
|
1847
|
-
}
|
|
1848
|
-
exports.not = not;
|
|
1849
|
-
/**
|
|
1850
|
-
* @since 2.0.0
|
|
1851
|
-
*/
|
|
1852
|
-
function constant(a) {
|
|
1853
|
-
return function () { return a; };
|
|
1854
|
-
}
|
|
1855
|
-
exports.constant = constant;
|
|
1856
|
-
/**
|
|
1857
|
-
* A thunk that returns always `true`.
|
|
1858
|
-
*
|
|
1859
|
-
* @since 2.0.0
|
|
1860
|
-
*/
|
|
1861
|
-
exports.constTrue =
|
|
1862
|
-
/*#__PURE__*/
|
|
1863
|
-
constant(true);
|
|
1864
|
-
/**
|
|
1865
|
-
* A thunk that returns always `false`.
|
|
1866
|
-
*
|
|
1867
|
-
* @since 2.0.0
|
|
1868
|
-
*/
|
|
1869
|
-
exports.constFalse =
|
|
1870
|
-
/*#__PURE__*/
|
|
1871
|
-
constant(false);
|
|
1872
|
-
/**
|
|
1873
|
-
* A thunk that returns always `null`.
|
|
1874
|
-
*
|
|
1875
|
-
* @since 2.0.0
|
|
1876
|
-
*/
|
|
1877
|
-
exports.constNull =
|
|
1878
|
-
/*#__PURE__*/
|
|
1879
|
-
constant(null);
|
|
1880
|
-
/**
|
|
1881
|
-
* A thunk that returns always `undefined`.
|
|
1882
|
-
*
|
|
1883
|
-
* @since 2.0.0
|
|
1884
|
-
*/
|
|
1885
|
-
exports.constUndefined =
|
|
1886
|
-
/*#__PURE__*/
|
|
1887
|
-
constant(undefined);
|
|
1888
|
-
/**
|
|
1889
|
-
* A thunk that returns always `void`.
|
|
1890
|
-
*
|
|
1891
|
-
* @since 2.0.0
|
|
1892
|
-
*/
|
|
1893
|
-
exports.constVoid = exports.constUndefined;
|
|
1894
|
-
// TODO: remove in v3
|
|
1895
|
-
/**
|
|
1896
|
-
* Flips the order of the arguments of a function of two arguments.
|
|
1897
|
-
*
|
|
1898
|
-
* @since 2.0.0
|
|
1899
|
-
*/
|
|
1900
|
-
function flip(f) {
|
|
1901
|
-
return function (b, a) { return f(a, b); };
|
|
1902
|
-
}
|
|
1903
|
-
exports.flip = flip;
|
|
1904
|
-
function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
|
|
1905
|
-
switch (arguments.length) {
|
|
1906
|
-
case 1:
|
|
1907
|
-
return ab;
|
|
1908
|
-
case 2:
|
|
1909
|
-
return function () {
|
|
1910
|
-
return bc(ab.apply(this, arguments));
|
|
1911
|
-
};
|
|
1912
|
-
case 3:
|
|
1913
|
-
return function () {
|
|
1914
|
-
return cd(bc(ab.apply(this, arguments)));
|
|
1915
|
-
};
|
|
1916
|
-
case 4:
|
|
1917
|
-
return function () {
|
|
1918
|
-
return de(cd(bc(ab.apply(this, arguments))));
|
|
1919
|
-
};
|
|
1920
|
-
case 5:
|
|
1921
|
-
return function () {
|
|
1922
|
-
return ef(de(cd(bc(ab.apply(this, arguments)))));
|
|
1923
|
-
};
|
|
1924
|
-
case 6:
|
|
1925
|
-
return function () {
|
|
1926
|
-
return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
|
|
1927
|
-
};
|
|
1928
|
-
case 7:
|
|
1929
|
-
return function () {
|
|
1930
|
-
return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
|
|
1931
|
-
};
|
|
1932
|
-
case 8:
|
|
1933
|
-
return function () {
|
|
1934
|
-
return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
|
|
1935
|
-
};
|
|
1936
|
-
case 9:
|
|
1937
|
-
return function () {
|
|
1938
|
-
return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
return;
|
|
1942
|
-
}
|
|
1943
|
-
exports.flow = flow;
|
|
1944
|
-
/**
|
|
1945
|
-
* @since 2.0.0
|
|
1946
|
-
*/
|
|
1947
|
-
function tuple() {
|
|
1948
|
-
var t = [];
|
|
1949
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1950
|
-
t[_i] = arguments[_i];
|
|
1951
|
-
}
|
|
1952
|
-
return t;
|
|
1953
|
-
}
|
|
1954
|
-
exports.tuple = tuple;
|
|
1955
|
-
/**
|
|
1956
|
-
* @since 2.0.0
|
|
1957
|
-
*/
|
|
1958
|
-
function increment(n) {
|
|
1959
|
-
return n + 1;
|
|
1960
|
-
}
|
|
1961
|
-
exports.increment = increment;
|
|
1962
|
-
/**
|
|
1963
|
-
* @since 2.0.0
|
|
1964
|
-
*/
|
|
1965
|
-
function decrement(n) {
|
|
1966
|
-
return n - 1;
|
|
1967
|
-
}
|
|
1968
|
-
exports.decrement = decrement;
|
|
1969
|
-
/**
|
|
1970
|
-
* @since 2.0.0
|
|
1971
|
-
*/
|
|
1972
|
-
function absurd(_) {
|
|
1973
|
-
throw new Error('Called `absurd` function which should be uncallable');
|
|
1974
|
-
}
|
|
1975
|
-
exports.absurd = absurd;
|
|
1976
|
-
/**
|
|
1977
|
-
* Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.
|
|
1978
|
-
*
|
|
1979
|
-
* @example
|
|
1980
|
-
* import { tupled } from 'fp-ts/function'
|
|
1981
|
-
*
|
|
1982
|
-
* const add = tupled((x: number, y: number): number => x + y)
|
|
1983
|
-
*
|
|
1984
|
-
* assert.strictEqual(add([1, 2]), 3)
|
|
1985
|
-
*
|
|
1986
|
-
* @since 2.4.0
|
|
1987
|
-
*/
|
|
1988
|
-
function tupled(f) {
|
|
1989
|
-
return function (a) { return f.apply(void 0, a); };
|
|
1990
|
-
}
|
|
1991
|
-
exports.tupled = tupled;
|
|
1992
|
-
/**
|
|
1993
|
-
* Inverse function of `tupled`
|
|
1994
|
-
*
|
|
1995
|
-
* @since 2.4.0
|
|
1996
|
-
*/
|
|
1997
|
-
function untupled(f) {
|
|
1998
|
-
return function () {
|
|
1999
|
-
var a = [];
|
|
2000
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2001
|
-
a[_i] = arguments[_i];
|
|
2002
|
-
}
|
|
2003
|
-
return f(a);
|
|
2004
|
-
};
|
|
2005
|
-
}
|
|
2006
|
-
exports.untupled = untupled;
|
|
2007
|
-
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr, rs, st) {
|
|
2008
|
-
switch (arguments.length) {
|
|
2009
|
-
case 1:
|
|
2010
|
-
return a;
|
|
2011
|
-
case 2:
|
|
2012
|
-
return ab(a);
|
|
2013
|
-
case 3:
|
|
2014
|
-
return bc(ab(a));
|
|
2015
|
-
case 4:
|
|
2016
|
-
return cd(bc(ab(a)));
|
|
2017
|
-
case 5:
|
|
2018
|
-
return de(cd(bc(ab(a))));
|
|
2019
|
-
case 6:
|
|
2020
|
-
return ef(de(cd(bc(ab(a)))));
|
|
2021
|
-
case 7:
|
|
2022
|
-
return fg(ef(de(cd(bc(ab(a))))));
|
|
2023
|
-
case 8:
|
|
2024
|
-
return gh(fg(ef(de(cd(bc(ab(a)))))));
|
|
2025
|
-
case 9:
|
|
2026
|
-
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
|
|
2027
|
-
case 10:
|
|
2028
|
-
return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
|
|
2029
|
-
case 11:
|
|
2030
|
-
return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
|
|
2031
|
-
case 12:
|
|
2032
|
-
return kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))));
|
|
2033
|
-
case 13:
|
|
2034
|
-
return lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))));
|
|
2035
|
-
case 14:
|
|
2036
|
-
return mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))));
|
|
2037
|
-
case 15:
|
|
2038
|
-
return no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))));
|
|
2039
|
-
case 16:
|
|
2040
|
-
return op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))));
|
|
2041
|
-
case 17:
|
|
2042
|
-
return pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))));
|
|
2043
|
-
case 18:
|
|
2044
|
-
return qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))));
|
|
2045
|
-
case 19:
|
|
2046
|
-
return rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))))));
|
|
2047
|
-
case 20:
|
|
2048
|
-
return st(rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))))));
|
|
2049
|
-
}
|
|
2050
|
-
return;
|
|
2051
|
-
}
|
|
2052
|
-
exports.pipe = pipe;
|
|
2053
|
-
/**
|
|
2054
|
-
* Type hole simulation
|
|
2055
|
-
*
|
|
2056
|
-
* @since 2.7.0
|
|
2057
|
-
*/
|
|
2058
|
-
exports.hole = absurd;
|
|
2059
|
-
/**
|
|
2060
|
-
* @internal
|
|
2061
|
-
*/
|
|
2062
|
-
var bind_ = function (a, name, b) {
|
|
2063
|
-
var _a;
|
|
2064
|
-
return Object.assign({}, a, (_a = {}, _a[name] = b, _a));
|
|
2065
|
-
};
|
|
2066
|
-
exports.bind_ = bind_;
|
|
2067
|
-
/**
|
|
2068
|
-
* @internal
|
|
2069
|
-
*/
|
|
2070
|
-
var bindTo_ = function (name) { return function (b) {
|
|
2071
|
-
var _a;
|
|
2072
|
-
return (_a = {}, _a[name] = b, _a);
|
|
2073
|
-
}; };
|
|
2074
|
-
exports.bindTo_ = bindTo_;
|
|
2075
|
-
});
|
|
2076
|
-
|
|
2077
|
-
var Option = createCommonjsModule(function (module, exports) {
|
|
2078
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2079
|
-
exports.getApplySemigroup = exports.getOrd = exports.getEq = exports.getShow = exports.URI = exports.wilt = exports.wither = exports.sequence = exports.traverse = exports.partitionMap = exports.partition = exports.filterMap = exports.filter = exports.separate = exports.compact = exports.reduceRight = exports.foldMap = exports.reduce = exports.duplicate = exports.extend = exports.throwError = exports.zero = exports.alt = exports.altW = exports.flatten = exports.chainFirst = exports.chain = exports.of = exports.apSecond = exports.apFirst = exports.ap = exports.map = exports.chainNullableK = exports.mapNullable = exports.fromNullableK = exports.getOrElse = exports.getOrElseW = exports.toUndefined = exports.toNullable = exports.fold = exports.fromEither = exports.getRight = exports.getLeft = exports.tryCatch = exports.fromPredicate = exports.fromNullable = exports.some = exports.none = exports.isNone = exports.isSome = void 0;
|
|
2080
|
-
exports.sequenceArray = exports.traverseArray = exports.traverseArrayWithIndex = exports.apS = exports.bind = exports.bindTo = exports.Do = exports.getRefinement = exports.exists = exports.elem = exports.option = exports.MonadThrow = exports.Witherable = exports.Traversable = exports.Filterable = exports.Compactable = exports.Extend = exports.Alternative = exports.Alt = exports.Foldable = exports.Monad = exports.Applicative = exports.Functor = exports.getMonoid = exports.getLastMonoid = exports.getFirstMonoid = exports.getApplyMonoid = void 0;
|
|
2081
|
-
|
|
2082
|
-
// -------------------------------------------------------------------------------------
|
|
2083
|
-
// guards
|
|
2084
|
-
// -------------------------------------------------------------------------------------
|
|
2085
|
-
/**
|
|
2086
|
-
* Returns `true` if the option is an instance of `Some`, `false` otherwise.
|
|
2087
|
-
*
|
|
2088
|
-
* @example
|
|
2089
|
-
* import { some, none, isSome } from 'fp-ts/Option'
|
|
2090
|
-
*
|
|
2091
|
-
* assert.strictEqual(isSome(some(1)), true)
|
|
2092
|
-
* assert.strictEqual(isSome(none), false)
|
|
2093
|
-
*
|
|
2094
|
-
* @category guards
|
|
2095
|
-
* @since 2.0.0
|
|
2096
|
-
*/
|
|
2097
|
-
var isSome = function (fa) { return fa._tag === 'Some'; };
|
|
2098
|
-
exports.isSome = isSome;
|
|
2099
|
-
/**
|
|
2100
|
-
* Returns `true` if the option is `None`, `false` otherwise.
|
|
2101
|
-
*
|
|
2102
|
-
* @example
|
|
2103
|
-
* import { some, none, isNone } from 'fp-ts/Option'
|
|
2104
|
-
*
|
|
2105
|
-
* assert.strictEqual(isNone(some(1)), false)
|
|
2106
|
-
* assert.strictEqual(isNone(none), true)
|
|
2107
|
-
*
|
|
2108
|
-
* @category guards
|
|
2109
|
-
* @since 2.0.0
|
|
2110
|
-
*/
|
|
2111
|
-
var isNone = function (fa) { return fa._tag === 'None'; };
|
|
2112
|
-
exports.isNone = isNone;
|
|
2113
|
-
// -------------------------------------------------------------------------------------
|
|
2114
|
-
// constructors
|
|
2115
|
-
// -------------------------------------------------------------------------------------
|
|
2116
|
-
/**
|
|
2117
|
-
* `None` doesn't have a constructor, instead you can use it directly as a value. Represents a missing value.
|
|
2118
|
-
*
|
|
2119
|
-
* @category constructors
|
|
2120
|
-
* @since 2.0.0
|
|
2121
|
-
*/
|
|
2122
|
-
exports.none = { _tag: 'None' };
|
|
2123
|
-
/**
|
|
2124
|
-
* Constructs a `Some`. Represents an optional value that exists.
|
|
2125
|
-
*
|
|
2126
|
-
* @category constructors
|
|
2127
|
-
* @since 2.0.0
|
|
2128
|
-
*/
|
|
2129
|
-
var some = function (a) { return ({ _tag: 'Some', value: a }); };
|
|
2130
|
-
exports.some = some;
|
|
2131
|
-
/**
|
|
2132
|
-
* Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise
|
|
2133
|
-
* returns the value wrapped in a `Some`.
|
|
2134
|
-
*
|
|
2135
|
-
* @example
|
|
2136
|
-
* import { none, some, fromNullable } from 'fp-ts/Option'
|
|
2137
|
-
*
|
|
2138
|
-
* assert.deepStrictEqual(fromNullable(undefined), none)
|
|
2139
|
-
* assert.deepStrictEqual(fromNullable(null), none)
|
|
2140
|
-
* assert.deepStrictEqual(fromNullable(1), some(1))
|
|
2141
|
-
*
|
|
2142
|
-
* @category constructors
|
|
2143
|
-
* @since 2.0.0
|
|
2144
|
-
*/
|
|
2145
|
-
function fromNullable(a) {
|
|
2146
|
-
return a == null ? exports.none : exports.some(a);
|
|
2147
|
-
}
|
|
2148
|
-
exports.fromNullable = fromNullable;
|
|
2149
|
-
function fromPredicate(predicate) {
|
|
2150
|
-
return function (a) { return (predicate(a) ? exports.some(a) : exports.none); };
|
|
2151
|
-
}
|
|
2152
|
-
exports.fromPredicate = fromPredicate;
|
|
2153
|
-
/**
|
|
2154
|
-
* Transforms an exception into an `Option`. If `f` throws, returns `None`, otherwise returns the output wrapped in a
|
|
2155
|
-
* `Some`.
|
|
2156
|
-
*
|
|
2157
|
-
* @example
|
|
2158
|
-
* import { none, some, tryCatch } from 'fp-ts/Option'
|
|
2159
|
-
*
|
|
2160
|
-
* assert.deepStrictEqual(
|
|
2161
|
-
* tryCatch(() => {
|
|
2162
|
-
* throw new Error()
|
|
2163
|
-
* }),
|
|
2164
|
-
* none
|
|
2165
|
-
* )
|
|
2166
|
-
* assert.deepStrictEqual(tryCatch(() => 1), some(1))
|
|
2167
|
-
*
|
|
2168
|
-
* @category constructors
|
|
2169
|
-
* @since 2.0.0
|
|
2170
|
-
*/
|
|
2171
|
-
function tryCatch(f) {
|
|
2172
|
-
try {
|
|
2173
|
-
return exports.some(f());
|
|
2174
|
-
}
|
|
2175
|
-
catch (e) {
|
|
2176
|
-
return exports.none;
|
|
1330
|
+
catch (e) {
|
|
1331
|
+
return exports.none;
|
|
2177
1332
|
}
|
|
2178
1333
|
}
|
|
2179
1334
|
exports.tryCatch = tryCatch;
|
|
@@ -2893,383 +2048,1228 @@ exports.getFirstMonoid = getFirstMonoid;
|
|
|
2893
2048
|
* assert.deepStrictEqual(M.concat(none, some(1)), some(1))
|
|
2894
2049
|
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(2))
|
|
2895
2050
|
*
|
|
2896
|
-
* @category instances
|
|
2051
|
+
* @category instances
|
|
2052
|
+
* @since 2.0.0
|
|
2053
|
+
*/
|
|
2054
|
+
function getLastMonoid() {
|
|
2055
|
+
return {
|
|
2056
|
+
concat: function (x, y) { return (exports.isNone(y) ? x : y); },
|
|
2057
|
+
empty: exports.none
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
exports.getLastMonoid = getLastMonoid;
|
|
2061
|
+
/**
|
|
2062
|
+
* Monoid returning the left-most non-`None` value. If both operands are `Some`s then the inner values are
|
|
2063
|
+
* concatenated using the provided `Semigroup`
|
|
2064
|
+
*
|
|
2065
|
+
* | x | y | concat(x, y) |
|
|
2066
|
+
* | ------- | ------- | ------------------ |
|
|
2067
|
+
* | none | none | none |
|
|
2068
|
+
* | some(a) | none | some(a) |
|
|
2069
|
+
* | none | some(a) | some(a) |
|
|
2070
|
+
* | some(a) | some(b) | some(concat(a, b)) |
|
|
2071
|
+
*
|
|
2072
|
+
* @example
|
|
2073
|
+
* import { getMonoid, some, none } from 'fp-ts/Option'
|
|
2074
|
+
* import { semigroupSum } from 'fp-ts/Semigroup'
|
|
2075
|
+
*
|
|
2076
|
+
* const M = getMonoid(semigroupSum)
|
|
2077
|
+
* assert.deepStrictEqual(M.concat(none, none), none)
|
|
2078
|
+
* assert.deepStrictEqual(M.concat(some(1), none), some(1))
|
|
2079
|
+
* assert.deepStrictEqual(M.concat(none, some(1)), some(1))
|
|
2080
|
+
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(3))
|
|
2081
|
+
*
|
|
2082
|
+
* @category instances
|
|
2083
|
+
* @since 2.0.0
|
|
2084
|
+
*/
|
|
2085
|
+
function getMonoid(S) {
|
|
2086
|
+
return {
|
|
2087
|
+
concat: function (x, y) { return (exports.isNone(x) ? y : exports.isNone(y) ? x : exports.some(S.concat(x.value, y.value))); },
|
|
2088
|
+
empty: exports.none
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
exports.getMonoid = getMonoid;
|
|
2092
|
+
/**
|
|
2093
|
+
* @category instances
|
|
2094
|
+
* @since 2.7.0
|
|
2095
|
+
*/
|
|
2096
|
+
exports.Functor = {
|
|
2097
|
+
URI: exports.URI,
|
|
2098
|
+
map: map_
|
|
2099
|
+
};
|
|
2100
|
+
/**
|
|
2101
|
+
* @category instances
|
|
2102
|
+
* @since 2.7.0
|
|
2103
|
+
*/
|
|
2104
|
+
exports.Applicative = {
|
|
2105
|
+
URI: exports.URI,
|
|
2106
|
+
map: map_,
|
|
2107
|
+
ap: ap_,
|
|
2108
|
+
of: exports.of
|
|
2109
|
+
};
|
|
2110
|
+
/**
|
|
2111
|
+
* @category instances
|
|
2112
|
+
* @since 2.7.0
|
|
2113
|
+
*/
|
|
2114
|
+
exports.Monad = {
|
|
2115
|
+
URI: exports.URI,
|
|
2116
|
+
map: map_,
|
|
2117
|
+
ap: ap_,
|
|
2118
|
+
of: exports.of,
|
|
2119
|
+
chain: chain_
|
|
2120
|
+
};
|
|
2121
|
+
/**
|
|
2122
|
+
* @category instances
|
|
2123
|
+
* @since 2.7.0
|
|
2124
|
+
*/
|
|
2125
|
+
exports.Foldable = {
|
|
2126
|
+
URI: exports.URI,
|
|
2127
|
+
reduce: reduce_,
|
|
2128
|
+
foldMap: foldMap_,
|
|
2129
|
+
reduceRight: reduceRight_
|
|
2130
|
+
};
|
|
2131
|
+
/**
|
|
2132
|
+
* @category instances
|
|
2133
|
+
* @since 2.7.0
|
|
2134
|
+
*/
|
|
2135
|
+
exports.Alt = {
|
|
2136
|
+
URI: exports.URI,
|
|
2137
|
+
map: map_,
|
|
2138
|
+
alt: alt_
|
|
2139
|
+
};
|
|
2140
|
+
/**
|
|
2141
|
+
* @category instances
|
|
2142
|
+
* @since 2.7.0
|
|
2143
|
+
*/
|
|
2144
|
+
exports.Alternative = {
|
|
2145
|
+
URI: exports.URI,
|
|
2146
|
+
map: map_,
|
|
2147
|
+
ap: ap_,
|
|
2148
|
+
of: exports.of,
|
|
2149
|
+
alt: alt_,
|
|
2150
|
+
zero: exports.zero
|
|
2151
|
+
};
|
|
2152
|
+
/**
|
|
2153
|
+
* @category instances
|
|
2154
|
+
* @since 2.7.0
|
|
2155
|
+
*/
|
|
2156
|
+
exports.Extend = {
|
|
2157
|
+
URI: exports.URI,
|
|
2158
|
+
map: map_,
|
|
2159
|
+
extend: extend_
|
|
2160
|
+
};
|
|
2161
|
+
/**
|
|
2162
|
+
* @category instances
|
|
2163
|
+
* @since 2.7.0
|
|
2164
|
+
*/
|
|
2165
|
+
exports.Compactable = {
|
|
2166
|
+
URI: exports.URI,
|
|
2167
|
+
compact: exports.compact,
|
|
2168
|
+
separate: exports.separate
|
|
2169
|
+
};
|
|
2170
|
+
/**
|
|
2171
|
+
* @category instances
|
|
2172
|
+
* @since 2.7.0
|
|
2173
|
+
*/
|
|
2174
|
+
exports.Filterable = {
|
|
2175
|
+
URI: exports.URI,
|
|
2176
|
+
map: map_,
|
|
2177
|
+
compact: exports.compact,
|
|
2178
|
+
separate: exports.separate,
|
|
2179
|
+
filter: filter_,
|
|
2180
|
+
filterMap: filterMap_,
|
|
2181
|
+
partition: partition_,
|
|
2182
|
+
partitionMap: partitionMap_
|
|
2183
|
+
};
|
|
2184
|
+
/**
|
|
2185
|
+
* @category instances
|
|
2186
|
+
* @since 2.7.0
|
|
2187
|
+
*/
|
|
2188
|
+
exports.Traversable = {
|
|
2189
|
+
URI: exports.URI,
|
|
2190
|
+
map: map_,
|
|
2191
|
+
reduce: reduce_,
|
|
2192
|
+
foldMap: foldMap_,
|
|
2193
|
+
reduceRight: reduceRight_,
|
|
2194
|
+
traverse: traverse_,
|
|
2195
|
+
sequence: exports.sequence
|
|
2196
|
+
};
|
|
2197
|
+
/**
|
|
2198
|
+
* @category instances
|
|
2199
|
+
* @since 2.7.0
|
|
2200
|
+
*/
|
|
2201
|
+
exports.Witherable = {
|
|
2202
|
+
URI: exports.URI,
|
|
2203
|
+
map: map_,
|
|
2204
|
+
reduce: reduce_,
|
|
2205
|
+
foldMap: foldMap_,
|
|
2206
|
+
reduceRight: reduceRight_,
|
|
2207
|
+
traverse: traverse_,
|
|
2208
|
+
sequence: exports.sequence,
|
|
2209
|
+
compact: exports.compact,
|
|
2210
|
+
separate: exports.separate,
|
|
2211
|
+
filter: filter_,
|
|
2212
|
+
filterMap: filterMap_,
|
|
2213
|
+
partition: partition_,
|
|
2214
|
+
partitionMap: partitionMap_,
|
|
2215
|
+
wither: wither_,
|
|
2216
|
+
wilt: wilt_
|
|
2217
|
+
};
|
|
2218
|
+
/**
|
|
2219
|
+
* @category instances
|
|
2220
|
+
* @since 2.7.0
|
|
2221
|
+
*/
|
|
2222
|
+
exports.MonadThrow = {
|
|
2223
|
+
URI: exports.URI,
|
|
2224
|
+
map: map_,
|
|
2225
|
+
ap: ap_,
|
|
2226
|
+
of: exports.of,
|
|
2227
|
+
chain: chain_,
|
|
2228
|
+
throwError: exports.throwError
|
|
2229
|
+
};
|
|
2230
|
+
// TODO: remove in v3
|
|
2231
|
+
/**
|
|
2232
|
+
* @category instances
|
|
2233
|
+
* @since 2.0.0
|
|
2234
|
+
*/
|
|
2235
|
+
exports.option = {
|
|
2236
|
+
URI: exports.URI,
|
|
2237
|
+
map: map_,
|
|
2238
|
+
of: exports.of,
|
|
2239
|
+
ap: ap_,
|
|
2240
|
+
chain: chain_,
|
|
2241
|
+
reduce: reduce_,
|
|
2242
|
+
foldMap: foldMap_,
|
|
2243
|
+
reduceRight: reduceRight_,
|
|
2244
|
+
traverse: traverse_,
|
|
2245
|
+
sequence: exports.sequence,
|
|
2246
|
+
zero: exports.zero,
|
|
2247
|
+
alt: alt_,
|
|
2248
|
+
extend: extend_,
|
|
2249
|
+
compact: exports.compact,
|
|
2250
|
+
separate: exports.separate,
|
|
2251
|
+
filter: filter_,
|
|
2252
|
+
filterMap: filterMap_,
|
|
2253
|
+
partition: partition_,
|
|
2254
|
+
partitionMap: partitionMap_,
|
|
2255
|
+
wither: wither_,
|
|
2256
|
+
wilt: wilt_,
|
|
2257
|
+
throwError: exports.throwError
|
|
2258
|
+
};
|
|
2259
|
+
// -------------------------------------------------------------------------------------
|
|
2260
|
+
// utils
|
|
2261
|
+
// -------------------------------------------------------------------------------------
|
|
2262
|
+
/**
|
|
2263
|
+
* Returns `true` if `ma` contains `a`
|
|
2264
|
+
*
|
|
2265
|
+
* @example
|
|
2266
|
+
* import { some, none, elem } from 'fp-ts/Option'
|
|
2267
|
+
* import { eqNumber } from 'fp-ts/Eq'
|
|
2268
|
+
*
|
|
2269
|
+
* assert.strictEqual(elem(eqNumber)(1, some(1)), true)
|
|
2270
|
+
* assert.strictEqual(elem(eqNumber)(2, some(1)), false)
|
|
2271
|
+
* assert.strictEqual(elem(eqNumber)(1, none), false)
|
|
2272
|
+
*
|
|
2273
|
+
* @since 2.0.0
|
|
2274
|
+
*/
|
|
2275
|
+
function elem(E) {
|
|
2276
|
+
return function (a, ma) { return (exports.isNone(ma) ? false : E.equals(a, ma.value)); };
|
|
2277
|
+
}
|
|
2278
|
+
exports.elem = elem;
|
|
2279
|
+
/**
|
|
2280
|
+
* Returns `true` if the predicate is satisfied by the wrapped value
|
|
2281
|
+
*
|
|
2282
|
+
* @example
|
|
2283
|
+
* import { some, none, exists } from 'fp-ts/Option'
|
|
2284
|
+
* import { pipe } from 'fp-ts/function'
|
|
2285
|
+
*
|
|
2286
|
+
* assert.strictEqual(
|
|
2287
|
+
* pipe(
|
|
2288
|
+
* some(1),
|
|
2289
|
+
* exists(n => n > 0)
|
|
2290
|
+
* ),
|
|
2291
|
+
* true
|
|
2292
|
+
* )
|
|
2293
|
+
* assert.strictEqual(
|
|
2294
|
+
* pipe(
|
|
2295
|
+
* some(1),
|
|
2296
|
+
* exists(n => n > 1)
|
|
2297
|
+
* ),
|
|
2298
|
+
* false
|
|
2299
|
+
* )
|
|
2300
|
+
* assert.strictEqual(
|
|
2301
|
+
* pipe(
|
|
2302
|
+
* none,
|
|
2303
|
+
* exists(n => n > 0)
|
|
2304
|
+
* ),
|
|
2305
|
+
* false
|
|
2306
|
+
* )
|
|
2307
|
+
*
|
|
2897
2308
|
* @since 2.0.0
|
|
2898
2309
|
*/
|
|
2899
|
-
function
|
|
2900
|
-
return {
|
|
2901
|
-
concat: function (x, y) { return (exports.isNone(y) ? x : y); },
|
|
2902
|
-
empty: exports.none
|
|
2903
|
-
};
|
|
2310
|
+
function exists(predicate) {
|
|
2311
|
+
return function (ma) { return (exports.isNone(ma) ? false : predicate(ma.value)); };
|
|
2904
2312
|
}
|
|
2905
|
-
exports.
|
|
2313
|
+
exports.exists = exists;
|
|
2906
2314
|
/**
|
|
2907
|
-
*
|
|
2908
|
-
*
|
|
2315
|
+
* Returns a `Refinement` (i.e. a custom type guard) from a `Option` returning function.
|
|
2316
|
+
* This function ensures that a custom type guard definition is type-safe.
|
|
2909
2317
|
*
|
|
2910
|
-
*
|
|
2911
|
-
*
|
|
2912
|
-
* | none | none | none |
|
|
2913
|
-
* | some(a) | none | some(a) |
|
|
2914
|
-
* | none | some(a) | some(a) |
|
|
2915
|
-
* | some(a) | some(b) | some(concat(a, b)) |
|
|
2318
|
+
* ```ts
|
|
2319
|
+
* import { some, none, getRefinement } from 'fp-ts/Option'
|
|
2916
2320
|
*
|
|
2917
|
-
*
|
|
2918
|
-
*
|
|
2919
|
-
*
|
|
2321
|
+
* type A = { type: 'A' }
|
|
2322
|
+
* type B = { type: 'B' }
|
|
2323
|
+
* type C = A | B
|
|
2920
2324
|
*
|
|
2921
|
-
* const
|
|
2922
|
-
*
|
|
2923
|
-
*
|
|
2924
|
-
* assert.deepStrictEqual(M.concat(none, some(1)), some(1))
|
|
2925
|
-
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(3))
|
|
2325
|
+
* const isA = (c: C): c is A => c.type === 'B' // <= typo but typescript doesn't complain
|
|
2326
|
+
* const isA = getRefinement<C, A>(c => (c.type === 'B' ? some(c) : none)) // static error: Type '"B"' is not assignable to type '"A"'
|
|
2327
|
+
* ```
|
|
2926
2328
|
*
|
|
2927
|
-
* @category instances
|
|
2928
2329
|
* @since 2.0.0
|
|
2929
2330
|
*/
|
|
2930
|
-
function
|
|
2931
|
-
return {
|
|
2932
|
-
concat: function (x, y) { return (exports.isNone(x) ? y : exports.isNone(y) ? x : exports.some(S.concat(x.value, y.value))); },
|
|
2933
|
-
empty: exports.none
|
|
2934
|
-
};
|
|
2331
|
+
function getRefinement(getOption) {
|
|
2332
|
+
return function (a) { return exports.isSome(getOption(a)); };
|
|
2935
2333
|
}
|
|
2936
|
-
exports.
|
|
2334
|
+
exports.getRefinement = getRefinement;
|
|
2335
|
+
// -------------------------------------------------------------------------------------
|
|
2336
|
+
// do notation
|
|
2337
|
+
// -------------------------------------------------------------------------------------
|
|
2937
2338
|
/**
|
|
2938
|
-
* @
|
|
2939
|
-
* @since 2.7.0
|
|
2339
|
+
* @since 2.9.0
|
|
2940
2340
|
*/
|
|
2941
|
-
exports.
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
};
|
|
2341
|
+
exports.Do =
|
|
2342
|
+
/*#__PURE__*/
|
|
2343
|
+
exports.of({});
|
|
2945
2344
|
/**
|
|
2946
|
-
* @
|
|
2947
|
-
* @since 2.7.0
|
|
2345
|
+
* @since 2.8.0
|
|
2948
2346
|
*/
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
map: map_,
|
|
2952
|
-
ap: ap_,
|
|
2953
|
-
of: exports.of
|
|
2954
|
-
};
|
|
2347
|
+
var bindTo = function (name) { return exports.map(_function.bindTo_(name)); };
|
|
2348
|
+
exports.bindTo = bindTo;
|
|
2955
2349
|
/**
|
|
2956
|
-
* @
|
|
2957
|
-
* @since 2.7.0
|
|
2350
|
+
* @since 2.8.0
|
|
2958
2351
|
*/
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
of: exports.of,
|
|
2964
|
-
chain: chain_
|
|
2352
|
+
var bind = function (name, f) {
|
|
2353
|
+
return exports.chain(function (a) {
|
|
2354
|
+
return _function.pipe(f(a), exports.map(function (b) { return _function.bind_(a, name, b); }));
|
|
2355
|
+
});
|
|
2965
2356
|
};
|
|
2357
|
+
exports.bind = bind;
|
|
2358
|
+
// -------------------------------------------------------------------------------------
|
|
2359
|
+
// pipeable sequence S
|
|
2360
|
+
// -------------------------------------------------------------------------------------
|
|
2966
2361
|
/**
|
|
2967
|
-
* @
|
|
2968
|
-
* @since 2.7.0
|
|
2362
|
+
* @since 2.8.0
|
|
2969
2363
|
*/
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
reduce: reduce_,
|
|
2973
|
-
foldMap: foldMap_,
|
|
2974
|
-
reduceRight: reduceRight_
|
|
2364
|
+
var apS = function (name, fb) {
|
|
2365
|
+
return _function.flow(exports.map(function (a) { return function (b) { return _function.bind_(a, name, b); }; }), exports.ap(fb));
|
|
2975
2366
|
};
|
|
2367
|
+
exports.apS = apS;
|
|
2368
|
+
// -------------------------------------------------------------------------------------
|
|
2369
|
+
// array utils
|
|
2370
|
+
// -------------------------------------------------------------------------------------
|
|
2976
2371
|
/**
|
|
2977
|
-
*
|
|
2978
|
-
* @since 2.
|
|
2372
|
+
*
|
|
2373
|
+
* @since 2.9.0
|
|
2979
2374
|
*/
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2375
|
+
var traverseArrayWithIndex = function (f) { return function (arr) {
|
|
2376
|
+
// tslint:disable-next-line: readonly-array
|
|
2377
|
+
var result = [];
|
|
2378
|
+
for (var i = 0; i < arr.length; i++) {
|
|
2379
|
+
var b = f(i, arr[i]);
|
|
2380
|
+
if (exports.isNone(b)) {
|
|
2381
|
+
return exports.none;
|
|
2382
|
+
}
|
|
2383
|
+
result.push(b.value);
|
|
2384
|
+
}
|
|
2385
|
+
return exports.some(result);
|
|
2386
|
+
}; };
|
|
2387
|
+
exports.traverseArrayWithIndex = traverseArrayWithIndex;
|
|
2985
2388
|
/**
|
|
2986
|
-
*
|
|
2987
|
-
*
|
|
2389
|
+
* Runs an action for every element in array and accumulates the results in option
|
|
2390
|
+
*
|
|
2391
|
+
* this function have the same behavior of `A.sequence(O.option)` but it's optimized and perform better
|
|
2392
|
+
*
|
|
2393
|
+
* @example
|
|
2394
|
+
*
|
|
2395
|
+
* import * as A from 'fp-ts/Array'
|
|
2396
|
+
* import { traverseArray, some, fromPredicate, none } from 'fp-ts/Option'
|
|
2397
|
+
* import { pipe } from 'fp-ts/function'
|
|
2398
|
+
*
|
|
2399
|
+
* const arr = A.range(0, 10)
|
|
2400
|
+
* assert.deepStrictEqual(pipe(arr, traverseArray(some)), some(arr))
|
|
2401
|
+
* assert.deepStrictEqual(pipe(arr, traverseArray(fromPredicate((x) => x > 5))), none)
|
|
2402
|
+
*
|
|
2403
|
+
* @since 2.9.0
|
|
2988
2404
|
*/
|
|
2989
|
-
exports.
|
|
2990
|
-
|
|
2991
|
-
map: map_,
|
|
2992
|
-
ap: ap_,
|
|
2993
|
-
of: exports.of,
|
|
2994
|
-
alt: alt_,
|
|
2995
|
-
zero: exports.zero
|
|
2996
|
-
};
|
|
2405
|
+
var traverseArray = function (f) { return exports.traverseArrayWithIndex(function (_, a) { return f(a); }); };
|
|
2406
|
+
exports.traverseArray = traverseArray;
|
|
2997
2407
|
/**
|
|
2998
|
-
*
|
|
2999
|
-
*
|
|
2408
|
+
* get an array of option and convert it to option of array
|
|
2409
|
+
*
|
|
2410
|
+
* this function have the same behavior of `A.sequence(O.option)` but it's optimized and perform better
|
|
2411
|
+
*
|
|
2412
|
+
* @example
|
|
2413
|
+
*
|
|
2414
|
+
* import * as A from 'fp-ts/Array'
|
|
2415
|
+
* import { sequenceArray, some, none, fromPredicate } from 'fp-ts/Option'
|
|
2416
|
+
* import { pipe } from 'fp-ts/function'
|
|
2417
|
+
*
|
|
2418
|
+
* const arr = A.range(0, 10)
|
|
2419
|
+
* assert.deepStrictEqual(pipe(arr, A.map(some), sequenceArray), some(arr))
|
|
2420
|
+
* assert.deepStrictEqual(pipe(arr, A.map(fromPredicate(x => x > 8)), sequenceArray), none)
|
|
2421
|
+
*
|
|
2422
|
+
* @since 2.9.0
|
|
3000
2423
|
*/
|
|
3001
|
-
exports.
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
2424
|
+
exports.sequenceArray =
|
|
2425
|
+
/*#__PURE__*/
|
|
2426
|
+
exports.traverseArray(_function.identity);
|
|
2427
|
+
});
|
|
2428
|
+
|
|
2429
|
+
var __assign$1 = (undefined && undefined.__assign) || function () {
|
|
2430
|
+
__assign$1 = Object.assign || function(t) {
|
|
2431
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2432
|
+
s = arguments[i];
|
|
2433
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
2434
|
+
t[p] = s[p];
|
|
2435
|
+
}
|
|
2436
|
+
return t;
|
|
2437
|
+
};
|
|
2438
|
+
return __assign$1.apply(this, arguments);
|
|
2439
|
+
};
|
|
2440
|
+
var __spreadArrays = (undefined && undefined.__spreadArrays) || function () {
|
|
2441
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
2442
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
2443
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
2444
|
+
r[k] = a[j];
|
|
2445
|
+
return r;
|
|
2446
|
+
};
|
|
2447
|
+
var mix = function (one, two, mergeArrays) {
|
|
2448
|
+
if (mergeArrays === void 0) { mergeArrays = false; }
|
|
2449
|
+
if (!one || !two || typeof one !== "object" || typeof two !== "object")
|
|
2450
|
+
return one;
|
|
2451
|
+
var clone = __assign$1({}, one);
|
|
2452
|
+
for (var prop in two) {
|
|
2453
|
+
if (two.hasOwnProperty(prop)) {
|
|
2454
|
+
if (two[prop] instanceof Array && one[prop] instanceof Array) {
|
|
2455
|
+
clone[prop] = mergeArrays ? __spreadArrays(one[prop], two[prop]) : two[prop];
|
|
2456
|
+
}
|
|
2457
|
+
else if (typeof two[prop] === "object" && typeof one[prop] === "object") {
|
|
2458
|
+
clone[prop] = mix(one[prop], two[prop], mergeArrays);
|
|
2459
|
+
}
|
|
2460
|
+
else {
|
|
2461
|
+
clone[prop] = two[prop];
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
return clone;
|
|
2466
|
+
};
|
|
2467
|
+
|
|
2468
|
+
var __spreadArrays$1 = (undefined && undefined.__spreadArrays) || function () {
|
|
2469
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
2470
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
2471
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
2472
|
+
r[k] = a[j];
|
|
2473
|
+
return r;
|
|
2474
|
+
};
|
|
2475
|
+
var config = {
|
|
2476
|
+
// Default options
|
|
2477
|
+
defaults: {},
|
|
2478
|
+
// Error type
|
|
2479
|
+
errorType: null,
|
|
2480
|
+
// Polyfills
|
|
2481
|
+
polyfills: {
|
|
2482
|
+
fetch: null,
|
|
2483
|
+
FormData: null,
|
|
2484
|
+
URLSearchParams: null,
|
|
2485
|
+
performance: null,
|
|
2486
|
+
PerformanceObserver: null,
|
|
2487
|
+
AbortController: null
|
|
2488
|
+
},
|
|
2489
|
+
polyfill: function (p, _a) {
|
|
2490
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.doThrow, doThrow = _c === void 0 ? true : _c, _d = _b.instance, instance = _d === void 0 ? false : _d;
|
|
2491
|
+
var args = [];
|
|
2492
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2493
|
+
args[_i - 2] = arguments[_i];
|
|
2494
|
+
}
|
|
2495
|
+
var res = this.polyfills[p] ||
|
|
2496
|
+
(typeof self !== "undefined" ? self[p] : null) ||
|
|
2497
|
+
(typeof global !== "undefined" ? global[p] : null);
|
|
2498
|
+
if (doThrow && !res)
|
|
2499
|
+
throw new Error(p + " is not defined");
|
|
2500
|
+
return instance && res ? new (res.bind.apply(res, __spreadArrays$1([void 0], args)))() : res;
|
|
2501
|
+
}
|
|
3005
2502
|
};
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
2503
|
+
|
|
2504
|
+
var onMatch = function (entries, name, callback, _performance) {
|
|
2505
|
+
if (!entries.getEntriesByName)
|
|
2506
|
+
return false;
|
|
2507
|
+
var matches = entries.getEntriesByName(name);
|
|
2508
|
+
if (matches && matches.length > 0) {
|
|
2509
|
+
callback(matches.reverse()[0]);
|
|
2510
|
+
if (_performance.clearMeasures)
|
|
2511
|
+
_performance.clearMeasures(name);
|
|
2512
|
+
perfs.callbacks.delete(name);
|
|
2513
|
+
if (perfs.callbacks.size < 1) {
|
|
2514
|
+
perfs.observer.disconnect();
|
|
2515
|
+
if (_performance.clearResourceTimings) {
|
|
2516
|
+
_performance.clearResourceTimings();
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
return true;
|
|
2520
|
+
}
|
|
2521
|
+
return false;
|
|
3014
2522
|
};
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
partition: partition_,
|
|
3027
|
-
partitionMap: partitionMap_
|
|
2523
|
+
var lazyObserver = function (_performance, _observer) {
|
|
2524
|
+
if (!perfs.observer && _performance && _observer) {
|
|
2525
|
+
perfs.observer = new _observer(function (entries) {
|
|
2526
|
+
perfs.callbacks.forEach(function (callback, name) {
|
|
2527
|
+
onMatch(entries, name, callback, _performance);
|
|
2528
|
+
});
|
|
2529
|
+
});
|
|
2530
|
+
if (_performance.clearResourceTimings)
|
|
2531
|
+
_performance.clearResourceTimings();
|
|
2532
|
+
}
|
|
2533
|
+
return perfs.observer;
|
|
3028
2534
|
};
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
2535
|
+
var perfs = {
|
|
2536
|
+
callbacks: new Map(),
|
|
2537
|
+
observer: null,
|
|
2538
|
+
observe: function (name, callback) {
|
|
2539
|
+
if (!name || !callback)
|
|
2540
|
+
return;
|
|
2541
|
+
var _performance = config.polyfill("performance", { doThrow: false });
|
|
2542
|
+
var _observer = config.polyfill("PerformanceObserver", { doThrow: false });
|
|
2543
|
+
if (!lazyObserver(_performance, _observer))
|
|
2544
|
+
return;
|
|
2545
|
+
if (!onMatch(_performance, name, callback, _performance)) {
|
|
2546
|
+
if (perfs.callbacks.size < 1)
|
|
2547
|
+
perfs.observer.observe({ entryTypes: ["resource", "measure"] });
|
|
2548
|
+
perfs.callbacks.set(name, callback);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
3041
2551
|
};
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
2552
|
+
|
|
2553
|
+
var middlewareHelper = function (middlewares) { return function (fetchFunction) {
|
|
2554
|
+
return (middlewares.length === 0 ?
|
|
2555
|
+
fetchFunction :
|
|
2556
|
+
middlewares.length === 1 ?
|
|
2557
|
+
middlewares[0](fetchFunction) :
|
|
2558
|
+
middlewares.reduceRight(function (acc, curr, idx) {
|
|
2559
|
+
return (idx === middlewares.length - 2) ? curr(acc(fetchFunction)) : curr(acc);
|
|
2560
|
+
}));
|
|
2561
|
+
}; };
|
|
2562
|
+
|
|
2563
|
+
var WretchErrorWrapper = /** @class */ (function () {
|
|
2564
|
+
function WretchErrorWrapper(error) {
|
|
2565
|
+
this.error = error;
|
|
2566
|
+
}
|
|
2567
|
+
return WretchErrorWrapper;
|
|
2568
|
+
}());
|
|
2569
|
+
var resolver = function (wretcher) {
|
|
2570
|
+
var url = wretcher._url, _catchers = wretcher._catchers, resolvers = wretcher._resolvers, middlewares = wretcher._middlewares, opts = wretcher._options;
|
|
2571
|
+
var catchers = new Map(_catchers);
|
|
2572
|
+
var finalOptions = mix(config.defaults, opts);
|
|
2573
|
+
var fetchController = config.polyfill("AbortController", { doThrow: false, instance: true });
|
|
2574
|
+
if (!finalOptions["signal"] && fetchController) {
|
|
2575
|
+
finalOptions["signal"] = fetchController.signal;
|
|
2576
|
+
}
|
|
2577
|
+
// Request timeout
|
|
2578
|
+
var timeout = {
|
|
2579
|
+
ref: null,
|
|
2580
|
+
clear: function () {
|
|
2581
|
+
if (timeout.ref) {
|
|
2582
|
+
clearTimeout(timeout.ref);
|
|
2583
|
+
timeout.ref = null;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
};
|
|
2587
|
+
// The generated fetch request
|
|
2588
|
+
var fetchRequest = middlewareHelper(middlewares)(config.polyfill("fetch"))(url, finalOptions);
|
|
2589
|
+
// Throws on an http error
|
|
2590
|
+
var throwingPromise = fetchRequest
|
|
2591
|
+
.catch(function (error) {
|
|
2592
|
+
throw new WretchErrorWrapper(error);
|
|
2593
|
+
})
|
|
2594
|
+
.then(function (response) {
|
|
2595
|
+
timeout.clear();
|
|
2596
|
+
if (!response.ok) {
|
|
2597
|
+
return response[config.errorType || "text"]().then(function (msg) {
|
|
2598
|
+
// Enhances the error object
|
|
2599
|
+
var err = new Error(msg);
|
|
2600
|
+
err[config.errorType || "text"] = msg;
|
|
2601
|
+
err["status"] = response.status;
|
|
2602
|
+
err["response"] = response;
|
|
2603
|
+
throw err;
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
return response;
|
|
2607
|
+
});
|
|
2608
|
+
// Wraps the Promise in order to dispatch the error to a matching catcher
|
|
2609
|
+
var catchersWrapper = function (promise) {
|
|
2610
|
+
return promise.catch(function (err) {
|
|
2611
|
+
timeout.clear();
|
|
2612
|
+
var error = err instanceof WretchErrorWrapper ? err.error : err;
|
|
2613
|
+
if (err instanceof WretchErrorWrapper && catchers.has("__fromFetch"))
|
|
2614
|
+
return catchers.get("__fromFetch")(error, wretcher);
|
|
2615
|
+
else if (catchers.has(error.status))
|
|
2616
|
+
return catchers.get(error.status)(error, wretcher);
|
|
2617
|
+
else if (catchers.has(error.name))
|
|
2618
|
+
return catchers.get(error.name)(error, wretcher);
|
|
2619
|
+
else
|
|
2620
|
+
throw error;
|
|
2621
|
+
});
|
|
2622
|
+
};
|
|
2623
|
+
var bodyParser = function (funName) { return function (cb) { return funName ?
|
|
2624
|
+
// If a callback is provided, then callback with the body result otherwise return the parsed body itself.
|
|
2625
|
+
catchersWrapper(throwingPromise.then(function (_) { return _ && _[funName](); }).then(function (_) { return cb ? cb(_) : _; })) :
|
|
2626
|
+
// No body parsing method - return the response
|
|
2627
|
+
catchersWrapper(throwingPromise.then(function (_) { return cb ? cb(_) : _; })); }; };
|
|
2628
|
+
var responseChain = {
|
|
2629
|
+
/**
|
|
2630
|
+
* Retrieves the raw result as a promise.
|
|
2631
|
+
*/
|
|
2632
|
+
res: bodyParser(null),
|
|
2633
|
+
/**
|
|
2634
|
+
* Retrieves the result as a parsed JSON object.
|
|
2635
|
+
*/
|
|
2636
|
+
json: bodyParser("json"),
|
|
2637
|
+
/**
|
|
2638
|
+
* Retrieves the result as a Blob object.
|
|
2639
|
+
*/
|
|
2640
|
+
blob: bodyParser("blob"),
|
|
2641
|
+
/**
|
|
2642
|
+
* Retrieves the result as a FormData object.
|
|
2643
|
+
*/
|
|
2644
|
+
formData: bodyParser("formData"),
|
|
2645
|
+
/**
|
|
2646
|
+
* Retrieves the result as an ArrayBuffer object.
|
|
2647
|
+
*/
|
|
2648
|
+
arrayBuffer: bodyParser("arrayBuffer"),
|
|
2649
|
+
/**
|
|
2650
|
+
* Retrieves the result as a string.
|
|
2651
|
+
*/
|
|
2652
|
+
text: bodyParser("text"),
|
|
2653
|
+
/**
|
|
2654
|
+
* Performs a callback on the API performance timings of the request.
|
|
2655
|
+
*
|
|
2656
|
+
* Warning: Still experimental on browsers and node.js
|
|
2657
|
+
*/
|
|
2658
|
+
perfs: function (cb) {
|
|
2659
|
+
fetchRequest.then(function (res) { return perfs.observe(res.url, cb); });
|
|
2660
|
+
return responseChain;
|
|
2661
|
+
},
|
|
2662
|
+
/**
|
|
2663
|
+
* Aborts the request after a fixed time.
|
|
2664
|
+
*
|
|
2665
|
+
* @param time Time in milliseconds
|
|
2666
|
+
* @param controller A custom controller
|
|
2667
|
+
*/
|
|
2668
|
+
setTimeout: function (time, controller) {
|
|
2669
|
+
if (controller === void 0) { controller = fetchController; }
|
|
2670
|
+
timeout.clear();
|
|
2671
|
+
timeout.ref = setTimeout(function () { return controller.abort(); }, time);
|
|
2672
|
+
return responseChain;
|
|
2673
|
+
},
|
|
2674
|
+
/**
|
|
2675
|
+
* Returns the automatically generated AbortController alongside the current wretch response as a pair.
|
|
2676
|
+
*/
|
|
2677
|
+
controller: function () { return [fetchController, responseChain]; },
|
|
2678
|
+
/**
|
|
2679
|
+
* Catches an http response with a specific error code or name and performs a callback.
|
|
2680
|
+
*/
|
|
2681
|
+
error: function (errorId, cb) {
|
|
2682
|
+
catchers.set(errorId, cb);
|
|
2683
|
+
return responseChain;
|
|
2684
|
+
},
|
|
2685
|
+
/**
|
|
2686
|
+
* Catches a bad request (http code 400) and performs a callback.
|
|
2687
|
+
*/
|
|
2688
|
+
badRequest: function (cb) { return responseChain.error(400, cb); },
|
|
2689
|
+
/**
|
|
2690
|
+
* Catches an unauthorized request (http code 401) and performs a callback.
|
|
2691
|
+
*/
|
|
2692
|
+
unauthorized: function (cb) { return responseChain.error(401, cb); },
|
|
2693
|
+
/**
|
|
2694
|
+
* Catches a forbidden request (http code 403) and performs a callback.
|
|
2695
|
+
*/
|
|
2696
|
+
forbidden: function (cb) { return responseChain.error(403, cb); },
|
|
2697
|
+
/**
|
|
2698
|
+
* Catches a "not found" request (http code 404) and performs a callback.
|
|
2699
|
+
*/
|
|
2700
|
+
notFound: function (cb) { return responseChain.error(404, cb); },
|
|
2701
|
+
/**
|
|
2702
|
+
* Catches a timeout (http code 408) and performs a callback.
|
|
2703
|
+
*/
|
|
2704
|
+
timeout: function (cb) { return responseChain.error(408, cb); },
|
|
2705
|
+
/**
|
|
2706
|
+
* Catches an internal server error (http code 500) and performs a callback.
|
|
2707
|
+
*/
|
|
2708
|
+
internalError: function (cb) { return responseChain.error(500, cb); },
|
|
2709
|
+
/**
|
|
2710
|
+
* Catches errors thrown when calling the fetch function and performs a callback.
|
|
2711
|
+
*/
|
|
2712
|
+
fetchError: function (cb) { return responseChain.error("__fromFetch", cb); },
|
|
2713
|
+
/**
|
|
2714
|
+
* Catches an AbortError and performs a callback.
|
|
2715
|
+
*/
|
|
2716
|
+
onAbort: function (cb) { return responseChain.error("AbortError", cb); }
|
|
2717
|
+
};
|
|
2718
|
+
return resolvers.reduce(function (chain, r) { return r(chain, wretcher); }, responseChain);
|
|
3062
2719
|
};
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
2720
|
+
|
|
2721
|
+
var __assign$2 = (undefined && undefined.__assign) || function () {
|
|
2722
|
+
__assign$2 = Object.assign || function(t) {
|
|
2723
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2724
|
+
s = arguments[i];
|
|
2725
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
2726
|
+
t[p] = s[p];
|
|
2727
|
+
}
|
|
2728
|
+
return t;
|
|
2729
|
+
};
|
|
2730
|
+
return __assign$2.apply(this, arguments);
|
|
3074
2731
|
};
|
|
3075
|
-
|
|
2732
|
+
var __spreadArrays$2 = (undefined && undefined.__spreadArrays) || function () {
|
|
2733
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
2734
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
2735
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
2736
|
+
r[k] = a[j];
|
|
2737
|
+
return r;
|
|
2738
|
+
};
|
|
2739
|
+
var JSON_MIME = "application/json";
|
|
2740
|
+
var CONTENT_TYPE_HEADER = "Content-Type";
|
|
3076
2741
|
/**
|
|
3077
|
-
*
|
|
3078
|
-
*
|
|
2742
|
+
* The Wretcher class used to perform easy fetch requests.
|
|
2743
|
+
*
|
|
2744
|
+
* Immutability : almost every method of this class return a fresh Wretcher object.
|
|
3079
2745
|
*/
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
2746
|
+
var Wretcher = /** @class */ (function () {
|
|
2747
|
+
function Wretcher(_url, _options, _catchers, _resolvers, _middlewares, _deferredChain) {
|
|
2748
|
+
if (_catchers === void 0) { _catchers = new Map(); }
|
|
2749
|
+
if (_resolvers === void 0) { _resolvers = []; }
|
|
2750
|
+
if (_middlewares === void 0) { _middlewares = []; }
|
|
2751
|
+
if (_deferredChain === void 0) { _deferredChain = []; }
|
|
2752
|
+
this._url = _url;
|
|
2753
|
+
this._options = _options;
|
|
2754
|
+
this._catchers = _catchers;
|
|
2755
|
+
this._resolvers = _resolvers;
|
|
2756
|
+
this._middlewares = _middlewares;
|
|
2757
|
+
this._deferredChain = _deferredChain;
|
|
2758
|
+
}
|
|
2759
|
+
Wretcher.factory = function (url, options) {
|
|
2760
|
+
if (url === void 0) { url = ""; }
|
|
2761
|
+
if (options === void 0) { options = {}; }
|
|
2762
|
+
return new Wretcher(url, options);
|
|
2763
|
+
};
|
|
2764
|
+
Wretcher.prototype.selfFactory = function (_a) {
|
|
2765
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.url, url = _c === void 0 ? this._url : _c, _d = _b.options, options = _d === void 0 ? this._options : _d, _e = _b.catchers, catchers = _e === void 0 ? this._catchers : _e, _f = _b.resolvers, resolvers = _f === void 0 ? this._resolvers : _f, _g = _b.middlewares, middlewares = _g === void 0 ? this._middlewares : _g, _h = _b.deferredChain, deferredChain = _h === void 0 ? this._deferredChain : _h;
|
|
2766
|
+
return new Wretcher(url, __assign$2({}, options), new Map(catchers), __spreadArrays$2(resolvers), __spreadArrays$2(middlewares), __spreadArrays$2(deferredChain));
|
|
2767
|
+
};
|
|
2768
|
+
/**
|
|
2769
|
+
* Sets the default fetch options used for every subsequent fetch call.
|
|
2770
|
+
* @param options New default options
|
|
2771
|
+
* @param mixin If true, mixes in instead of replacing the existing options
|
|
2772
|
+
*/
|
|
2773
|
+
Wretcher.prototype.defaults = function (options, mixin) {
|
|
2774
|
+
if (mixin === void 0) { mixin = false; }
|
|
2775
|
+
config.defaults = mixin ? mix(config.defaults, options) : options;
|
|
2776
|
+
return this;
|
|
2777
|
+
};
|
|
2778
|
+
/**
|
|
2779
|
+
* Sets the method (text, json ...) used to parse the data contained in the response body in case of an HTTP error.
|
|
2780
|
+
*
|
|
2781
|
+
* Persists for every subsequent requests.
|
|
2782
|
+
*
|
|
2783
|
+
* Default is "text".
|
|
2784
|
+
*/
|
|
2785
|
+
Wretcher.prototype.errorType = function (method) {
|
|
2786
|
+
config.errorType = method;
|
|
2787
|
+
return this;
|
|
2788
|
+
};
|
|
2789
|
+
/**
|
|
2790
|
+
* Sets the non-global polyfills which will be used for every subsequent calls.
|
|
2791
|
+
*
|
|
2792
|
+
* Needed for libraries like [fetch-ponyfill](https://github.com/qubyte/fetch-ponyfill).
|
|
2793
|
+
*
|
|
2794
|
+
* @param polyfills An object containing the polyfills.
|
|
2795
|
+
*/
|
|
2796
|
+
Wretcher.prototype.polyfills = function (polyfills) {
|
|
2797
|
+
config.polyfills = __assign$2(__assign$2({}, config.polyfills), polyfills);
|
|
2798
|
+
return this;
|
|
2799
|
+
};
|
|
2800
|
+
/**
|
|
2801
|
+
* Returns a new Wretcher object with the argument url appended and the same options.
|
|
2802
|
+
* @param url String url
|
|
2803
|
+
* @param replace Boolean If true, replaces the current url instead of appending
|
|
2804
|
+
*/
|
|
2805
|
+
Wretcher.prototype.url = function (url, replace) {
|
|
2806
|
+
if (replace === void 0) { replace = false; }
|
|
2807
|
+
if (replace)
|
|
2808
|
+
return this.selfFactory({ url: url });
|
|
2809
|
+
var split = this._url.split("?");
|
|
2810
|
+
return this.selfFactory({
|
|
2811
|
+
url: split.length > 1 ?
|
|
2812
|
+
split[0] + url + "?" + split[1] :
|
|
2813
|
+
this._url + url
|
|
2814
|
+
});
|
|
2815
|
+
};
|
|
2816
|
+
/**
|
|
2817
|
+
* Returns a new Wretcher object with the same url and new options.
|
|
2818
|
+
* @param options New options
|
|
2819
|
+
* @param mixin If true, mixes in instead of replacing the existing options
|
|
2820
|
+
*/
|
|
2821
|
+
Wretcher.prototype.options = function (options, mixin) {
|
|
2822
|
+
if (mixin === void 0) { mixin = true; }
|
|
2823
|
+
return this.selfFactory({ options: mixin ? mix(this._options, options) : options });
|
|
2824
|
+
};
|
|
2825
|
+
/**
|
|
2826
|
+
* Converts a javascript object to query parameters,
|
|
2827
|
+
* then appends this query string to the current url.
|
|
2828
|
+
*
|
|
2829
|
+
* If given a string, use the string as the query verbatim.
|
|
2830
|
+
*
|
|
2831
|
+
* ```
|
|
2832
|
+
* let w = wretch("http://example.com") // url is http://example.com
|
|
2833
|
+
*
|
|
2834
|
+
* // Chain query calls
|
|
2835
|
+
* w = w.query({ a: 1, b : 2 }) // url is now http://example.com?a=1&b=2
|
|
2836
|
+
* w = w.query("foo-bar-baz-woz") // url is now http://example.com?a=1&b=2&foo-bar-baz-woz
|
|
2837
|
+
*
|
|
2838
|
+
* // Pass true as the second argument to replace existing query parameters
|
|
2839
|
+
* w = w.query("c=3&d=4", true) // url is now http://example.com?c=3&d=4
|
|
2840
|
+
* ```
|
|
2841
|
+
*
|
|
2842
|
+
* @param qp An object which will be converted, or a string which will be used verbatim.
|
|
2843
|
+
*/
|
|
2844
|
+
Wretcher.prototype.query = function (qp, replace) {
|
|
2845
|
+
if (replace === void 0) { replace = false; }
|
|
2846
|
+
return this.selfFactory({ url: appendQueryParams(this._url, qp, replace) });
|
|
2847
|
+
};
|
|
2848
|
+
/**
|
|
2849
|
+
* Set request headers.
|
|
2850
|
+
* @param headerValues An object containing header keys and values
|
|
2851
|
+
*/
|
|
2852
|
+
Wretcher.prototype.headers = function (headerValues) {
|
|
2853
|
+
return this.selfFactory({ options: mix(this._options, { headers: headerValues || {} }) });
|
|
2854
|
+
};
|
|
2855
|
+
/**
|
|
2856
|
+
* Shortcut to set the "Accept" header.
|
|
2857
|
+
* @param headerValue Header value
|
|
2858
|
+
*/
|
|
2859
|
+
Wretcher.prototype.accept = function (headerValue) {
|
|
2860
|
+
return this.headers({ Accept: headerValue });
|
|
2861
|
+
};
|
|
2862
|
+
/**
|
|
2863
|
+
* Shortcut to set the "Content-Type" header.
|
|
2864
|
+
* @param headerValue Header value
|
|
2865
|
+
*/
|
|
2866
|
+
Wretcher.prototype.content = function (headerValue) {
|
|
2867
|
+
var _a;
|
|
2868
|
+
return this.headers((_a = {}, _a[CONTENT_TYPE_HEADER] = headerValue, _a));
|
|
2869
|
+
};
|
|
2870
|
+
/**
|
|
2871
|
+
* Shortcut to set the "Authorization" header.
|
|
2872
|
+
* @param headerValue Header value
|
|
2873
|
+
*/
|
|
2874
|
+
Wretcher.prototype.auth = function (headerValue) {
|
|
2875
|
+
return this.headers({ Authorization: headerValue });
|
|
2876
|
+
};
|
|
2877
|
+
/**
|
|
2878
|
+
* Adds a default catcher which will be called on every subsequent request error when the error code matches.
|
|
2879
|
+
* @param errorId Error code or name
|
|
2880
|
+
* @param catcher: The catcher method
|
|
2881
|
+
*/
|
|
2882
|
+
Wretcher.prototype.catcher = function (errorId, catcher) {
|
|
2883
|
+
var newMap = new Map(this._catchers);
|
|
2884
|
+
newMap.set(errorId, catcher);
|
|
2885
|
+
return this.selfFactory({ catchers: newMap });
|
|
2886
|
+
};
|
|
2887
|
+
/**
|
|
2888
|
+
* Associates a custom signal with the request.
|
|
2889
|
+
* @param controller : An AbortController
|
|
2890
|
+
*/
|
|
2891
|
+
Wretcher.prototype.signal = function (controller) {
|
|
2892
|
+
return this.selfFactory({ options: __assign$2(__assign$2({}, this._options), { signal: controller.signal }) });
|
|
2893
|
+
};
|
|
2894
|
+
/**
|
|
2895
|
+
* Program a resolver to perform response chain tasks automatically.
|
|
2896
|
+
* @param doResolve : Resolver callback
|
|
2897
|
+
*/
|
|
2898
|
+
Wretcher.prototype.resolve = function (doResolve, clear) {
|
|
2899
|
+
if (clear === void 0) { clear = false; }
|
|
2900
|
+
return this.selfFactory({ resolvers: clear ? [doResolve] : __spreadArrays$2(this._resolvers, [doResolve]) });
|
|
2901
|
+
};
|
|
2902
|
+
/**
|
|
2903
|
+
* Defer wretcher methods that will be chained and called just before the request is performed.
|
|
2904
|
+
*/
|
|
2905
|
+
Wretcher.prototype.defer = function (callback, clear) {
|
|
2906
|
+
if (clear === void 0) { clear = false; }
|
|
2907
|
+
return this.selfFactory({
|
|
2908
|
+
deferredChain: clear ? [callback] : __spreadArrays$2(this._deferredChain, [callback])
|
|
2909
|
+
});
|
|
2910
|
+
};
|
|
2911
|
+
/**
|
|
2912
|
+
* Add middlewares to intercept a request before being sent.
|
|
2913
|
+
*/
|
|
2914
|
+
Wretcher.prototype.middlewares = function (middlewares, clear) {
|
|
2915
|
+
if (clear === void 0) { clear = false; }
|
|
2916
|
+
return this.selfFactory({
|
|
2917
|
+
middlewares: clear ? middlewares : __spreadArrays$2(this._middlewares, middlewares)
|
|
2918
|
+
});
|
|
2919
|
+
};
|
|
2920
|
+
Wretcher.prototype.method = function (method, options, body) {
|
|
2921
|
+
if (options === void 0) { options = {}; }
|
|
2922
|
+
if (body === void 0) { body = null; }
|
|
2923
|
+
var headers = this._options.headers;
|
|
2924
|
+
var baseWretcher = !body ? this :
|
|
2925
|
+
typeof body === "object" && (!headers ||
|
|
2926
|
+
Object.entries(headers).every(function (_a) {
|
|
2927
|
+
var k = _a[0], v = _a[1];
|
|
2928
|
+
return k.toLowerCase() !== CONTENT_TYPE_HEADER.toLowerCase() ||
|
|
2929
|
+
v.startsWith(JSON_MIME);
|
|
2930
|
+
})) ? this.json(body) :
|
|
2931
|
+
this.body(body);
|
|
2932
|
+
baseWretcher = baseWretcher.options(__assign$2(__assign$2({}, options), { method: method }));
|
|
2933
|
+
var deferredWretcher = baseWretcher._deferredChain.reduce(function (acc, curr) { return curr(acc, acc._url, acc._options); }, baseWretcher);
|
|
2934
|
+
return resolver(deferredWretcher);
|
|
2935
|
+
};
|
|
2936
|
+
/**
|
|
2937
|
+
* Performs a get request.
|
|
2938
|
+
*/
|
|
2939
|
+
Wretcher.prototype.get = function (options) {
|
|
2940
|
+
return this.method("GET", options);
|
|
2941
|
+
};
|
|
2942
|
+
/**
|
|
2943
|
+
* Performs a delete request.
|
|
2944
|
+
*/
|
|
2945
|
+
Wretcher.prototype.delete = function (options) {
|
|
2946
|
+
return this.method("DELETE", options);
|
|
2947
|
+
};
|
|
2948
|
+
/**
|
|
2949
|
+
* Performs a put request.
|
|
2950
|
+
*/
|
|
2951
|
+
Wretcher.prototype.put = function (body, options) {
|
|
2952
|
+
return this.method("PUT", options, body);
|
|
2953
|
+
};
|
|
2954
|
+
/**
|
|
2955
|
+
* Performs a post request.
|
|
2956
|
+
*/
|
|
2957
|
+
Wretcher.prototype.post = function (body, options) {
|
|
2958
|
+
return this.method("POST", options, body);
|
|
2959
|
+
};
|
|
2960
|
+
/**
|
|
2961
|
+
* Performs a patch request.
|
|
2962
|
+
*/
|
|
2963
|
+
Wretcher.prototype.patch = function (body, options) {
|
|
2964
|
+
return this.method("PATCH", options, body);
|
|
2965
|
+
};
|
|
2966
|
+
/**
|
|
2967
|
+
* Performs a head request.
|
|
2968
|
+
*/
|
|
2969
|
+
Wretcher.prototype.head = function (options) {
|
|
2970
|
+
return this.method("HEAD", options);
|
|
2971
|
+
};
|
|
2972
|
+
/**
|
|
2973
|
+
* Performs an options request
|
|
2974
|
+
*/
|
|
2975
|
+
Wretcher.prototype.opts = function (options) {
|
|
2976
|
+
return this.method("OPTIONS", options);
|
|
2977
|
+
};
|
|
2978
|
+
/**
|
|
2979
|
+
* Replay a request.
|
|
2980
|
+
*/
|
|
2981
|
+
Wretcher.prototype.replay = function (options) {
|
|
2982
|
+
return this.method(this._options.method, options);
|
|
2983
|
+
};
|
|
2984
|
+
/**
|
|
2985
|
+
* Sets the request body with any content.
|
|
2986
|
+
* @param contents The body contents
|
|
2987
|
+
*/
|
|
2988
|
+
Wretcher.prototype.body = function (contents) {
|
|
2989
|
+
return this.selfFactory({ options: __assign$2(__assign$2({}, this._options), { body: contents }) });
|
|
2990
|
+
};
|
|
2991
|
+
/**
|
|
2992
|
+
* Sets the content type header, stringifies an object and sets the request body.
|
|
2993
|
+
* @param jsObject An object which will be serialized into a JSON
|
|
2994
|
+
*/
|
|
2995
|
+
Wretcher.prototype.json = function (jsObject) {
|
|
2996
|
+
var _a;
|
|
2997
|
+
var preservedContentType = (_a = Object.entries(this._options.headers || {}).find(function (_a) {
|
|
2998
|
+
var k = _a[0], v = _a[1];
|
|
2999
|
+
return k.toLowerCase() === CONTENT_TYPE_HEADER.toLowerCase() && v.startsWith(JSON_MIME);
|
|
3000
|
+
})) === null || _a === void 0 ? void 0 : _a[1];
|
|
3001
|
+
return this.content(preservedContentType || JSON_MIME).body(JSON.stringify(jsObject));
|
|
3002
|
+
};
|
|
3003
|
+
/**
|
|
3004
|
+
* Converts the javascript object to a FormData and sets the request body.
|
|
3005
|
+
* @param formObject An object which will be converted to a FormData
|
|
3006
|
+
* @param recursive If `true`, will recurse through all nested objects
|
|
3007
|
+
* Can be set as an array of string to exclude specific keys.
|
|
3008
|
+
* See https://github.com/elbywan/wretch/issues/68 for more details.
|
|
3009
|
+
*/
|
|
3010
|
+
Wretcher.prototype.formData = function (formObject, recursive) {
|
|
3011
|
+
if (recursive === void 0) { recursive = false; }
|
|
3012
|
+
return this.body(convertFormData(formObject, recursive));
|
|
3013
|
+
};
|
|
3014
|
+
/**
|
|
3015
|
+
* Converts the input to an url encoded string and sets the content-type header and body.
|
|
3016
|
+
* If the input argument is already a string, skips the conversion part.
|
|
3017
|
+
*
|
|
3018
|
+
* @param input An object to convert into an url encoded string or an already encoded string
|
|
3019
|
+
*/
|
|
3020
|
+
Wretcher.prototype.formUrl = function (input) {
|
|
3021
|
+
return this
|
|
3022
|
+
.body(typeof input === "string" ? input : convertFormUrl(input))
|
|
3023
|
+
.content("application/x-www-form-urlencoded");
|
|
3024
|
+
};
|
|
3025
|
+
return Wretcher;
|
|
3026
|
+
}());
|
|
3027
|
+
// Internal helpers
|
|
3028
|
+
var appendQueryParams = function (url, qp, replace) {
|
|
3029
|
+
var queryString;
|
|
3030
|
+
if (typeof qp === "string") {
|
|
3031
|
+
queryString = qp;
|
|
3032
|
+
}
|
|
3033
|
+
else {
|
|
3034
|
+
var usp = config.polyfill("URLSearchParams", { instance: true });
|
|
3035
|
+
for (var key in qp) {
|
|
3036
|
+
if (qp[key] instanceof Array) {
|
|
3037
|
+
for (var _i = 0, _a = qp[key]; _i < _a.length; _i++) {
|
|
3038
|
+
var val = _a[_i];
|
|
3039
|
+
usp.append(key, val);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
else {
|
|
3043
|
+
usp.append(key, qp[key]);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
queryString = usp.toString();
|
|
3047
|
+
}
|
|
3048
|
+
var split = url.split("?");
|
|
3049
|
+
if (replace || split.length < 2)
|
|
3050
|
+
return split[0] + "?" + queryString;
|
|
3051
|
+
return url + "&" + queryString;
|
|
3103
3052
|
};
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
* assert.strictEqual(
|
|
3132
|
-
* pipe(
|
|
3133
|
-
* some(1),
|
|
3134
|
-
* exists(n => n > 0)
|
|
3135
|
-
* ),
|
|
3136
|
-
* true
|
|
3137
|
-
* )
|
|
3138
|
-
* assert.strictEqual(
|
|
3139
|
-
* pipe(
|
|
3140
|
-
* some(1),
|
|
3141
|
-
* exists(n => n > 1)
|
|
3142
|
-
* ),
|
|
3143
|
-
* false
|
|
3144
|
-
* )
|
|
3145
|
-
* assert.strictEqual(
|
|
3146
|
-
* pipe(
|
|
3147
|
-
* none,
|
|
3148
|
-
* exists(n => n > 0)
|
|
3149
|
-
* ),
|
|
3150
|
-
* false
|
|
3151
|
-
* )
|
|
3152
|
-
*
|
|
3153
|
-
* @since 2.0.0
|
|
3154
|
-
*/
|
|
3155
|
-
function exists(predicate) {
|
|
3156
|
-
return function (ma) { return (exports.isNone(ma) ? false : predicate(ma.value)); };
|
|
3053
|
+
function convertFormData(formObject, recursive, formData, ancestors) {
|
|
3054
|
+
if (recursive === void 0) { recursive = false; }
|
|
3055
|
+
if (formData === void 0) { formData = config.polyfill("FormData", { instance: true }); }
|
|
3056
|
+
if (ancestors === void 0) { ancestors = []; }
|
|
3057
|
+
Object.entries(formObject).forEach(function (_a) {
|
|
3058
|
+
var key = _a[0], value = _a[1];
|
|
3059
|
+
var formKey = ancestors.reduce(function (acc, ancestor) { return (acc ? acc + "[" + ancestor + "]" : ancestor); }, null);
|
|
3060
|
+
formKey = formKey ? formKey + "[" + key + "]" : key;
|
|
3061
|
+
if (value instanceof Array) {
|
|
3062
|
+
for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
|
|
3063
|
+
var item = value_1[_i];
|
|
3064
|
+
formData.append(formKey + "[]", item);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
else if (recursive &&
|
|
3068
|
+
typeof value === "object" &&
|
|
3069
|
+
(!(recursive instanceof Array) ||
|
|
3070
|
+
!recursive.includes(key))) {
|
|
3071
|
+
if (value !== null) {
|
|
3072
|
+
convertFormData(value, recursive, formData, __spreadArrays$2(ancestors, [key]));
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
else {
|
|
3076
|
+
formData.append(formKey, value);
|
|
3077
|
+
}
|
|
3078
|
+
});
|
|
3079
|
+
return formData;
|
|
3157
3080
|
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
* import { some, none, getRefinement } from 'fp-ts/Option'
|
|
3165
|
-
*
|
|
3166
|
-
* type A = { type: 'A' }
|
|
3167
|
-
* type B = { type: 'B' }
|
|
3168
|
-
* type C = A | B
|
|
3169
|
-
*
|
|
3170
|
-
* const isA = (c: C): c is A => c.type === 'B' // <= typo but typescript doesn't complain
|
|
3171
|
-
* const isA = getRefinement<C, A>(c => (c.type === 'B' ? some(c) : none)) // static error: Type '"B"' is not assignable to type '"A"'
|
|
3172
|
-
* ```
|
|
3173
|
-
*
|
|
3174
|
-
* @since 2.0.0
|
|
3175
|
-
*/
|
|
3176
|
-
function getRefinement(getOption) {
|
|
3177
|
-
return function (a) { return exports.isSome(getOption(a)); };
|
|
3081
|
+
function encodeQueryValue(key, value) {
|
|
3082
|
+
return encodeURIComponent(key) +
|
|
3083
|
+
"=" +
|
|
3084
|
+
encodeURIComponent(typeof value === "object" ?
|
|
3085
|
+
JSON.stringify(value) :
|
|
3086
|
+
"" + value);
|
|
3178
3087
|
}
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3088
|
+
function convertFormUrl(formObject) {
|
|
3089
|
+
return Object.keys(formObject)
|
|
3090
|
+
.map(function (key) {
|
|
3091
|
+
var value = formObject[key];
|
|
3092
|
+
if (value instanceof Array) {
|
|
3093
|
+
return value.map(function (v) { return encodeQueryValue(key, v); }).join("&");
|
|
3094
|
+
}
|
|
3095
|
+
return encodeQueryValue(key, value);
|
|
3096
|
+
})
|
|
3097
|
+
.join("&");
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
var factory = Wretcher.factory;
|
|
3101
|
+
factory["default"] = Wretcher.factory;
|
|
3102
|
+
|
|
3103
|
+
const appendToMap = (map, propName, value) => {
|
|
3104
|
+
const items = map.get(propName);
|
|
3105
|
+
if (!items) {
|
|
3106
|
+
map.set(propName, [value]);
|
|
3107
|
+
}
|
|
3108
|
+
else if (!items.includes(value)) {
|
|
3109
|
+
items.push(value);
|
|
3110
|
+
}
|
|
3201
3111
|
};
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3112
|
+
const debounce = (fn, ms) => {
|
|
3113
|
+
let timeoutId;
|
|
3114
|
+
return (...args) => {
|
|
3115
|
+
if (timeoutId) {
|
|
3116
|
+
clearTimeout(timeoutId);
|
|
3117
|
+
}
|
|
3118
|
+
timeoutId = setTimeout(() => {
|
|
3119
|
+
timeoutId = 0;
|
|
3120
|
+
fn(...args);
|
|
3121
|
+
}, ms);
|
|
3122
|
+
};
|
|
3211
3123
|
};
|
|
3212
|
-
|
|
3213
|
-
// -------------------------------------------------------------------------------------
|
|
3214
|
-
// array utils
|
|
3215
|
-
// -------------------------------------------------------------------------------------
|
|
3124
|
+
|
|
3216
3125
|
/**
|
|
3126
|
+
* Check if a possible element isConnected.
|
|
3127
|
+
* The property might not be there, so we check for it.
|
|
3217
3128
|
*
|
|
3218
|
-
*
|
|
3129
|
+
* We want it to return true if isConnected is not a property,
|
|
3130
|
+
* otherwise we would remove these elements and would not update.
|
|
3131
|
+
*
|
|
3132
|
+
* Better leak in Edge than to be useless.
|
|
3219
3133
|
*/
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3134
|
+
const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
|
|
3135
|
+
const cleanupElements = debounce((map) => {
|
|
3136
|
+
for (let key of map.keys()) {
|
|
3137
|
+
map.set(key, map.get(key).filter(isConnected));
|
|
3138
|
+
}
|
|
3139
|
+
}, 2000);
|
|
3140
|
+
const stencilSubscription = ({ on }) => {
|
|
3141
|
+
const elmsToUpdate = new Map();
|
|
3142
|
+
if (typeof getRenderingRef === 'function') {
|
|
3143
|
+
// If we are not in a stencil project, we do nothing.
|
|
3144
|
+
// This function is not really exported by @stencil/core.
|
|
3145
|
+
on('dispose', () => {
|
|
3146
|
+
elmsToUpdate.clear();
|
|
3147
|
+
});
|
|
3148
|
+
on('get', (propName) => {
|
|
3149
|
+
const elm = getRenderingRef();
|
|
3150
|
+
if (elm) {
|
|
3151
|
+
appendToMap(elmsToUpdate, propName, elm);
|
|
3152
|
+
}
|
|
3153
|
+
});
|
|
3154
|
+
on('set', (propName) => {
|
|
3155
|
+
const elements = elmsToUpdate.get(propName);
|
|
3156
|
+
if (elements) {
|
|
3157
|
+
elmsToUpdate.set(propName, elements.filter(forceUpdate));
|
|
3158
|
+
}
|
|
3159
|
+
cleanupElements(elmsToUpdate);
|
|
3160
|
+
});
|
|
3161
|
+
on('reset', () => {
|
|
3162
|
+
elmsToUpdate.forEach((elms) => elms.forEach(forceUpdate));
|
|
3163
|
+
cleanupElements(elmsToUpdate);
|
|
3164
|
+
});
|
|
3165
|
+
}
|
|
3166
|
+
};
|
|
3167
|
+
|
|
3168
|
+
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
3169
|
+
let states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));
|
|
3170
|
+
const handlers = {
|
|
3171
|
+
dispose: [],
|
|
3172
|
+
get: [],
|
|
3173
|
+
set: [],
|
|
3174
|
+
reset: [],
|
|
3175
|
+
};
|
|
3176
|
+
const reset = () => {
|
|
3177
|
+
states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));
|
|
3178
|
+
handlers.reset.forEach((cb) => cb());
|
|
3179
|
+
};
|
|
3180
|
+
const dispose = () => {
|
|
3181
|
+
// Call first dispose as resetting the state would
|
|
3182
|
+
// cause less updates ;)
|
|
3183
|
+
handlers.dispose.forEach((cb) => cb());
|
|
3184
|
+
reset();
|
|
3185
|
+
};
|
|
3186
|
+
const get = (propName) => {
|
|
3187
|
+
handlers.get.forEach((cb) => cb(propName));
|
|
3188
|
+
return states.get(propName);
|
|
3189
|
+
};
|
|
3190
|
+
const set = (propName, value) => {
|
|
3191
|
+
const oldValue = states.get(propName);
|
|
3192
|
+
if (shouldUpdate(value, oldValue, propName)) {
|
|
3193
|
+
states.set(propName, value);
|
|
3194
|
+
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
3227
3195
|
}
|
|
3228
|
-
|
|
3196
|
+
};
|
|
3197
|
+
const state = (typeof Proxy === 'undefined'
|
|
3198
|
+
? {}
|
|
3199
|
+
: new Proxy(defaultState, {
|
|
3200
|
+
get(_, propName) {
|
|
3201
|
+
return get(propName);
|
|
3202
|
+
},
|
|
3203
|
+
ownKeys(_) {
|
|
3204
|
+
return Array.from(states.keys());
|
|
3205
|
+
},
|
|
3206
|
+
getOwnPropertyDescriptor() {
|
|
3207
|
+
return {
|
|
3208
|
+
enumerable: true,
|
|
3209
|
+
configurable: true,
|
|
3210
|
+
};
|
|
3211
|
+
},
|
|
3212
|
+
has(_, propName) {
|
|
3213
|
+
return states.has(propName);
|
|
3214
|
+
},
|
|
3215
|
+
set(_, propName, value) {
|
|
3216
|
+
set(propName, value);
|
|
3217
|
+
return true;
|
|
3218
|
+
},
|
|
3219
|
+
}));
|
|
3220
|
+
const on = (eventName, callback) => {
|
|
3221
|
+
handlers[eventName].push(callback);
|
|
3222
|
+
return () => {
|
|
3223
|
+
removeFromArray(handlers[eventName], callback);
|
|
3224
|
+
};
|
|
3225
|
+
};
|
|
3226
|
+
const onChange = (propName, cb) => {
|
|
3227
|
+
const unSet = on('set', (key, newValue) => {
|
|
3228
|
+
if (key === propName) {
|
|
3229
|
+
cb(newValue);
|
|
3230
|
+
}
|
|
3231
|
+
});
|
|
3232
|
+
const unReset = on('reset', () => cb(defaultState[propName]));
|
|
3233
|
+
return () => {
|
|
3234
|
+
unSet();
|
|
3235
|
+
unReset();
|
|
3236
|
+
};
|
|
3237
|
+
};
|
|
3238
|
+
const use = (...subscriptions) => subscriptions.forEach((subscription) => {
|
|
3239
|
+
if (subscription.set) {
|
|
3240
|
+
on('set', subscription.set);
|
|
3241
|
+
}
|
|
3242
|
+
if (subscription.get) {
|
|
3243
|
+
on('get', subscription.get);
|
|
3244
|
+
}
|
|
3245
|
+
if (subscription.reset) {
|
|
3246
|
+
on('reset', subscription.reset);
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
return {
|
|
3250
|
+
state,
|
|
3251
|
+
get,
|
|
3252
|
+
set,
|
|
3253
|
+
on,
|
|
3254
|
+
onChange,
|
|
3255
|
+
use,
|
|
3256
|
+
dispose,
|
|
3257
|
+
reset,
|
|
3258
|
+
};
|
|
3259
|
+
};
|
|
3260
|
+
const removeFromArray = (array, item) => {
|
|
3261
|
+
const index = array.indexOf(item);
|
|
3262
|
+
if (index >= 0) {
|
|
3263
|
+
array[index] = array[array.length - 1];
|
|
3264
|
+
array.length--;
|
|
3229
3265
|
}
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
*
|
|
3238
|
-
* @example
|
|
3239
|
-
*
|
|
3240
|
-
* import * as A from 'fp-ts/Array'
|
|
3241
|
-
* import { traverseArray, some, fromPredicate, none } from 'fp-ts/Option'
|
|
3242
|
-
* import { pipe } from 'fp-ts/function'
|
|
3243
|
-
*
|
|
3244
|
-
* const arr = A.range(0, 10)
|
|
3245
|
-
* assert.deepStrictEqual(pipe(arr, traverseArray(some)), some(arr))
|
|
3246
|
-
* assert.deepStrictEqual(pipe(arr, traverseArray(fromPredicate((x) => x > 5))), none)
|
|
3247
|
-
*
|
|
3248
|
-
* @since 2.9.0
|
|
3249
|
-
*/
|
|
3250
|
-
var traverseArray = function (f) { return exports.traverseArrayWithIndex(function (_, a) { return f(a); }); };
|
|
3251
|
-
exports.traverseArray = traverseArray;
|
|
3252
|
-
/**
|
|
3253
|
-
* get an array of option and convert it to option of array
|
|
3254
|
-
*
|
|
3255
|
-
* this function have the same behavior of `A.sequence(O.option)` but it's optimized and perform better
|
|
3256
|
-
*
|
|
3257
|
-
* @example
|
|
3258
|
-
*
|
|
3259
|
-
* import * as A from 'fp-ts/Array'
|
|
3260
|
-
* import { sequenceArray, some, none, fromPredicate } from 'fp-ts/Option'
|
|
3261
|
-
* import { pipe } from 'fp-ts/function'
|
|
3262
|
-
*
|
|
3263
|
-
* const arr = A.range(0, 10)
|
|
3264
|
-
* assert.deepStrictEqual(pipe(arr, A.map(some), sequenceArray), some(arr))
|
|
3265
|
-
* assert.deepStrictEqual(pipe(arr, A.map(fromPredicate(x => x > 8)), sequenceArray), none)
|
|
3266
|
-
*
|
|
3267
|
-
* @since 2.9.0
|
|
3268
|
-
*/
|
|
3269
|
-
exports.sequenceArray =
|
|
3270
|
-
/*#__PURE__*/
|
|
3271
|
-
exports.traverseArray(_function.identity);
|
|
3272
|
-
});
|
|
3266
|
+
};
|
|
3267
|
+
|
|
3268
|
+
const createStore = (defaultState, shouldUpdate) => {
|
|
3269
|
+
const map = createObservableMap(defaultState, shouldUpdate);
|
|
3270
|
+
stencilSubscription(map);
|
|
3271
|
+
return map;
|
|
3272
|
+
};
|
|
3273
3273
|
|
|
3274
3274
|
function e(e){this.message=e;}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw "Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e;}function o(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}}n.prototype=new Error,n.prototype.name="InvalidTokenError";
|
|
3275
3275
|
|
|
@@ -3301,6 +3301,9 @@ function hydratePromotedFundChoiceDtoKind(dto) {
|
|
|
3301
3301
|
else if ('mercerMyChoice' in dto) {
|
|
3302
3302
|
dto.kind = 'mercerMyChoice';
|
|
3303
3303
|
}
|
|
3304
|
+
else if ('generic' in dto) {
|
|
3305
|
+
dto.kind = 'generic';
|
|
3306
|
+
}
|
|
3304
3307
|
}
|
|
3305
3308
|
function getPromotedFundUsi(dto) {
|
|
3306
3309
|
switch (dto.kind) {
|
|
@@ -3322,6 +3325,8 @@ function getPromotedFundUsi(dto) {
|
|
|
3322
3325
|
return some(dto.firstSuper.usi);
|
|
3323
3326
|
case 'mercerMyChoice':
|
|
3324
3327
|
return some(dto.mercerMyChoice.usi);
|
|
3328
|
+
case 'generic':
|
|
3329
|
+
return some(dto.generic.usi);
|
|
3325
3330
|
default:
|
|
3326
3331
|
return none;
|
|
3327
3332
|
}
|
|
@@ -3338,6 +3343,8 @@ function getSuperChoiceUsi(dto) {
|
|
|
3338
3343
|
return some(dto.default.usi);
|
|
3339
3344
|
case 'PromotedDefault':
|
|
3340
3345
|
return some(dto.promotedDefault.usi);
|
|
3346
|
+
case 'DefinedBenefits':
|
|
3347
|
+
return some(dto.definedBenefits.usi);
|
|
3341
3348
|
default:
|
|
3342
3349
|
return none;
|
|
3343
3350
|
}
|
|
@@ -3362,6 +3369,8 @@ function getPromotedFundMemberNumber(dto) {
|
|
|
3362
3369
|
return some(dto.firstSuper.memberNumber);
|
|
3363
3370
|
case 'mercerMyChoice':
|
|
3364
3371
|
return some(dto.mercerMyChoice.memberNumber);
|
|
3372
|
+
case 'generic':
|
|
3373
|
+
return some(dto.generic.memberNumber);
|
|
3365
3374
|
default:
|
|
3366
3375
|
return none;
|
|
3367
3376
|
}
|
|
@@ -3372,6 +3381,8 @@ function getSuperChoiceMemberNumber(dto) {
|
|
|
3372
3381
|
return getPromotedFundMemberNumber(dto.promoted);
|
|
3373
3382
|
case 'MyOwnFund':
|
|
3374
3383
|
return some(dto.myOwnFund.memberNumber);
|
|
3384
|
+
case 'DefinedBenefits':
|
|
3385
|
+
return some(dto.definedBenefits.memberNumber);
|
|
3375
3386
|
case 'SMSF':
|
|
3376
3387
|
case 'Default':
|
|
3377
3388
|
case 'PromotedDefault':
|
|
@@ -3396,6 +3407,9 @@ function hydrateSuperChoiceDetailsDtoKind(dto) {
|
|
|
3396
3407
|
else if ('promotedDefault' in dto) {
|
|
3397
3408
|
dto.kind = 'PromotedDefault';
|
|
3398
3409
|
}
|
|
3410
|
+
else if ('definedBenefits' in dto) {
|
|
3411
|
+
dto.kind = 'DefinedBenefits';
|
|
3412
|
+
}
|
|
3399
3413
|
}
|
|
3400
3414
|
|
|
3401
3415
|
class SuperSelectionApi {
|
|
@@ -3476,7 +3490,7 @@ const initialState = {
|
|
|
3476
3490
|
hasSuperSelectionBeenSubmitted: false,
|
|
3477
3491
|
campaignConnectEnabled: false,
|
|
3478
3492
|
campaignConnectPromise: Option.none,
|
|
3479
|
-
|
|
3493
|
+
isDefinedBenefitsEligible: Option.none,
|
|
3480
3494
|
campaignConnect: Option.none
|
|
3481
3495
|
};
|
|
3482
3496
|
|
|
@@ -3577,6 +3591,9 @@ class SuperSelectionAppService {
|
|
|
3577
3591
|
get campaignConnectEnabled() {
|
|
3578
3592
|
return this._state.campaignConnectEnabled;
|
|
3579
3593
|
}
|
|
3594
|
+
get isDefinedBenefitsEligible() {
|
|
3595
|
+
return this._state.isDefinedBenefitsEligible;
|
|
3596
|
+
}
|
|
3580
3597
|
async loadAppStateAsync() {
|
|
3581
3598
|
const appStateResponse = await superSelectionApi.getAppStateAsync();
|
|
3582
3599
|
this._state.accountConfiguration = Option.fromNullable(appStateResponse.accountConfiguration);
|
|
@@ -3585,7 +3602,7 @@ class SuperSelectionAppService {
|
|
|
3585
3602
|
this._state.promotedFunds = Option.fromNullable(appStateResponse.promotedFunds);
|
|
3586
3603
|
this._state.campaignConnectEnabled = appStateResponse.campaignConnectEnabled;
|
|
3587
3604
|
this._state.superChoicePrefill = Option.fromNullable(appStateResponse.prefill);
|
|
3588
|
-
this._state.
|
|
3605
|
+
this._state.isDefinedBenefitsEligible = Option.fromNullable(appStateResponse.isDefinedBenefitsEligible);
|
|
3589
3606
|
}
|
|
3590
3607
|
async startLoadingCampaignConnectAsync() {
|
|
3591
3608
|
if (this._state.campaignConnectEnabled) {
|
|
@@ -3873,7 +3890,15 @@ const Consent = class {
|
|
|
3873
3890
|
this.eventTrackingService = EventTrackingService.Instance;
|
|
3874
3891
|
}
|
|
3875
3892
|
componentDidLoad() {
|
|
3876
|
-
|
|
3893
|
+
let isDefinedBenefitsEligible = 'Not set';
|
|
3894
|
+
if (Option.isSome(superSelectionAppService.isDefinedBenefitsEligible)) {
|
|
3895
|
+
isDefinedBenefitsEligible = superSelectionAppService.isDefinedBenefitsEligible.value
|
|
3896
|
+
? 'True'
|
|
3897
|
+
: 'False';
|
|
3898
|
+
}
|
|
3899
|
+
return this.eventTrackingService.TrackSuperFundDisclaimerViewedAsync({
|
|
3900
|
+
isDefinedBenefitsEligible
|
|
3901
|
+
});
|
|
3877
3902
|
}
|
|
3878
3903
|
render() {
|
|
3879
3904
|
return (h("div", null, h("div", { class: "text-2xl sm:text-3xl font-bold text-center leading-8" }, "Important information about super"), h("div", { class: "sm:text-lg text-gray-600 mt-3 sm:mt-4 max-w-800 text-center leading-7 sm:leading-8" }, "The choice of superannuation fund is an important personal financial decision. Next, you\u2019ll be asked to nominate a super fund to receive your employer contributions."), h("div", { class: "flex justify-center mt-8 sm:mt-12" }, h("div", { class: "border shadow-sm p-4 pb-6 sm:p-6 sm:pb-8 max-w-560 rounded-lg" }, h("div", { class: "sm:text-lg font-bold leading-6" }, "By clicking \u201CContinue\u201D you acknowledge that:"), h("ul", { class: "list-disc list-outside ml-6 mt-3 mb-6 space-y-2 text-sm leading-6" }, h("li", null, "Flare (we/us) provides this paperless employee management service, will feature superannuation funds and offer you employee benefits that you may be interested in;"), h("li", null, "all content contained in the following pages does not take into account any of your objectives, financial situation or needs and does not constitute financial product advice;"), h("li", null, "in featuring any superannuation funds, we, the technology partner you are accessing us via, or your employer, are not providing any opinion or recommendation (actual or implied) in relation to the suitability or appropriateness of the featured funds;"), h("li", null, "Trustees of the featured superannuation funds pay fees to Flare and/or its associates. Some funds pay us a fee if you choose one of the featured funds, while others pay us to have their application form on our platform;"), h("li", null, "in the event that you choose one of the featured superannuation funds, we may pass on your personal information and TFN to a related party for the purpose of completing your chosen fund's application form."), h("li", null, "Your personal data that is provided to us will be subject to our", ' ', h(Link, { className: "font-medium text-blue-600 hover:text-blue-800", href: "https://www.flarehr.com/privacy-policy" }, "Privacy Policy"), ".")), h("sss-button", { fillWidth: true, promiseFn: () => this.handleSuperFundDisclaimerAccepted() }, "Continue")))));
|
|
@@ -4624,6 +4649,10 @@ const getFundByDtoPropName = (dtoPropName) => {
|
|
|
4624
4649
|
const fund = allPromotedFunds.find((f) => f.dtoPropName == dtoPropName);
|
|
4625
4650
|
return fund ? some(fund) : none;
|
|
4626
4651
|
};
|
|
4652
|
+
const getFundByFundId = (fundId) => {
|
|
4653
|
+
const fund = allPromotedFunds.find((f) => f.fundId == fundId);
|
|
4654
|
+
return fund ? some(fund) : none;
|
|
4655
|
+
};
|
|
4627
4656
|
const getFundNameByFundId = (fundId) => fundsById[fundId] != undefined ? some(fundsById[fundId].name) : none;
|
|
4628
4657
|
const getFooterTextOverrideByFundId = (fundId) => { var _a, _b; return (_b = (_a = fundsById[fundId]) === null || _a === void 0 ? void 0 : _a.footnoteTextOverride) !== null && _b !== void 0 ? _b : none; };
|
|
4629
4658
|
const getFundUsiByFundId = (fundId) => fundId == fund$7.fundId ? some(slateUsi) : none;
|
|
@@ -4643,8 +4672,9 @@ class ExistingFundService {
|
|
|
4643
4672
|
const memberNumber = getSuperChoiceMemberNumber(choiceDetails);
|
|
4644
4673
|
switch (choiceDetails.kind) {
|
|
4645
4674
|
case 'Promoted': {
|
|
4646
|
-
const
|
|
4647
|
-
|
|
4675
|
+
const fund = choiceDetails.promoted['generic']
|
|
4676
|
+
? getFundByFundId(choiceDetails.promoted['generic'].fundId)
|
|
4677
|
+
: getFundByDtoPropName(Object.keys(choiceDetails.promoted)[0]);
|
|
4648
4678
|
if (isNone(fund))
|
|
4649
4679
|
return none;
|
|
4650
4680
|
return some({
|
|
@@ -4699,6 +4729,17 @@ class ExistingFundService {
|
|
|
4699
4729
|
lastNominatedAt: dateSubmitted
|
|
4700
4730
|
});
|
|
4701
4731
|
}
|
|
4732
|
+
case 'DefinedBenefits': {
|
|
4733
|
+
const defaultUsi = choiceDetails.definedBenefits.usi;
|
|
4734
|
+
const fund = await this.getFundByUsiAsync(defaultUsi);
|
|
4735
|
+
return some({
|
|
4736
|
+
type: 'Defined Benefits Fund',
|
|
4737
|
+
name: isSome(fund) ? fund.value.productName : defaultUsi,
|
|
4738
|
+
usi: usi,
|
|
4739
|
+
valid: this.toFundValidState(fund),
|
|
4740
|
+
lastNominatedAt: dateSubmitted
|
|
4741
|
+
});
|
|
4742
|
+
}
|
|
4702
4743
|
default:
|
|
4703
4744
|
return none;
|
|
4704
4745
|
}
|
|
@@ -4778,7 +4819,13 @@ const ExistingChoice = class {
|
|
|
4778
4819
|
const DefaultFundView = () => {
|
|
4779
4820
|
return (h("div", { class: "flex h-20 justify-center items-center relative" }, h("div", { class: "h-20 w-20 rounded-full bg-primary-base opacity-10" }), h("div", { class: "h-10 w-10 absolute" }, h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512", class: "fill-primary-base" }, h("path", { d: "M448 96h-64V48C384 21.53 362.5 0 336 0h-160C149.5 0 128 21.53 128 48V96H64C28.65 96 0 124.7 0 160v256c0 35.35 28.65 64 64 64h384c35.35 0 64-28.65 64-64V160C512 124.7 483.3 96 448 96zM160 48C160 39.17 167.2 32 176 32h160C344.8 32 352 39.17 352 48V96H160V48zM480 416c0 17.64-14.36 32-32 32H64c-17.64 0-32-14.36-32-32V288h144v64c0 8.844 7.156 16 16 16h128c8.844 0 16-7.156 16-16V288H480V416zM208 336V288h96v48H208zM480 256H32V160c0-17.64 14.36-32 32-32h384c17.64 0 32 14.36 32 32V256z" })))));
|
|
4780
4821
|
};
|
|
4781
|
-
|
|
4822
|
+
const DefinedBenefitsFundView = () => {
|
|
4823
|
+
return (h("div", { class: "flex h-20 justify-center items-center relative" }, h("div", { class: "h-20 w-20 rounded-full bg-primary-base opacity-10" }), h("div", { class: "h-10 w-10 absolute" }, h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 576 512", class: "fill-primary-base" }, h("path", { d: "M174.7 111.8C165.1 110.3 160.1 102.1 161.5 93.35C170.4 40.37 216.5 0 272 0C320.8 0 362.3 31.19 377.6 74.67C380.6 82.1 376.2 92.14 367.9 95.09C359.5 98.03 350.4 93.66 347.5 85.33C336.5 54.24 306.8 32 272 32C232.4 32 199.5 60.82 193.1 98.65C191.6 107.4 183.4 113.2 174.7 111.8V111.8zM400 264C400 250.7 410.7 240 424 240C437.3 240 448 250.7 448 264C448 277.3 437.3 288 424 288C410.7 288 400 277.3 400 264zM488.5 125.8L480 159.1C501.1 176.5 519.6 198.5 530.7 224H544C561.7 224 576 238.3 576 256V352C576 369.7 561.7 384 544 384H512C495.5 405.1 473.5 423.6 448 434.7V464C448 490.5 426.5 512 400 512H368C341.5 512 320 490.5 320 464V448H256V464C256 490.5 234.5 512 208 512H176C149.5 512 128 490.5 128 464V416C89.14 386.8 64 340.3 64 288C28.52 287.2 0 258.2 0 222.6C0 197.8 14 175.1 36.18 164L40.84 161.7C48.75 157.7 58.36 160.9 62.31 168.8C66.26 176.7 63.06 186.4 55.16 190.3L50.49 192.6C39.16 198.3 31.1 209.9 31.1 222.6C31.1 241 46.97 256 65.44 256H67.2C82.02 182.1 146.6 128 223.1 128H376.4C394 108.4 419.6 96 448 96H465.3C480.9 96 492.3 110.7 488.5 125.8H488.5zM224 160C153.3 160 96 217.3 96 288C96 329.9 116.1 367 147.2 390.4L160 400V464C160 472.8 167.2 480 176 480H208C216.8 480 224 472.8 224 464V416H352V464C352 472.8 359.2 480 368 480H400C408.8 480 416 472.8 416 464V413.7L435.2 405.4C455.6 396.5 473.2 382.4 486.4 364.8L496 352H544V256H509.7L501.4 236.8C492.5 216.4 478.4 198.8 460.8 185.6L443.8 172.8L455 128H448C429 128 412.1 136.2 400.3 149.3L390.7 160H224z" })))));
|
|
4824
|
+
};
|
|
4825
|
+
const ChooseAnotherFundView = () => {
|
|
4826
|
+
return this.existingFund.type == 'Defined Benefits Fund' ? null : (h("div", { class: "mt-4" }, h("sss-button", { fillWidth: true, variant: "secondary", promiseFn: () => this.handleFundNominationDeclined() }, "Choose another fund")));
|
|
4827
|
+
};
|
|
4828
|
+
return (h("div", null, h("div", { class: "text-2xl sm:text-3xl font-bold text-center" }, "Your super nomination"), this.existingFund.type == 'Defined Benefits Fund' ? null : (h("div", { class: "sm:text-lg text-gray-600 mt-3 sm:mt-4 max-w-800 text-center leading-7" }, "Continue with your chosen fund or choose another fund below.")), h("div", { class: "flex justify-center mt-8 sm:mt-12" }, h("div", { class: "max-w-400 w-full" }, h("div", { class: "flex-col border shadow-sm p-6 pt-8 rounded-lg text-center" }, h("div", { class: "space-y-4" }, (() => {
|
|
4782
4829
|
switch (this.existingFund.type) {
|
|
4783
4830
|
case 'Promoted Fund':
|
|
4784
4831
|
case 'Promoted Default Fund':
|
|
@@ -4789,6 +4836,8 @@ const ExistingChoice = class {
|
|
|
4789
4836
|
return h(MyOwnFundView, null);
|
|
4790
4837
|
case 'Default Fund':
|
|
4791
4838
|
return h(DefaultFundView, null);
|
|
4839
|
+
case 'Defined Benefits Fund':
|
|
4840
|
+
return h(DefinedBenefitsFundView, null);
|
|
4792
4841
|
default:
|
|
4793
4842
|
return h("div", null);
|
|
4794
4843
|
}
|
|
@@ -4800,11 +4849,12 @@ const ExistingChoice = class {
|
|
|
4800
4849
|
case 'Promoted Fund':
|
|
4801
4850
|
case 'Self Managed Fund':
|
|
4802
4851
|
case 'Promoted Default Fund':
|
|
4852
|
+
case 'Defined Benefits Fund':
|
|
4803
4853
|
return this.existingFund.name;
|
|
4804
4854
|
default:
|
|
4805
4855
|
return '';
|
|
4806
4856
|
}
|
|
4807
|
-
})())), h("div", { class: "mt-6" }, h("sss-button", { fillWidth: true, promiseFn: () => this.handleFundNominationAccepted() }, "Continue with this fund"))), h(
|
|
4857
|
+
})())), h("div", { class: "mt-6" }, h("sss-button", { fillWidth: true, promiseFn: () => this.handleFundNominationAccepted() }, "Continue with this fund"))), h(ChooseAnotherFundView, null)))));
|
|
4808
4858
|
}
|
|
4809
4859
|
async handleFundNominationAccepted() {
|
|
4810
4860
|
const detail = this.createSuperFundNominationDetail(this.existingFund);
|
|
@@ -7983,7 +8033,12 @@ const SuperSelectionApp = class {
|
|
|
7983
8033
|
});
|
|
7984
8034
|
iframe.appReady();
|
|
7985
8035
|
const ignoreExistingSelectionOption = Option.fromNullable(this.ignoreExistingSelection);
|
|
7986
|
-
const
|
|
8036
|
+
const shouldIgnoreExistingDefinedBenefitsChoice = Option.isSome(chosenFundOption) &&
|
|
8037
|
+
chosenFundOption.value.type == 'Defined Benefits Fund' &&
|
|
8038
|
+
(Option.isNone(superSelectionAppService.isDefinedBenefitsEligible) ||
|
|
8039
|
+
!superSelectionAppService.isDefinedBenefitsEligible.value);
|
|
8040
|
+
const shouldIgnoreExistingChoice = (Option.isSome(ignoreExistingSelectionOption) && ignoreExistingSelectionOption.value) ||
|
|
8041
|
+
shouldIgnoreExistingDefinedBenefitsChoice;
|
|
7987
8042
|
if (Option.isSome(superSelectionAppService.state.superChoicePrefill)) {
|
|
7988
8043
|
navigationService.navigateInternally(this.history, SuperSelectionAppRoutes.Prefill);
|
|
7989
8044
|
}
|