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