@typed/io
Version:
Runtime IO type system
32 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.remoteData = exports.RemoteData = void 0;
const either_1 = require("@typed/either");
const remote_data_1 = require("@typed/remote-data");
const strings_1 = require("@typed/strings");
const G = require("../guard/RemoteData");
const Decoder_1 = require("./Decoder");
const refinement_1 = require("./refinement");
const _RemoteData = Decoder_1.Decoder.fromGuard(G.RemoteData, `RemoteData<unknown unknown>`);
exports.RemoteData = _RemoteData;
exports.remoteData = (l, r) => {
const expected = `RemoteData<${l.expected}, ${r.expected}>`;
return refinement_1.refinement(_RemoteData, function* (rd) {
if (remote_data_1.isFailure(rd)) {
const either = yield* Decoder_1.catchDecodeFailure(l.decode(rd.value));
if (either_1.isRight(either)) {
return remote_data_1.RemoteData.failure(either_1.fromRight(either));
}
return yield* Decoder_1.decodeFailure(Decoder_1.DecodeError.create(expected, `Failure<${strings_1.toString(rd.value)}>`));
}
if (remote_data_1.isSuccess(rd)) {
const either = yield* Decoder_1.catchDecodeFailure(r.decode(rd.value));
if (either_1.isRight(either)) {
return remote_data_1.RemoteData.of(either_1.fromRight(either));
}
return yield* Decoder_1.decodeFailure(Decoder_1.DecodeError.create(expected, `Success<${strings_1.toString(rd.value)}>`));
}
return rd;
}, expected);
};
//# sourceMappingURL=RemoteData.js.map