effect
Version:
The missing standard library for TypeScript, for writing production-grade software.
84 lines (83 loc) • 3.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.unnested = exports.patch = exports.nested = exports.mapName = exports.empty = exports.andThen = void 0;
var RA = _interopRequireWildcard(require("../../Array.js"));
var Either = _interopRequireWildcard(require("../../Either.js"));
var _Function = require("../../Function.js");
var List = _interopRequireWildcard(require("../../List.js"));
var Option = _interopRequireWildcard(require("../../Option.js"));
var configError = _interopRequireWildcard(require("../configError.js"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/** @internal */
const empty = exports.empty = {
_tag: "Empty"
};
/** @internal */
const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => ({
_tag: "AndThen",
first: self,
second: that
}));
/** @internal */
const mapName = exports.mapName = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => andThen(self, {
_tag: "MapName",
f
}));
/** @internal */
const nested = exports.nested = /*#__PURE__*/(0, _Function.dual)(2, (self, name) => andThen(self, {
_tag: "Nested",
name
}));
/** @internal */
const unnested = exports.unnested = /*#__PURE__*/(0, _Function.dual)(2, (self, name) => andThen(self, {
_tag: "Unnested",
name
}));
/** @internal */
const patch = exports.patch = /*#__PURE__*/(0, _Function.dual)(2, (path, patch) => {
let input = List.of(patch);
let output = path;
while (List.isCons(input)) {
const patch = input.head;
switch (patch._tag) {
case "Empty":
{
input = input.tail;
break;
}
case "AndThen":
{
input = List.cons(patch.first, List.cons(patch.second, input.tail));
break;
}
case "MapName":
{
output = RA.map(output, patch.f);
input = input.tail;
break;
}
case "Nested":
{
output = RA.prepend(output, patch.name);
input = input.tail;
break;
}
case "Unnested":
{
const containsName = (0, _Function.pipe)(RA.head(output), Option.contains(patch.name));
if (containsName) {
output = RA.tailNonEmpty(output);
input = input.tail;
} else {
return Either.left(configError.MissingData(output, `Expected ${patch.name} to be in path in ConfigProvider#unnested`));
}
break;
}
}
}
return Either.right(output);
});
//# sourceMappingURL=pathPatch.js.map