@flarehr/apollo-super-selection 1.3.40541 → 1.3.40557

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