UNPKG

veffect

Version:

powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha

107 lines (106 loc) 3.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unnested = exports.patch = exports.nested = exports.mapName = exports.empty = exports.andThen = void 0; var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../Either.js")); var _Function = /*#__PURE__*/require("../../Function.js"); var List = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../List.js")); var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../Option.js")); var RA = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../ReadonlyArray.js")); var configError = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/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