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

246 lines (245 loc) 6.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unsafeTrack = exports.track = exports.supervisorVariance = exports.none = exports.isZip = exports.fromEffect = exports.fibersIn = exports.Zip = exports.Track = exports.SupervisorTypeId = exports.ProxySupervisor = exports.Const = void 0; var _Function = /*#__PURE__*/require("../Function.js"); var _GlobalValue = /*#__PURE__*/require("../GlobalValue.js"); var MutableRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../MutableRef.js")); var _Predicate = /*#__PURE__*/require("../Predicate.js"); var SortedSet = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../SortedSet.js")); var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./core.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 SupervisorSymbolKey = "effect/Supervisor"; /** @internal */ const SupervisorTypeId = exports.SupervisorTypeId = /*#__PURE__*/Symbol.for(SupervisorSymbolKey); /** @internal */ const supervisorVariance = exports.supervisorVariance = { /* c8 ignore next */ _T: _ => _ }; /** @internal */ class ProxySupervisor { underlying; value0; [SupervisorTypeId] = supervisorVariance; constructor(underlying, value0) { this.underlying = underlying; this.value0 = value0; } get value() { return this.value0; } onStart(context, effect, parent, fiber) { this.underlying.onStart(context, effect, parent, fiber); } onEnd(value, fiber) { this.underlying.onEnd(value, fiber); } onEffect(fiber, effect) { this.underlying.onEffect(fiber, effect); } onSuspend(fiber) { this.underlying.onSuspend(fiber); } onResume(fiber) { this.underlying.onResume(fiber); } map(f) { return new ProxySupervisor(this, (0, _Function.pipe)(this.value, core.map(f))); } zip(right) { return new Zip(this, right); } } /** @internal */ exports.ProxySupervisor = ProxySupervisor; class Zip { left; right; _tag = "Zip"; [SupervisorTypeId] = supervisorVariance; constructor(left, right) { this.left = left; this.right = right; } get value() { return core.zip(this.left.value, this.right.value); } onStart(context, effect, parent, fiber) { this.left.onStart(context, effect, parent, fiber); this.right.onStart(context, effect, parent, fiber); } onEnd(value, fiber) { this.left.onEnd(value, fiber); this.right.onEnd(value, fiber); } onEffect(fiber, effect) { this.left.onEffect(fiber, effect); this.right.onEffect(fiber, effect); } onSuspend(fiber) { this.left.onSuspend(fiber); this.right.onSuspend(fiber); } onResume(fiber) { this.left.onResume(fiber); this.right.onResume(fiber); } map(f) { return new ProxySupervisor(this, (0, _Function.pipe)(this.value, core.map(f))); } zip(right) { return new Zip(this, right); } } /** @internal */ exports.Zip = Zip; const isZip = self => (0, _Predicate.hasProperty)(self, SupervisorTypeId) && (0, _Predicate.isTagged)(self, "Zip"); /** @internal */ exports.isZip = isZip; class Track { [SupervisorTypeId] = supervisorVariance; fibers = new Set(); get value() { return core.sync(() => Array.from(this.fibers)); } onStart(_context, _effect, _parent, fiber) { this.fibers.add(fiber); } onEnd(_value, fiber) { this.fibers.delete(fiber); } onEffect(_fiber, _effect) { // } onSuspend(_fiber) { // } onResume(_fiber) { // } map(f) { return new ProxySupervisor(this, (0, _Function.pipe)(this.value, core.map(f))); } zip(right) { return new Zip(this, right); } onRun(execution, _fiber) { return execution(); } } /** @internal */ exports.Track = Track; class Const { effect; [SupervisorTypeId] = supervisorVariance; constructor(effect) { this.effect = effect; } get value() { return this.effect; } onStart(_context, _effect, _parent, _fiber) { // } onEnd(_value, _fiber) { // } onEffect(_fiber, _effect) { // } onSuspend(_fiber) { // } onResume(_fiber) { // } map(f) { return new ProxySupervisor(this, (0, _Function.pipe)(this.value, core.map(f))); } zip(right) { return new Zip(this, right); } onRun(execution, _fiber) { return execution(); } } exports.Const = Const; class FibersIn { ref; [SupervisorTypeId] = supervisorVariance; constructor(ref) { this.ref = ref; } get value() { return core.sync(() => MutableRef.get(this.ref)); } onStart(_context, _effect, _parent, fiber) { (0, _Function.pipe)(this.ref, MutableRef.set((0, _Function.pipe)(MutableRef.get(this.ref), SortedSet.add(fiber)))); } onEnd(_value, fiber) { (0, _Function.pipe)(this.ref, MutableRef.set((0, _Function.pipe)(MutableRef.get(this.ref), SortedSet.remove(fiber)))); } onEffect(_fiber, _effect) { // } onSuspend(_fiber) { // } onResume(_fiber) { // } map(f) { return new ProxySupervisor(this, (0, _Function.pipe)(this.value, core.map(f))); } zip(right) { return new Zip(this, right); } onRun(execution, _fiber) { return execution(); } } /** @internal */ const unsafeTrack = () => { return new Track(); }; /** @internal */ exports.unsafeTrack = unsafeTrack; const track = exports.track = /*#__PURE__*/core.sync(unsafeTrack); /** @internal */ const fromEffect = effect => { return new Const(effect); }; /** @internal */ exports.fromEffect = fromEffect; const none = exports.none = /*#__PURE__*/(0, _GlobalValue.globalValue)("effect/Supervisor/none", () => fromEffect(core.unit)); /** @internal */ const fibersIn = ref => core.sync(() => new FibersIn(ref)); exports.fibersIn = fibersIn; //# sourceMappingURL=supervisor.js.map