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
1,117 lines (1,115 loc) • 71.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.exitInterrupt = exports.exitGetOrElse = exports.exitFromOption = exports.exitFromEither = exports.exitForEachEffect = exports.exitFlatten = exports.exitFlatMapEffect = exports.exitFlatMap = exports.exitFailCause = exports.exitFail = exports.exitExists = exports.exitDie = exports.exitCollectAll = exports.exitCauseOption = exports.exitAsUnit = exports.exitAs = exports.exit = exports.either = exports.dieSync = exports.dieMessage = exports.die = exports.deferredUnsafeMake = exports.deferredUnsafeDone = exports.deferredSync = exports.deferredSucceed = exports.deferredPoll = exports.deferredMakeAs = exports.deferredMake = exports.deferredIsDone = exports.deferredInterruptWith = exports.deferredInterrupt = exports.deferredFailSync = exports.deferredFailCauseSync = exports.deferredFailCause = exports.deferredFail = exports.deferredDone = exports.deferredDieSync = exports.deferredDie = exports.deferredCompleteWith = exports.deferredComplete = exports.deferredAwait = exports.custom = exports.currentUnhandledErrorLogLevel = exports.currentTracerTimingEnabled = exports.currentTracerSpanLinks = exports.currentTracerSpanAnnotations = exports.currentTracerEnabled = exports.currentSpanFromFiber = exports.currentSchedulingPriority = exports.currentRequestBatching = exports.currentMetricLabels = exports.currentMaxOpsBeforeYield = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentInterruptedCause = exports.currentForkScopeOverride = exports.currentContext = exports.currentConcurrency = exports.contextWithEffect = exports.contextWith = exports.context = exports.checkInterruptible = exports.causeSquashWith = exports.causeSquash = exports.catchSome = exports.catchIf = exports.catchAllCause = exports.catchAll = exports.blocked = exports.attemptOrElse = exports.async = exports.asUnit = exports.as = exports.andThen = exports.allLogLevels = exports.acquireUseRelease = exports.YieldableError = exports.UnknownExceptionTypeId = exports.UnknownException = exports.TimeoutExceptionTypeId = exports.TimeoutException = exports.ScopeTypeId = exports.RuntimeExceptionTypeId = exports.RuntimeException = exports.RevertFlags = exports.RequestResolverTypeId = exports.RequestResolverImpl = exports.NoSuchElementExceptionTypeId = exports.NoSuchElementException = exports.InvalidPubSubCapacityExceptionTypeId = exports.InvalidPubSubCapacityException = exports.InterruptedExceptionTypeId = exports.InterruptedException = exports.IllegalArgumentExceptionTypeId = exports.IllegalArgumentException = exports.FiberRefTypeId = exports.EffectTypeId = exports.EffectErrorTypeId = exports.CloseableScopeTypeId = void 0;
exports.requestBlockLocally = exports.provideSomeContext = exports.provideContext = exports.partitionMap = exports.originalInstance = exports.orElse = exports.orDieWith = exports.orDie = exports.onInterrupt = exports.onExit = exports.onError = exports.noopSpan = exports.never = exports.metricLabels = exports.matchEffect = exports.matchCauseEffect = exports.matchCause = exports.mapInputContext = exports.mapError = exports.mapBoth = exports.map = exports.makeEffectError = exports.logLevelWarning = exports.logLevelTrace = exports.logLevelNone = exports.logLevelInfo = exports.logLevelFatal = exports.logLevelError = exports.logLevelDebug = exports.logLevelAll = exports.isUnknownException = exports.isTimeoutException = exports.isRuntimeException = exports.isRequestResolver = exports.isNoSuchElementException = exports.isInvalidCapacityError = exports.isInterruptedException = exports.isIllegalArgumentException = exports.isEffectError = exports.isEffect = exports.intoDeferred = exports.interruptibleMask = exports.interruptible = exports.interruptWith = exports.interruptFiber = exports.interruptAsFiber = exports.interrupt = exports.if_ = exports.forEachSequentialDiscard = exports.forEachSequential = exports.flip = exports.flatten = exports.flatMap = exports.fiberRefUpdateSomeAndGet = exports.fiberRefUpdateSome = exports.fiberRefUpdateAndGet = exports.fiberRefUpdate = exports.fiberRefUnsafeMakeRuntimeFlags = exports.fiberRefUnsafeMakeReadonlyArray = exports.fiberRefUnsafeMakePatch = exports.fiberRefUnsafeMakeHashSet = exports.fiberRefUnsafeMakeContext = exports.fiberRefUnsafeMake = exports.fiberRefSet = exports.fiberRefReset = exports.fiberRefModifySome = exports.fiberRefModify = exports.fiberRefLocallyWith = exports.fiberRefLocally = exports.fiberRefGetWith = exports.fiberRefGetAndUpdateSome = exports.fiberRefGetAndUpdate = exports.fiberRefGetAndSet = exports.fiberRefGet = exports.fiberRefDelete = exports.fiberIdWith = exports.fiberId = exports.failSync = exports.failCauseSync = exports.failCause = exports.fail = exports.exitZipWith = exports.exitZipRight = exports.exitZipParRight = exports.exitZipParLeft = exports.exitZipPar = exports.exitZipLeft = exports.exitZip = exports.exitUnit = exports.exitSucceed = exports.exitMatchEffect = exports.exitMatch = exports.exitMapErrorCause = exports.exitMapError = exports.exitMapBoth = exports.exitMap = exports.exitIsSuccess = exports.exitIsInterrupted = exports.exitIsFailure = exports.exitIsExit = void 0;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zipFlatten = exports.zip = exports.yieldNow = exports.withUnhandledErrorLogLevel = exports.withTracerTiming = exports.withTracerEnabled = exports.withSchedulingPriority = exports.withRuntimeFlags = exports.withRequestBatching = exports.withMaxOpsBeforeYield = exports.withFiberRuntime = exports.withConcurrency = exports.whileLoop = exports.whenEffect = exports.updateRuntimeFlags = exports.unit = exports.uninterruptibleMask = exports.uninterruptible = exports.transplant = exports.tap = exports.sync = exports.suspend = exports.succeed = exports.step = exports.scopeFork = exports.scopeClose = exports.scopeAddFinalizerExit = exports.scopeAddFinalizer = exports.runtimeFlags = exports.runRequestBlock = exports.resolverLocally = void 0;
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Chunk.js"));
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Context.js"));
var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Either.js"));
var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Equal.js"));
var FiberId = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../FiberId.js"));
var _Function = /*#__PURE__*/require("../Function.js");
var _GlobalValue = /*#__PURE__*/require("../GlobalValue.js");
var Hash = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Hash.js"));
var HashMap = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../HashMap.js"));
var _Inspectable = /*#__PURE__*/require("../Inspectable.js");
var List = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../List.js"));
var MutableRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../MutableRef.js"));
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../Option.js"));
var _Pipeable = /*#__PURE__*/require("../Pipeable.js");
var _Predicate = /*#__PURE__*/require("../Predicate.js");
var ReadonlyArray = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../ReadonlyArray.js"));
var RuntimeFlagsPatch = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../RuntimeFlagsPatch.js"));
var _blockedRequests = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./blockedRequests.js"));
var internalCause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./cause.js"));
var deferred = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./deferred.js"));
var internalDiffer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./differ.js"));
var _effectable = /*#__PURE__*/require("./effectable.js");
var _errors = /*#__PURE__*/require("./errors.js");
var DeferredOpCodes = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./opCodes/deferred.js"));
var OpCodes = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./opCodes/effect.js"));
var _runtimeFlags = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./runtimeFlags.js"));
var internalTracer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./tracer.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;
}
// -----------------------------------------------------------------------------
// Effect
// -----------------------------------------------------------------------------
/** @internal */
const EffectErrorSymbolKey = "effect/EffectError";
/** @internal */
const EffectErrorTypeId = exports.EffectErrorTypeId = /*#__PURE__*/Symbol.for(EffectErrorSymbolKey);
/** @internal */
const isEffectError = u => (0, _Predicate.hasProperty)(u, EffectErrorTypeId);
/** @internal */
exports.isEffectError = isEffectError;
const makeEffectError = cause => ({
[EffectErrorTypeId]: EffectErrorTypeId,
_tag: "EffectError",
cause
});
/**
* @internal
*/
exports.makeEffectError = makeEffectError;
const blocked = (blockedRequests, _continue) => {
const effect = new EffectPrimitive("Blocked");
effect.effect_instruction_i0 = blockedRequests;
effect.effect_instruction_i1 = _continue;
return effect;
};
/**
* @internal
*/
exports.blocked = blocked;
const runRequestBlock = blockedRequests => {
const effect = new EffectPrimitive("RunBlocked");
effect.effect_instruction_i0 = blockedRequests;
return effect;
};
/** @internal */
exports.runRequestBlock = runRequestBlock;
const EffectTypeId = exports.EffectTypeId = /*#__PURE__*/Symbol.for("effect/Effect");
/** @internal */
class RevertFlags {
patch;
op;
_op = OpCodes.OP_REVERT_FLAGS;
constructor(patch, op) {
this.patch = patch;
this.op = op;
}
}
/** @internal */
exports.RevertFlags = RevertFlags;
class EffectPrimitive {
_op;
effect_instruction_i0 = undefined;
effect_instruction_i1 = undefined;
effect_instruction_i2 = undefined;
trace = undefined;
[EffectTypeId] = _effectable.effectVariance;
constructor(_op) {
this._op = _op;
}
[Equal.symbol](that) {
return this === that;
}
[Hash.symbol]() {
return Hash.cached(this, Hash.random(this));
}
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
toJSON() {
return {
_id: "Effect",
_op: this._op,
effect_instruction_i0: (0, _Inspectable.toJSON)(this.effect_instruction_i0),
effect_instruction_i1: (0, _Inspectable.toJSON)(this.effect_instruction_i1),
effect_instruction_i2: (0, _Inspectable.toJSON)(this.effect_instruction_i2)
};
}
toString() {
return (0, _Inspectable.format)(this.toJSON());
}
[_Inspectable.NodeInspectSymbol]() {
return this.toJSON();
}
}
/** @internal */
class EffectPrimitiveFailure {
_op;
effect_instruction_i0 = undefined;
effect_instruction_i1 = undefined;
effect_instruction_i2 = undefined;
trace = undefined;
[EffectTypeId] = _effectable.effectVariance;
constructor(_op) {
this._op = _op;
// @ts-expect-error
this._tag = _op;
}
[Equal.symbol](that) {
return this === that;
}
[Hash.symbol]() {
return Hash.cached(this, Hash.random(this));
}
get cause() {
return this.effect_instruction_i0;
}
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
toJSON() {
return {
_id: "Exit",
_tag: this._op,
cause: this.cause.toJSON()
};
}
toString() {
return (0, _Inspectable.format)(this.toJSON());
}
[_Inspectable.NodeInspectSymbol]() {
return this.toJSON();
}
}
/** @internal */
class EffectPrimitiveSuccess {
_op;
effect_instruction_i0 = undefined;
effect_instruction_i1 = undefined;
effect_instruction_i2 = undefined;
trace = undefined;
[EffectTypeId] = _effectable.effectVariance;
constructor(_op) {
this._op = _op;
// @ts-expect-error
this._tag = _op;
}
[Equal.symbol](that) {
return this === that;
}
[Hash.symbol]() {
return Hash.cached(this, Hash.random(this));
}
get value() {
return this.effect_instruction_i0;
}
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
toJSON() {
return {
_id: "Exit",
_tag: this._op,
value: (0, _Inspectable.toJSON)(this.value)
};
}
toString() {
return (0, _Inspectable.format)(this.toJSON());
}
[_Inspectable.NodeInspectSymbol]() {
return this.toJSON();
}
}
/** @internal */
const isEffect = u => (0, _Predicate.hasProperty)(u, EffectTypeId);
/* @internal */
exports.isEffect = isEffect;
const withFiberRuntime = withRuntime => {
const effect = new EffectPrimitive(OpCodes.OP_WITH_RUNTIME);
effect.effect_instruction_i0 = withRuntime;
return effect;
};
/* @internal */
exports.withFiberRuntime = withFiberRuntime;
const acquireUseRelease = exports.acquireUseRelease = /*#__PURE__*/(0, _Function.dual)(3, (acquire, use, release) => uninterruptibleMask(restore => flatMap(acquire, a => flatMap(exit(suspend(() => restore(use(a)))), exit => {
return suspend(() => release(a, exit)).pipe(matchCauseEffect({
onFailure: cause => {
switch (exit._tag) {
case OpCodes.OP_FAILURE:
return failCause(internalCause.parallel(exit.effect_instruction_i0, cause));
case OpCodes.OP_SUCCESS:
return failCause(cause);
}
},
onSuccess: () => exit
}));
}))));
/* @internal */
const as = exports.as = /*#__PURE__*/(0, _Function.dual)(2, (self, value) => flatMap(self, () => succeed(value)));
/* @internal */
const asUnit = self => as(self, void 0);
/* @internal */
exports.asUnit = asUnit;
const custom = function () {
const wrapper = new EffectPrimitive(OpCodes.OP_COMMIT);
switch (arguments.length) {
case 2:
{
wrapper.effect_instruction_i0 = arguments[0];
wrapper.commit = arguments[1];
break;
}
case 3:
{
wrapper.effect_instruction_i0 = arguments[0];
wrapper.effect_instruction_i1 = arguments[1];
wrapper.commit = arguments[2];
break;
}
case 4:
{
wrapper.effect_instruction_i0 = arguments[0];
wrapper.effect_instruction_i1 = arguments[1];
wrapper.effect_instruction_i2 = arguments[2];
wrapper.commit = arguments[3];
break;
}
default:
{
throw new Error((0, _errors.getBugErrorMessage)("you're not supposed to end up here"));
}
}
return wrapper;
};
/* @internal */
exports.custom = custom;
const async = (register, blockingOn = FiberId.none) => {
return custom(register, function () {
let backingResume = undefined;
let pendingEffect = undefined;
function proxyResume(effect) {
if (backingResume) {
backingResume(effect);
} else if (pendingEffect === undefined) {
pendingEffect = effect;
}
}
const effect = new EffectPrimitive(OpCodes.OP_ASYNC);
effect.effect_instruction_i0 = resume => {
backingResume = resume;
if (pendingEffect) {
resume(pendingEffect);
}
};
effect.effect_instruction_i1 = blockingOn;
let cancelerRef = undefined;
let controllerRef = undefined;
if (this.effect_instruction_i0.length !== 1) {
controllerRef = new AbortController();
cancelerRef = this.effect_instruction_i0(proxyResume, controllerRef.signal);
} else {
cancelerRef = this.effect_instruction_i0(proxyResume);
}
return cancelerRef || controllerRef ? onInterrupt(effect, _ => {
if (controllerRef) {
controllerRef.abort();
}
return cancelerRef ?? unit;
}) : effect;
});
};
/* @internal */
exports.async = async;
const catchAllCause = exports.catchAllCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
const effect = new EffectPrimitive(OpCodes.OP_ON_FAILURE);
effect.effect_instruction_i0 = self;
effect.effect_instruction_i1 = f;
return effect;
});
/* @internal */
const catchAll = exports.catchAll = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => matchEffect(self, {
onFailure: f,
onSuccess: succeed
}));
/* @internal */
const catchIf = exports.catchIf = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, f) => catchAllCause(self, cause => {
const either = internalCause.failureOrCause(cause);
switch (either._tag) {
case "Left":
return predicate(either.left) ? f(either.left) : failCause(cause);
case "Right":
return failCause(either.right);
}
}));
/* @internal */
const catchSome = exports.catchSome = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => catchAllCause(self, cause => {
const either = internalCause.failureOrCause(cause);
switch (either._tag) {
case "Left":
return (0, _Function.pipe)(pf(either.left), Option.getOrElse(() => failCause(cause)));
case "Right":
return failCause(either.right);
}
}));
/* @internal */
const checkInterruptible = f => withFiberRuntime((_, status) => f(_runtimeFlags.interruption(status.runtimeFlags)));
exports.checkInterruptible = checkInterruptible;
const spanSymbol = /*#__PURE__*/Symbol.for("effect/SpanAnnotation");
const originalSymbol = /*#__PURE__*/Symbol.for("effect/OriginalAnnotation");
/* @internal */
const originalInstance = obj => {
if ((0, _Predicate.hasProperty)(obj, originalSymbol)) {
// @ts-expect-error
return obj[originalSymbol];
}
return obj;
};
/* @internal */
exports.originalInstance = originalInstance;
const capture = (obj, span) => {
if (Option.isSome(span)) {
return new Proxy(obj, {
has(target, p) {
return p === spanSymbol || p === originalSymbol || p in target;
},
get(target, p) {
if (p === spanSymbol) {
return span.value;
}
if (p === originalSymbol) {
return obj;
}
// @ts-expect-error
return target[p];
}
});
}
return obj;
};
/* @internal */
const die = defect => (0, _Predicate.isObject)(defect) && !(spanSymbol in defect) ? withFiberRuntime(fiber => failCause(internalCause.die(capture(defect, currentSpanFromFiber(fiber))))) : failCause(internalCause.die(defect));
/* @internal */
exports.die = die;
const dieMessage = message => failCauseSync(() => internalCause.die(new RuntimeException(message)));
/* @internal */
exports.dieMessage = dieMessage;
const dieSync = evaluate => flatMap(sync(evaluate), die);
/* @internal */
exports.dieSync = dieSync;
const either = self => matchEffect(self, {
onFailure: e => succeed(Either.left(e)),
onSuccess: a => succeed(Either.right(a))
});
/* @internal */
exports.either = either;
const exit = self => matchCause(self, {
onFailure: exitFailCause,
onSuccess: exitSucceed
});
/* @internal */
exports.exit = exit;
const fail = error => (0, _Predicate.isObject)(error) && !(spanSymbol in error) ? withFiberRuntime(fiber => failCause(internalCause.fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(internalCause.fail(error));
/* @internal */
exports.fail = fail;
const failSync = evaluate => flatMap(sync(evaluate), fail);
/* @internal */
exports.failSync = failSync;
const failCause = cause => {
const effect = new EffectPrimitiveFailure(OpCodes.OP_FAILURE);
effect.effect_instruction_i0 = cause;
return effect;
};
/* @internal */
exports.failCause = failCause;
const failCauseSync = evaluate => flatMap(sync(evaluate), failCause);
/* @internal */
exports.failCauseSync = failCauseSync;
const fiberId = exports.fiberId = /*#__PURE__*/withFiberRuntime(state => succeed(state.id()));
/* @internal */
const fiberIdWith = f => withFiberRuntime(state => f(state.id()));
/* @internal */
exports.fiberIdWith = fiberIdWith;
const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
const effect = new EffectPrimitive(OpCodes.OP_ON_SUCCESS);
effect.effect_instruction_i0 = self;
effect.effect_instruction_i1 = f;
return effect;
});
/* @internal */
const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatMap(self, a => {
const b = typeof f === "function" ? f(a) : f;
if (isEffect(b)) {
return b;
} else if ((0, _Predicate.isPromiseLike)(b)) {
return async(resume => {
b.then(a => resume(succeed(a)), e => resume(fail(new UnknownException(e))));
});
}
return succeed(b);
}));
/* @internal */
const step = self => {
const effect = new EffectPrimitive("OnStep");
effect.effect_instruction_i0 = self;
return effect;
};
/* @internal */
exports.step = step;
const flatten = self => flatMap(self, _Function.identity);
/* @internal */
exports.flatten = flatten;
const flip = self => matchEffect(self, {
onFailure: succeed,
onSuccess: fail
});
/* @internal */
exports.flip = flip;
const matchCause = exports.matchCause = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchCauseEffect(self, {
onFailure: cause => succeed(options.onFailure(cause)),
onSuccess: a => succeed(options.onSuccess(a))
}));
/* @internal */
const matchCauseEffect = exports.matchCauseEffect = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => {
const effect = new EffectPrimitive(OpCodes.OP_ON_SUCCESS_AND_FAILURE);
effect.effect_instruction_i0 = self;
effect.effect_instruction_i1 = options.onFailure;
effect.effect_instruction_i2 = options.onSuccess;
return effect;
});
/* @internal */
const matchEffect = exports.matchEffect = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchCauseEffect(self, {
onFailure: cause => {
const defects = internalCause.defects(cause);
if (defects.length > 0) {
return failCause(internalCause.electFailures(cause));
}
const failures = internalCause.failures(cause);
if (failures.length > 0) {
return options.onFailure(Chunk.unsafeHead(failures));
}
return failCause(cause);
},
onSuccess: options.onSuccess
}));
/* @internal */
const forEachSequential = exports.forEachSequential = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => suspend(() => {
const arr = ReadonlyArray.fromIterable(self);
const ret = new Array(arr.length);
let i = 0;
return as(whileLoop({
while: () => i < arr.length,
body: () => f(arr[i], i),
step: b => {
ret[i++] = b;
}
}), ret);
}));
/* @internal */
const forEachSequentialDiscard = exports.forEachSequentialDiscard = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => suspend(() => {
const arr = ReadonlyArray.fromIterable(self);
let i = 0;
return whileLoop({
while: () => i < arr.length,
body: () => f(arr[i], i),
step: () => {
i++;
}
});
}));
/* @internal */
const if_ = exports.if_ = /*#__PURE__*/(0, _Function.dual)(args => typeof args[0] === "boolean" || isEffect(args[0]), (self, {
onFalse,
onTrue
}) => isEffect(self) ? flatMap(self, b => b ? onTrue : onFalse) : Boolean(self) ? onTrue : onFalse);
/* @internal */
const interrupt = exports.interrupt = /*#__PURE__*/flatMap(fiberId, fiberId => interruptWith(fiberId));
/* @internal */
const interruptWith = fiberId => failCause(internalCause.interrupt(fiberId));
/* @internal */
exports.interruptWith = interruptWith;
const interruptible = self => {
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS);
effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(_runtimeFlags.Interruption);
effect.effect_instruction_i1 = () => self;
return effect;
};
/* @internal */
exports.interruptible = interruptible;
const interruptibleMask = f => custom(f, function () {
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS);
effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(_runtimeFlags.Interruption);
effect.effect_instruction_i1 = oldFlags => _runtimeFlags.interruption(oldFlags) ? this.effect_instruction_i0(interruptible) : this.effect_instruction_i0(uninterruptible);
return effect;
});
/* @internal */
exports.interruptibleMask = interruptibleMask;
const intoDeferred = exports.intoDeferred = /*#__PURE__*/(0, _Function.dual)(2, (self, deferred) => uninterruptibleMask(restore => flatMap(exit(restore(self)), exit => deferredDone(deferred, exit))));
/* @internal */
const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatMap(self, a => sync(() => f(a))));
/* @internal */
const mapBoth = exports.mapBoth = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchEffect(self, {
onFailure: e => failSync(() => options.onFailure(e)),
onSuccess: a => sync(() => options.onSuccess(a))
}));
/* @internal */
const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => matchCauseEffect(self, {
onFailure: cause => {
const either = internalCause.failureOrCause(cause);
switch (either._tag) {
case "Left":
{
return failSync(() => f(either.left));
}
case "Right":
{
return failCause(either.right);
}
}
},
onSuccess: succeed
}));
/* @internal */
const onError = exports.onError = /*#__PURE__*/(0, _Function.dual)(2, (self, cleanup) => onExit(self, exit => exitIsSuccess(exit) ? unit : cleanup(exit.effect_instruction_i0)));
/* @internal */
const onExit = exports.onExit = /*#__PURE__*/(0, _Function.dual)(2, (self, cleanup) => uninterruptibleMask(restore => matchCauseEffect(restore(self), {
onFailure: cause1 => {
const result = exitFailCause(cause1);
return matchCauseEffect(cleanup(result), {
onFailure: cause2 => exitFailCause(internalCause.sequential(cause1, cause2)),
onSuccess: () => result
});
},
onSuccess: success => {
const result = exitSucceed(success);
return zipRight(cleanup(result), result);
}
})));
/* @internal */
const onInterrupt = exports.onInterrupt = /*#__PURE__*/(0, _Function.dual)(2, (self, cleanup) => onExit(self, exitMatch({
onFailure: cause => internalCause.isInterruptedOnly(cause) ? asUnit(cleanup(internalCause.interruptors(cause))) : unit,
onSuccess: () => unit
})));
/* @internal */
const orElse = exports.orElse = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => attemptOrElse(self, that, succeed));
/* @internal */
const orDie = self => orDieWith(self, _Function.identity);
/* @internal */
exports.orDie = orDie;
const orDieWith = exports.orDieWith = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => matchEffect(self, {
onFailure: e => die(f(e)),
onSuccess: succeed
}));
/* @internal */
const partitionMap = (elements, f) => ReadonlyArray.fromIterable(elements).reduceRight(([lefts, rights], current) => {
const either = f(current);
switch (either._tag) {
case "Left":
{
return [[either.left, ...lefts], rights];
}
case "Right":
{
return [lefts, [either.right, ...rights]];
}
}
}, [new Array(), new Array()]);
/* @internal */
exports.partitionMap = partitionMap;
const runtimeFlags = exports.runtimeFlags = /*#__PURE__*/withFiberRuntime((_, status) => succeed(status.runtimeFlags));
/* @internal */
const succeed = value => {
const effect = new EffectPrimitiveSuccess(OpCodes.OP_SUCCESS);
effect.effect_instruction_i0 = value;
return effect;
};
/* @internal */
exports.succeed = succeed;
const suspend = effect => flatMap(sync(effect), _Function.identity);
/* @internal */
exports.suspend = suspend;
const sync = evaluate => {
const effect = new EffectPrimitive(OpCodes.OP_SYNC);
effect.effect_instruction_i0 = evaluate;
return effect;
};
/* @internal */
exports.sync = sync;
const tap = exports.tap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatMap(self, a => {
const b = typeof f === "function" ? f(a) : f;
if (isEffect(b)) {
return as(b, a);
} else if ((0, _Predicate.isPromiseLike)(b)) {
return async(resume => {
b.then(_ => resume(succeed(a)), e => resume(fail(new UnknownException(e))));
});
}
return succeed(a);
}));
/* @internal */
const transplant = f => withFiberRuntime(state => {
const scopeOverride = state.getFiberRef(currentForkScopeOverride);
const scope = (0, _Function.pipe)(scopeOverride, Option.getOrElse(() => state.scope()));
return f(fiberRefLocally(currentForkScopeOverride, Option.some(scope)));
});
/* @internal */
exports.transplant = transplant;
const attemptOrElse = exports.attemptOrElse = /*#__PURE__*/(0, _Function.dual)(3, (self, that, onSuccess) => matchCauseEffect(self, {
onFailure: cause => {
const defects = internalCause.defects(cause);
if (defects.length > 0) {
return failCause(Option.getOrThrow(internalCause.keepDefectsAndElectFailures(cause)));
}
return that();
},
onSuccess
}));
/* @internal */
const uninterruptible = self => {
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS);
effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(_runtimeFlags.Interruption);
effect.effect_instruction_i1 = () => self;
return effect;
};
/* @internal */
exports.uninterruptible = uninterruptible;
const uninterruptibleMask = f => custom(f, function () {
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS);
effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(_runtimeFlags.Interruption);
effect.effect_instruction_i1 = oldFlags => _runtimeFlags.interruption(oldFlags) ? this.effect_instruction_i0(interruptible) : this.effect_instruction_i0(uninterruptible);
return effect;
});
/* @internal */
exports.uninterruptibleMask = uninterruptibleMask;
const unit = exports.unit = /*#__PURE__*/succeed(void 0);
/* @internal */
const updateRuntimeFlags = patch => {
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS);
effect.effect_instruction_i0 = patch;
effect.effect_instruction_i1 = void 0;
return effect;
};
/* @internal */
exports.updateRuntimeFlags = updateRuntimeFlags;
const whenEffect = exports.whenEffect = /*#__PURE__*/(0, _Function.dual)(2, (self, condition) => flatMap(condition, b => {
if (b) {
return (0, _Function.pipe)(self, map(Option.some));
}
return succeed(Option.none());
}));
/* @internal */
const whileLoop = options => {
const effect = new EffectPrimitive(OpCodes.OP_WHILE);
effect.effect_instruction_i0 = options.while;
effect.effect_instruction_i1 = options.body;
effect.effect_instruction_i2 = options.step;
return effect;
};
/* @internal */
exports.whileLoop = whileLoop;
const withConcurrency = exports.withConcurrency = /*#__PURE__*/(0, _Function.dual)(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency));
/* @internal */
const withRequestBatching = exports.withRequestBatching = /*#__PURE__*/(0, _Function.dual)(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching));
/* @internal */
const withRuntimeFlags = exports.withRuntimeFlags = /*#__PURE__*/(0, _Function.dual)(2, (self, update) => {
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS);
effect.effect_instruction_i0 = update;
effect.effect_instruction_i1 = () => self;
return effect;
});
/** @internal */
const withTracerEnabled = exports.withTracerEnabled = /*#__PURE__*/(0, _Function.dual)(2, (effect, enabled) => fiberRefLocally(effect, currentTracerEnabled, enabled));
/** @internal */
const withTracerTiming = exports.withTracerTiming = /*#__PURE__*/(0, _Function.dual)(2, (effect, enabled) => fiberRefLocally(effect, currentTracerTimingEnabled, enabled));
/* @internal */
const yieldNow = options => {
const effect = new EffectPrimitive(OpCodes.OP_YIELD);
return typeof options?.priority !== "undefined" ? withSchedulingPriority(effect, options.priority) : effect;
};
/* @internal */
exports.yieldNow = yieldNow;
const zip = exports.zip = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatMap(self, a => map(that, b => [a, b])));
/* @internal */
const zipFlatten = exports.zipFlatten = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatMap(self, a => map(that, b => [...a, b])));
/* @internal */
const zipLeft = exports.zipLeft = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatMap(self, a => as(that, a)));
/* @internal */
const zipRight = exports.zipRight = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatMap(self, () => that));
/* @internal */
const zipWith = exports.zipWith = /*#__PURE__*/(0, _Function.dual)(3, (self, that, f) => flatMap(self, a => map(that, b => f(a, b))));
/* @internal */
const never = exports.never = /*#__PURE__*/async(() => {
const interval = setInterval(() => {
//
}, 2 ** 31 - 1);
return sync(() => clearInterval(interval));
});
// -----------------------------------------------------------------------------
// Fiber
// -----------------------------------------------------------------------------
/* @internal */
const interruptFiber = self => flatMap(fiberId, fiberId => (0, _Function.pipe)(self, interruptAsFiber(fiberId)));
/* @internal */
exports.interruptFiber = interruptFiber;
const interruptAsFiber = exports.interruptAsFiber = /*#__PURE__*/(0, _Function.dual)(2, (self, fiberId) => flatMap(self.interruptAsFork(fiberId), () => self.await));
// -----------------------------------------------------------------------------
// LogLevel
// -----------------------------------------------------------------------------
/** @internal */
const logLevelAll = exports.logLevelAll = {
_tag: "All",
syslog: 0,
label: "ALL",
ordinal: Number.MIN_SAFE_INTEGER,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelFatal = exports.logLevelFatal = {
_tag: "Fatal",
syslog: 2,
label: "FATAL",
ordinal: 50000,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelError = exports.logLevelError = {
_tag: "Error",
syslog: 3,
label: "ERROR",
ordinal: 40000,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelWarning = exports.logLevelWarning = {
_tag: "Warning",
syslog: 4,
label: "WARN",
ordinal: 30000,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelInfo = exports.logLevelInfo = {
_tag: "Info",
syslog: 6,
label: "INFO",
ordinal: 20000,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelDebug = exports.logLevelDebug = {
_tag: "Debug",
syslog: 7,
label: "DEBUG",
ordinal: 10000,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelTrace = exports.logLevelTrace = {
_tag: "Trace",
syslog: 7,
label: "TRACE",
ordinal: 0,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const logLevelNone = exports.logLevelNone = {
_tag: "None",
syslog: 7,
label: "OFF",
ordinal: Number.MAX_SAFE_INTEGER,
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
};
/** @internal */
const allLogLevels = exports.allLogLevels = [logLevelAll, logLevelTrace, logLevelDebug, logLevelInfo, logLevelWarning, logLevelError, logLevelFatal, logLevelNone];
// -----------------------------------------------------------------------------
// FiberRef
// -----------------------------------------------------------------------------
/** @internal */
const FiberRefSymbolKey = "effect/FiberRef";
/** @internal */
const FiberRefTypeId = exports.FiberRefTypeId = /*#__PURE__*/Symbol.for(FiberRefSymbolKey);
const fiberRefVariance = {
/* c8 ignore next */
_A: _ => _
};
/* @internal */
const fiberRefGet = self => fiberRefModify(self, a => [a, a]);
/* @internal */
exports.fiberRefGet = fiberRefGet;
const fiberRefGetAndSet = exports.fiberRefGetAndSet = /*#__PURE__*/(0, _Function.dual)(2, (self, value) => fiberRefModify(self, v => [v, value]));
/* @internal */
const fiberRefGetAndUpdate = exports.fiberRefGetAndUpdate = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => fiberRefModify(self, v => [v, f(v)]));
/* @internal */
const fiberRefGetAndUpdateSome = exports.fiberRefGetAndUpdateSome = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => fiberRefModify(self, v => [v, Option.getOrElse(pf(v), () => v)]));
/* @internal */
const fiberRefGetWith = exports.fiberRefGetWith = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatMap(fiberRefGet(self), f));
/* @internal */
const fiberRefSet = exports.fiberRefSet = /*#__PURE__*/(0, _Function.dual)(2, (self, value) => fiberRefModify(self, () => [void 0, value]));
/* @internal */
const fiberRefDelete = self => withFiberRuntime(state => {
state.unsafeDeleteFiberRef(self);
return unit;
});
/* @internal */
exports.fiberRefDelete = fiberRefDelete;
const fiberRefReset = self => fiberRefSet(self, self.initial);
/* @internal */
exports.fiberRefReset = fiberRefReset;
const fiberRefModify = exports.fiberRefModify = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => withFiberRuntime(state => {
const [b, a] = f(state.getFiberRef(self));
state.setFiberRef(self, a);
return succeed(b);
}));
/* @internal */
const fiberRefModifySome = (self, def, f) => fiberRefModify(self, v => Option.getOrElse(f(v), () => [def, v]));
/* @internal */
exports.fiberRefModifySome = fiberRefModifySome;
const fiberRefUpdate = exports.fiberRefUpdate = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => fiberRefModify(self, v => [void 0, f(v)]));
/* @internal */
const fiberRefUpdateSome = exports.fiberRefUpdateSome = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => fiberRefModify(self, v => [void 0, Option.getOrElse(pf(v), () => v)]));
/* @internal */
const fiberRefUpdateAndGet = exports.fiberRefUpdateAndGet = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => fiberRefModify(self, v => {
const result = f(v);
return [result, result];
}));
/* @internal */
const fiberRefUpdateSomeAndGet = exports.fiberRefUpdateSomeAndGet = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => fiberRefModify(self, v => {
const result = Option.getOrElse(pf(v), () => v);
return [result, result];
}));
// circular
/** @internal */
const RequestResolverSymbolKey = "effect/RequestResolver";
/** @internal */
const RequestResolverTypeId = exports.RequestResolverTypeId = /*#__PURE__*/Symbol.for(RequestResolverSymbolKey);
const requestResolverVariance = {
/* c8 ignore next */
_A: _ => _,
/* c8 ignore next */
_R: _ => _
};
/** @internal */
class RequestResolverImpl {
runAll;
target;
[RequestResolverTypeId] = requestResolverVariance;
constructor(runAll, target) {
this.runAll = runAll;
this.target = target;
this.runAll = runAll;
}
[Hash.symbol]() {
return Hash.cached(this, this.target ? Hash.hash(this.target) : Hash.random(this));
}
[Equal.symbol](that) {
return this.target ? isRequestResolver(that) && Equal.equals(this.target, that.target) : this === that;
}
identified(...ids) {
return new RequestResolverImpl(this.runAll, Chunk.fromIterable(ids));
}
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
}
/** @internal */
exports.RequestResolverImpl = RequestResolverImpl;
const isRequestResolver = u => (0, _Predicate.hasProperty)(u, RequestResolverTypeId);
// end
/** @internal */
exports.isRequestResolver = isRequestResolver;
const resolverLocally = exports.resolverLocally = /*#__PURE__*/(0, _Function.dual)(3, (use, self, value) => new RequestResolverImpl(requests => fiberRefLocally(use.runAll(requests), self, value), Chunk.make("Locally", use, self, value)));
/** @internal */
const requestBlockLocally = (self, ref, value) => _blockedRequests.reduce(self, LocallyReducer(ref, value));
exports.requestBlockLocally = requestBlockLocally;
const LocallyReducer = (ref, value) => ({
emptyCase: () => _blockedRequests.empty,
parCase: (left, right) => _blockedRequests.par(left, right),
seqCase: (left, right) => _blockedRequests.seq(left, right),
singleCase: (dataSource, blockedRequest) => _blockedRequests.single(resolverLocally(dataSource, ref, value), blockedRequest)
});
/* @internal */
const fiberRefLocally = exports.fiberRefLocally = /*#__PURE__*/(0, _Function.dual)(3, (use, self, value) => acquireUseRelease(zipLeft(fiberRefGet(self), fiberRefSet(self, value)), () => use, oldValue => fiberRefSet(self, oldValue)));
/* @internal */
const fiberRefLocallyWith = exports.fiberRefLocallyWith = /*#__PURE__*/(0, _Function.dual)(3, (use, self, f) => fiberRefGetWith(self, a => fiberRefLocally(use, self, f(a))));
/** @internal */
const fiberRefUnsafeMake = (initial, options) => fiberRefUnsafeMakePatch(initial, {
differ: internalDiffer.update(),
fork: options?.fork ?? _Function.identity,
join: options?.join
});
/** @internal */
exports.fiberRefUnsafeMake = fiberRefUnsafeMake;
const fiberRefUnsafeMakeHashSet = initial => {
const differ = internalDiffer.hashSet();
return fiberRefUnsafeMakePatch(initial, {
differ,
fork: differ.empty
});
};
/** @internal */
exports.fiberRefUnsafeMakeHashSet = fiberRefUnsafeMakeHashSet;
const fiberRefUnsafeMakeReadonlyArray = initial => {
const differ = internalDiffer.readonlyArray(internalDiffer.update());
return fiberRefUnsafeMakePatch(initial, {
differ,
fork: differ.empty
});
};
/** @internal */
exports.fiberRefUnsafeMakeReadonlyArray = fiberRefUnsafeMakeReadonlyArray;
const fiberRefUnsafeMakeContext = initial => {
const differ = internalDiffer.environment();
return fiberRefUnsafeMakePatch(initial, {
differ,
fork: differ.empty
});
};
/** @internal */
exports.fiberRefUnsafeMakeContext = fiberRefUnsafeMakeContext;
const fiberRefUnsafeMakePatch = (initial, options) => ({
[FiberRefTypeId]: fiberRefVariance,
initial,
diff: (oldValue, newValue) => options.differ.diff(oldValue, newValue),
combine: (first, second) => options.differ.combine(first, second),
patch: patch => oldValue => options.differ.patch(patch, oldValue),
fork: options.fork,
join: options.join ?? ((_, n) => n),
pipe() {
return (0, _Pipeable.pipeArguments)(this, arguments);
}
});
/** @internal */
exports.fiberRefUnsafeMakePatch = fiberRefUnsafeMakePatch;
const fiberRefUnsafeMakeRuntimeFlags = initial => fiberRefUnsafeMakePatch(initial, {
differ: _runtimeFlags.differ,
fork: _runtimeFlags.differ.empty
});
/** @internal */
exports.fiberRefUnsafeMakeRuntimeFlags = fiberRefUnsafeMakeRuntimeFlags;
const currentContext = exports.currentContext = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentContext"), () => fiberRefUnsafeMakeContext(Context.empty()));
/** @internal */
const currentSchedulingPriority = exports.currentSchedulingPriority = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentSchedulingPriority"), () => fiberRefUnsafeMake(0));
/** @internal */
const currentMaxOpsBeforeYield = exports.currentMaxOpsBeforeYield = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"), () => fiberRefUnsafeMake(2048));
/** @internal */
const currentLogAnnotations = exports.currentLogAnnotations = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentLogAnnotation"), () => fiberRefUnsafeMake(HashMap.empty()));
/** @internal */
const currentLogLevel = exports.currentLogLevel = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentLogLevel"), () => fiberRefUnsafeMake(logLevelInfo));
/** @internal */
const currentLogSpan = exports.currentLogSpan = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentLogSpan"), () => fiberRefUnsafeMake(List.empty()));
/** @internal */
const withSchedulingPriority = exports.withSchedulingPriority = /*#__PURE__*/(0, _Function.dual)(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler));
/** @internal */
const withMaxOpsBeforeYield = exports.withMaxOpsBeforeYield = /*#__PURE__*/(0, _Function.dual)(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler));
/** @internal */
const currentConcurrency = exports.currentConcurrency = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentConcurrency"), () => fiberRefUnsafeMake("unbounded"));
/**
* @internal
*/
const currentRequestBatching = exports.currentRequestBatching = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentRequestBatching"), () => fiberRefUnsafeMake(true));
/** @internal */
const currentUnhandledErrorLogLevel = exports.currentUnhandledErrorLogLevel = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"), () => fiberRefUnsafeMake(Option.some(logLevelDebug)));
/** @internal */
const withUnhandledErrorLogLevel = exports.withUnhandledErrorLogLevel = /*#__PURE__*/(0, _Function.dual)(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level));
/** @internal */
const currentMetricLabels = exports.currentMetricLabels = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentMetricLabels"), () => fiberRefUnsafeMakeReadonlyArray(ReadonlyArray.empty()));
/* @internal */
const metricLabels = exports.metricLabels = /*#__PURE__*/fiberRefGet(currentMetricLabels);
/** @internal */
const currentForkScopeOverride = exports.currentForkScopeOverride = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentForkScopeOverride"), () => fiberRefUnsafeMake(Option.none(), {
fork: () => Option.none(),
join: (parent, _) => parent
}));
/** @internal */
const currentInterruptedCause = exports.currentInterruptedCause = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentInterruptedCause"), () => fiberRefUnsafeMake(internalCause.empty, {
fork: () => internalCause.empty,
join: (parent, _) => parent
}));
/** @internal */
const currentTracerEnabled = exports.currentTracerEnabled = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentTracerEnabled"), () => fiberRefUnsafeMake(true));
/** @internal */
const currentTracerTimingEnabled = exports.currentTracerTimingEnabled = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentTracerTiming"), () => fiberRefUnsafeMake(true));
/** @internal */
const currentTracerSpanAnnotations = exports.currentTracerSpanAnnotations = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(HashMap.empty()));
/** @internal */
const currentTracerSpanLinks = exports.currentTracerSpanLinks = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/FiberRef/currentTracerSpanLinks"), () => fiberRefUnsafeMake(Chunk.empty()));
// -----------------------------------------------------------------------------
// Scope
// -----------------------------------------------------------------------------
/** @internal */
const ScopeTypeId = exports.ScopeTypeId = /*#__PURE__*/Symbol.for("effect/Scope");
/** @internal */
const CloseableScopeTypeId = exports.CloseableScopeTypeId = /*#__PURE__*/Symbol.for("effect/CloseableScope");
/* @internal */
const scopeAddFinalizer = (self, finalizer) => self.addFinalizer(() => asUnit(finalizer));
/* @internal */
exports.scopeAddFinalizer = scopeAddFinalizer;
const scopeAddFinalizerExit = (self, finalizer) => self.addFinalizer(finalizer);
/* @internal */
exports.scopeAddFinalizerExit = scopeAddFinalizerExit;
const scopeClose = (self, exit) => self.close(exit);
/* @internal */
exports.scopeClose = scopeClose;
const scopeFork = (self, strategy) => self.fork(strategy);
// -----------------------------------------------------------------------------
// Cause
// -----------------------------------------------------------------------------
/** @internal */
exports.scopeFork = scopeFork;
const causeSquash = self => {
return causeSquashWith(_Function.identity)(self);
};
/** @internal */
exports.causeSquash = causeSquash;
const causeSquashWith = exports.causeSquashWith = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
const option = (0, _Function.pipe)(self, internalCause.failureOption, Option.map(f));
switch (option._tag) {
case "None":
{
return (0, _Function.pipe)(internalCause.defects(self), Chunk.head, Option.match({
onNone: () => {
const interrupts = Array.from(internalCause.interruptors(self)).flatMap(fiberId => Array.from(FiberId.ids(fiberId)).map(id => `#${id}`));
return new InterruptedException(interrupts ? `Interrupted by fibers: ${interrupts.join(", ")}` : void 0);
},
onSome: _Function.identity
}));
}
case "Some":
{
return option.value;
}
}
});
// -----------------------------------------------------------------------------
// Errors
// -----------------------------------------------------------------------------
/** @internal */
const YieldableError = exports.YieldableError = /*#__PURE__*/function () {
class YieldableError extends globalThis.Error {
commit() {
return fail(this);
}
toString() {
return this.message ? `${this.name}: ${this.message}` : this.name;
}
toJSON() {
return {
...this
};
}
[_Inspectable.NodeInspectSymbol]() {