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
99 lines (98 loc) • 3.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.zip = exports.retry = exports.pollAndUpdate = exports.poll = exports.make = exports.launch = exports.collectAll = exports.MetricPollingTypeId = void 0;
var _Function = /*#__PURE__*/require("../../Function.js");
var _Pipeable = /*#__PURE__*/require("../../Pipeable.js");
var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../core.js"));
var circular = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../effect/circular.js"));
var metric = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../metric.js"));
var schedule = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../schedule.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 MetricPollingSymbolKey = "effect/MetricPolling";
/** @internal */
const MetricPollingTypeId = exports.MetricPollingTypeId = /*#__PURE__*/Symbol.for(MetricPollingSymbolKey);
/** @internal */
const make = (metric, poll) => {
return {
[MetricPollingTypeId]: MetricPollingTypeId,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
},
metric,
poll
};
};
/** @internal */
exports.make = make;
const collectAll = iterable => {
const metrics = Array.from(iterable);
return {
[MetricPollingTypeId]: MetricPollingTypeId,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
},
metric: metric.make(Array.of(void 0), (inputs, extraTags) => {
for (let i = 0; i < inputs.length; i++) {
const pollingMetric = metrics[i];
const input = (0, _Function.pipe)(inputs, x => x[i]);
pollingMetric.metric.unsafeUpdate(input, extraTags);
}
}, extraTags => Array.from(metrics.map(pollingMetric => pollingMetric.metric.unsafeValue(extraTags)))),
poll: core.forEachSequential(metrics, metric => metric.poll)
};
};
/** @internal */
exports.collectAll = collectAll;
const launch = exports.launch = /*#__PURE__*/(0, _Function.dual)(2, (self, schedule) => (0, _Function.pipe)(pollAndUpdate(self), core.zipRight(metric.value(self.metric)), circular.scheduleForked(schedule)));
/** @internal */
const poll = self => self.poll;
/** @internal */
exports.poll = poll;
const pollAndUpdate = self => core.flatMap(self.poll, value => metric.update(self.metric, value));
/** @internal */
exports.pollAndUpdate = pollAndUpdate;
const retry = exports.retry = /*#__PURE__*/(0, _Function.dual)(2, (self, policy) => ({
[MetricPollingTypeId]: MetricPollingTypeId,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
},
metric: self.metric,
poll: schedule.retry_Effect(self.poll, policy)
}));
/** @internal */
const zip = exports.zip = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => ({
[MetricPollingTypeId]: MetricPollingTypeId,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
},
metric: (0, _Function.pipe)(self.metric, metric.zip(that.metric)),
poll: core.zip(self.poll, that.poll)
}));
//# sourceMappingURL=polling.js.map