@effect/io
Advanced tools
Comparing version 0.36.1 to 0.37.0
/** | ||
* @since 1.0.0 | ||
*/ | ||
import type * as Chunk from "@effect/data/Chunk"; | ||
import type * as Context from "@effect/data/Context"; | ||
@@ -290,3 +291,3 @@ import type * as Differ from "@effect/data/Differ"; | ||
*/ | ||
export declare const currentTracerSpan: FiberRef<List.List<Tracer.Span>>; | ||
export declare const currentTracerSpan: FiberRef<List.List<Tracer.ParentSpan>>; | ||
/** | ||
@@ -306,3 +307,8 @@ * @since 1.0.0 | ||
*/ | ||
export declare const currentTracerSpanLinks: FiberRef<Chunk.Chunk<Tracer.SpanLink>>; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiberRefs | ||
*/ | ||
export declare const interruptedCause: FiberRef<Cause.Cause<never>>; | ||
//# sourceMappingURL=FiberRef.d.ts.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.updateSomeAndGet = exports.updateSome = exports.updateAndGet = exports.update = exports.unsafeMakeSupervisor = exports.unsafeMakePatch = exports.unsafeMakeHashSet = exports.unsafeMakeContext = exports.unsafeMake = exports.unhandledErrorLogLevel = exports.set = exports.reset = exports.modifySome = exports.modify = exports.makeWith = exports.makeRuntimeFlags = exports.makeContext = exports.make = exports.interruptedCause = exports.getWith = exports.getAndUpdateSome = exports.getAndUpdate = exports.getAndSet = exports.get = exports.delete = exports.currentTracerTimingEnabled = exports.currentTracerSpanAnnotations = exports.currentTracerSpan = exports.currentSupervisor = exports.currentSchedulingPriority = exports.currentScheduler = exports.currentRuntimeFlags = exports.currentRequestCacheEnabled = exports.currentRequestCache = exports.currentRequestBatchingEnabled = exports.currentMinimumLogLevel = exports.currentMetricLabels = exports.currentMaxFiberOps = exports.currentLoggers = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentContext = exports.FiberRefTypeId = void 0; | ||
exports.updateSomeAndGet = exports.updateSome = exports.updateAndGet = exports.update = exports.unsafeMakeSupervisor = exports.unsafeMakePatch = exports.unsafeMakeHashSet = exports.unsafeMakeContext = exports.unsafeMake = exports.unhandledErrorLogLevel = exports.set = exports.reset = exports.modifySome = exports.modify = exports.makeWith = exports.makeRuntimeFlags = exports.makeContext = exports.make = exports.interruptedCause = exports.getWith = exports.getAndUpdateSome = exports.getAndUpdate = exports.getAndSet = exports.get = exports.delete = exports.currentTracerTimingEnabled = exports.currentTracerSpanLinks = exports.currentTracerSpanAnnotations = exports.currentTracerSpan = exports.currentSupervisor = exports.currentSchedulingPriority = exports.currentScheduler = exports.currentRuntimeFlags = exports.currentRequestCacheEnabled = exports.currentRequestCache = exports.currentRequestBatchingEnabled = exports.currentMinimumLogLevel = exports.currentMetricLabels = exports.currentMaxFiberOps = exports.currentLoggers = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentContext = exports.FiberRefTypeId = void 0; | ||
var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/core")); | ||
@@ -271,4 +271,10 @@ var fiberRuntime = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/fiberRuntime")); | ||
exports.currentTracerSpanAnnotations = currentTracerSpanAnnotations; | ||
const currentTracerSpanLinks = core.currentTracerSpanLinks; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiberRefs | ||
*/ | ||
exports.currentTracerSpanLinks = currentTracerSpanLinks; | ||
const interruptedCause = core.currentInterruptedCause; | ||
exports.interruptedCause = interruptedCause; | ||
//# sourceMappingURL=FiberRef.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.exitZipWith = exports.exitZipRight = exports.exitZipParRight = exports.exitZipParLeft = exports.exitZipPar = exports.exitZipLeft = exports.exitZip = exports.exitUnit = exports.exitUnannotate = exports.exitSucceed = exports.exitMatchEffect = exports.exitMatch = exports.exitMapErrorCause = exports.exitMapError = exports.exitMapBoth = exports.exitMap = exports.exitIsSuccess = exports.exitIsInterrupted = exports.exitIsFailure = exports.exitIsExit = 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.currentUnhandledErrorLogLevel = exports.currentTracerTimingEnabled = exports.currentTracerSpanAnnotations = exports.currentTracerSpan = exports.currentSchedulingPriority = exports.currentScheduler = exports.currentRequestBatching = exports.currentMetricLabels = exports.currentMaxFiberOps = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentInterruptedCause = exports.currentForkScopeOverride = exports.currentContext = exports.currentConcurrency = exports.contextWithEffect = exports.context = exports.checkInterruptible = exports.catchSome = exports.catchAllCause = exports.catchAll = exports.blocked = exports.attemptOrElse = exports.asyncInterrupt = exports.asyncEither = exports.async = exports.asUnit = exports.as = exports.allLogLevels = exports.acquireUseRelease = exports.ScopeTypeId = exports.RevertFlags = exports.RequestResolverTypeId = exports.RequestResolverImpl = exports.FiberRefTypeId = exports.EffectTypeId = exports.EffectErrorTypeId = exports.CloseableScopeTypeId = void 0; | ||
exports.exitZipWith = exports.exitZipRight = exports.exitZipParRight = exports.exitZipParLeft = exports.exitZipPar = exports.exitZipLeft = exports.exitZip = exports.exitUnit = exports.exitUnannotate = exports.exitSucceed = exports.exitMatchEffect = exports.exitMatch = exports.exitMapErrorCause = exports.exitMapError = exports.exitMapBoth = exports.exitMap = exports.exitIsSuccess = exports.exitIsInterrupted = exports.exitIsFailure = exports.exitIsExit = 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.currentUnhandledErrorLogLevel = exports.currentTracerTimingEnabled = exports.currentTracerSpanLinks = exports.currentTracerSpanAnnotations = exports.currentTracerSpan = exports.currentSchedulingPriority = exports.currentScheduler = exports.currentRequestBatching = exports.currentMetricLabels = exports.currentMaxFiberOps = exports.currentLogSpan = exports.currentLogLevel = exports.currentLogAnnotations = exports.currentInterruptedCause = exports.currentForkScopeOverride = exports.currentContext = exports.currentConcurrency = exports.contextWithEffect = exports.context = exports.checkInterruptible = exports.catchSome = exports.catchAllCause = exports.catchAll = exports.blocked = exports.attemptOrElse = exports.asyncEither = exports.async = exports.asUnit = exports.as = exports.allLogLevels = exports.acquireUseRelease = exports.ScopeTypeId = exports.RevertFlags = exports.RequestResolverTypeId = exports.RequestResolverImpl = exports.FiberRefTypeId = exports.EffectTypeId = exports.EffectErrorTypeId = exports.CloseableScopeTypeId = void 0; | ||
exports.withConcurrency = exports.whileLoop = exports.whenEffect = exports.updateRuntimeFlags = exports.unit = exports.uninterruptibleMask = exports.uninterruptible = exports.unified = 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 = exports.requestBlockLocally = exports.releaseMapReplace = exports.releaseMapRemove = exports.releaseMapRelease = exports.releaseMapMake = exports.releaseMapGet = exports.releaseMapAddIfOpen = exports.releaseMapAdd = exports.provideSomeContext = exports.provideContext = exports.partitionMap = exports.orElse = exports.orDieWith = exports.orDie = exports.onInterrupt = exports.onExit = exports.onError = 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.isRequestResolver = 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.flatMapStep = exports.flatMap = exports.fiberRefUpdateSomeAndGet = exports.fiberRefUpdateSome = exports.fiberRefUpdateAndGet = exports.fiberRefUpdate = exports.fiberRefUnsafeMakeRuntimeFlags = 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 = void 0; | ||
@@ -196,8 +196,23 @@ exports.zipWith = exports.zipRight = exports.zipLeft = exports.zipFlatten = exports.zip = exports.yieldNow = exports.withUnhandledErrorLogLevel = exports.withTracerTiming = exports.withSchedulingPriority = exports.withScheduler = exports.withRuntimeFlags = exports.withRequestBatching = exports.withMaxFiberOps = exports.withFiberRuntime = void 0; | ||
let cancelerRef = undefined; | ||
let controllerRef = undefined; | ||
const effect = new EffectPrimitive(OpCodes.OP_ASYNC); | ||
effect.i0 = resume => { | ||
cancelerRef = register(resume); | ||
}; | ||
if (register.length !== 1) { | ||
const controller = new AbortController(); | ||
controllerRef = controller; | ||
effect.i0 = resume => { | ||
cancelerRef = register(resume, controller.signal); | ||
}; | ||
} else { | ||
effect.i0 = resume => { | ||
// @ts-expect-error | ||
cancelerRef = register(resume); | ||
}; | ||
} | ||
effect.i1 = blockingOn; | ||
return onInterrupt(effect, () => isEffect(cancelerRef) ? cancelerRef : unit); | ||
return onInterrupt(effect, () => { | ||
if (controllerRef) { | ||
controllerRef.abort(); | ||
} | ||
return cancelerRef ?? unit; | ||
}); | ||
}); | ||
@@ -214,13 +229,4 @@ /* @internal */ | ||
}, blockingOn); | ||
/** @internal */ | ||
/* @internal */ | ||
exports.asyncEither = asyncEither; | ||
const asyncInterrupt = (register, blockingOn = FiberId.none) => async(resume => { | ||
const controller = new AbortController(); | ||
register(resume, controller.signal); | ||
return sync(() => { | ||
controller.abort(); | ||
}); | ||
}, blockingOn); | ||
/* @internal */ | ||
exports.asyncInterrupt = asyncInterrupt; | ||
const catchAllCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => { | ||
@@ -921,3 +927,3 @@ const effect = new EffectPrimitive(OpCodes.OP_ON_FAILURE); | ||
exports.fiberRefLocally = fiberRefLocally; | ||
const fiberRefLocallyWith = /*#__PURE__*/(0, _Function.dual)(3, (use, self, f) => fiberRefGetWith(self, a => fiberRefLocally(self, f(a))(use))); | ||
const fiberRefLocallyWith = /*#__PURE__*/(0, _Function.dual)(3, (use, self, f) => fiberRefGetWith(self, a => fiberRefLocally(use, self, f(a)))); | ||
/** @internal */ | ||
@@ -1033,2 +1039,5 @@ exports.fiberRefLocallyWith = fiberRefLocallyWith; | ||
const currentTracerSpanAnnotations = /*#__PURE__*/(0, _Global.globalValue)( /*#__PURE__*/Symbol.for("@effect/io/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(HashMap.empty())); | ||
/** @internal */ | ||
exports.currentTracerSpanAnnotations = currentTracerSpanAnnotations; | ||
const currentTracerSpanLinks = /*#__PURE__*/(0, _Global.globalValue)( /*#__PURE__*/Symbol.for("@effect/io/FiberRef/currentTracerSpanLinks"), () => fiberRefUnsafeMake(Chunk.empty())); | ||
// ----------------------------------------------------------------------------- | ||
@@ -1038,3 +1047,3 @@ // Scope | ||
/** @internal */ | ||
exports.currentTracerSpanAnnotations = currentTracerSpanAnnotations; | ||
exports.currentTracerSpanLinks = currentTracerSpanLinks; | ||
const ScopeTypeId = /*#__PURE__*/Symbol.for("@effect/io/Scope"); | ||
@@ -1041,0 +1050,0 @@ /** @internal */ |
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.tracer = exports.timedWith = exports.timed = exports.tapErrorCause = exports.tapError = exports.tapDefect = exports.tapBoth = exports.takeWhile = exports.takeUntil = exports.tagMetrics = exports.summarized = exports.succeedSome = exports.succeedNone = exports.spanAnnotations = exports.some = exports.sleep = exports.setFiberRefs = exports.serviceFunctionEffect = exports.serviceFunction = exports.sandbox = exports.repeatN = exports.reduceWhile = exports.reduceRight = exports.reduce = exports.random = exports.provideServiceEffect = exports.provideService = exports.promiseInterrupt = exports.promise = exports.patchFiberRefs = exports.parallelErrors = exports.orElseSucceed = exports.orElseFail = exports.option = exports.once = exports.none = exports.negate = exports.merge = exports.memoize = exports.match = exports.mapErrorCause = exports.mapAccum = exports.loop = exports.logWarning = exports.logTrace = exports.logInfo = exports.logFatal = exports.logError = exports.logDebug = exports.logAnnotations = exports.log = exports.labelMetricsSet = exports.labelMetrics = exports.iterate = exports.isSuccess = exports.isFailure = exports.inheritFiberRefs = exports.ignoreLogged = exports.ignore = exports.head = exports.getFiberRefs = exports.gen = exports.forever = exports.flipWith = exports.firstSuccessOf = exports.findFirst = exports.filterOrFail = exports.filterOrElse = exports.filterOrDieMessage = exports.filterOrDie = exports.filterMap = exports.every = exports.eventually = exports.dropWhile = exports.dropUntil = exports.diffFiberRefs = exports.descriptorWith = exports.descriptor = exports.delay = exports.currentSpan = exports.contextWith = exports.clockWith = exports.clock = exports.cause = exports.catchTags = exports.catchTag = exports.catchSomeDefect = exports.catchSomeCause = exports.catchAllDefect = exports.bindValue = exports.bindTo = exports.bind = exports.asyncOption = exports.asSomeError = exports.asSome = exports.annotateSpans = exports.annotateLogs = exports.allowInterrupt = exports._catch = exports.Do = void 0; | ||
exports.withSpan = exports.withMetric = exports.withLogSpan = exports.whenRef = exports.whenFiberRef = exports.when = exports.useSpan = exports.updateService = exports.updateFiberRefs = exports.unsandbox = exports.unlessEffect = exports.unless = exports.try_ = exports.tryPromiseInterrupt = exports.tryPromise = exports.tryMapPromiseInterrupt = exports.tryMapPromise = exports.tryMap = exports.tracerWith = void 0; | ||
exports.tapDefect = exports.tapBoth = exports.takeWhile = exports.takeUntil = exports.tagMetrics = exports.summarized = exports.succeedSome = exports.succeedNone = exports.spanLinks = exports.spanAnnotations = exports.some = exports.sleep = exports.setFiberRefs = exports.serviceFunctionEffect = exports.serviceFunction = exports.sandbox = exports.repeatN = exports.reduceWhile = exports.reduceRight = exports.reduce = exports.random = exports.provideServiceEffect = exports.provideService = exports.promise = exports.patchFiberRefs = exports.parallelErrors = exports.orElseSucceed = exports.orElseFail = exports.option = exports.once = exports.none = exports.negate = exports.merge = exports.memoize = exports.match = exports.mapErrorCause = exports.mapAccum = exports.makeSpan = exports.loop = exports.logWarning = exports.logTrace = exports.logInfo = exports.logFatal = exports.logError = exports.logDebug = exports.logAnnotations = exports.log = exports.linkSpans = exports.labelMetricsSet = exports.labelMetrics = exports.iterate = exports.isSuccess = exports.isFailure = exports.inheritFiberRefs = exports.ignoreLogged = exports.ignore = exports.head = exports.getFiberRefs = exports.gen = exports.forever = exports.flipWith = exports.firstSuccessOf = exports.findFirst = exports.filterOrFail = exports.filterOrElse = exports.filterOrDieMessage = exports.filterOrDie = exports.filterMap = exports.every = exports.eventually = exports.dropWhile = exports.dropUntil = exports.diffFiberRefs = exports.descriptorWith = exports.descriptor = exports.delay = exports.currentTimeNanosTracing = exports.currentSpan = exports.currentParentSpan = exports.contextWith = exports.clockWith = exports.clock = exports.cause = exports.catchTags = exports.catchTag = exports.catchSomeDefect = exports.catchSomeCause = exports.catchAllDefect = exports.bindValue = exports.bindTo = exports.bind = exports.asyncOption = exports.asSomeError = exports.asSome = exports.annotateSpans = exports.annotateLogs = exports.annotateCurrentSpan = exports.allowInterrupt = exports._catch = exports.Do = void 0; | ||
exports.withSpan = exports.withParentSpan = exports.withMetric = exports.withLogSpan = exports.whenRef = exports.whenFiberRef = exports.when = exports.useSpan = exports.updateService = exports.updateFiberRefs = exports.unsandbox = exports.unlessEffect = exports.unless = exports.try_ = exports.tryPromise = exports.tryMapPromise = exports.tryMap = exports.tracerWith = exports.tracer = exports.timedWith = exports.timed = exports.tapErrorCause = exports.tapError = void 0; | ||
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk")); | ||
@@ -35,8 +35,8 @@ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context")); | ||
/* @internal */ | ||
const annotateLogs = /*#__PURE__*/(0, _Function.dual)(3, (effect, key, value) => core.flatMap(core.fiberRefGet(core.currentLogAnnotations), annotations => core.suspend(() => core.fiberRefLocally(effect, core.currentLogAnnotations, HashMap.set(annotations, key, value))))); | ||
const annotateLogs = /*#__PURE__*/(0, _Function.dual)(args => core.isEffect(args[0]), function () { | ||
const args = arguments; | ||
return core.fiberRefLocallyWith(args[0], core.currentLogAnnotations, typeof args[1] === "string" ? HashMap.set(args[1], args[2]) : annotations => Object.entries(args[1]).reduce((acc, [key, value]) => HashMap.set(acc, key, value), annotations)); | ||
}); | ||
/* @internal */ | ||
exports.annotateLogs = annotateLogs; | ||
const annotateSpans = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => core.flatMap(core.fiberRefGet(core.currentTracerSpanAnnotations), annotations => core.suspend(() => core.fiberRefLocally(self, core.currentTracerSpanAnnotations, HashMap.set(annotations, key, value))))); | ||
/* @internal */ | ||
exports.annotateSpans = annotateSpans; | ||
const asSome = self => core.map(self, Option.some); | ||
@@ -170,5 +170,2 @@ /* @internal */ | ||
exports.clock = clock; | ||
const currentSpan = /*#__PURE__*/core.map( /*#__PURE__*/core.fiberRefGet(core.currentTracerSpan), List.head); | ||
/* @internal */ | ||
exports.currentSpan = currentSpan; | ||
const delay = /*#__PURE__*/(0, _Function.dual)(2, (self, duration) => core.zipRight(Clock.sleep(duration), self)); | ||
@@ -443,3 +440,3 @@ /* @internal */ | ||
exports.logFatal = logFatal; | ||
const withLogSpan = /*#__PURE__*/(0, _Function.dual)(2, (effect, label) => core.flatMap(core.fiberRefGet(core.currentLogSpan), stack => core.flatMap(Clock.currentTimeMillis, now => core.suspend(() => core.fiberRefLocally(core.currentLogSpan, List.prepend(stack, LogSpan.make(label, now)))(effect))))); | ||
const withLogSpan = /*#__PURE__*/(0, _Function.dual)(2, (effect, label) => core.flatMap(Clock.currentTimeMillis, now => core.fiberRefLocallyWith(effect, core.currentLogSpan, List.prepend(LogSpan.make(label, now))))); | ||
/* @internal */ | ||
@@ -535,3 +532,6 @@ exports.withLogSpan = withLogSpan; | ||
exports.patchFiberRefs = patchFiberRefs; | ||
const promise = evaluate => core.async(resolve => { | ||
const promise = evaluate => evaluate.length >= 1 ? core.async((resolve, signal) => { | ||
evaluate(signal).then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitDie(e))); | ||
}) : core.async(resolve => { | ||
; | ||
evaluate().then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitDie(e))); | ||
@@ -541,9 +541,2 @@ }); | ||
exports.promise = promise; | ||
const promiseInterrupt = evaluate => core.asyncEither(resolve => { | ||
const controller = new AbortController(); | ||
evaluate(controller.signal).then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitDie(e))); | ||
return Either.left(core.sync(() => controller.abort())); | ||
}); | ||
/* @internal */ | ||
exports.promiseInterrupt = promiseInterrupt; | ||
const provideService = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, service) => provideServiceEffect(self, tag, core.succeed(service))); | ||
@@ -730,23 +723,26 @@ /* @internal */ | ||
exports.tracer = tracer; | ||
const tryPromise = arg => core.flatMap(try_(arg), promise => core.async(resolve => { | ||
promise.then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitFail("catch" in arg ? arg.catch(e) : e))); | ||
})); | ||
/* @internal */ | ||
exports.tryPromise = tryPromise; | ||
const tryPromiseInterrupt = arg => { | ||
const hasCatch = ("catch" in arg); | ||
const evaluate = () => { | ||
const controller = new AbortController(); | ||
return [controller, hasCatch ? arg.try(controller.signal) : arg(controller.signal)]; | ||
}; | ||
return core.flatMap(hasCatch ? try_({ | ||
try: evaluate, | ||
catch: arg.catch | ||
}) : try_(evaluate), ([controller, promise]) => core.asyncEither(resolve => { | ||
promise.then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitFail(hasCatch ? arg.catch(e) : e))); | ||
return Either.left(core.sync(() => controller.abort())); | ||
const tryPromise = arg => { | ||
let evaluate; | ||
let catcher = undefined; | ||
if (typeof arg === "function") { | ||
evaluate = arg; | ||
} else { | ||
evaluate = arg.try; | ||
catcher = arg.catch; | ||
} | ||
if (evaluate.length >= 1) { | ||
return core.suspend(() => { | ||
const controller = new AbortController(); | ||
return core.flatMap(try_(() => evaluate(controller.signal)), promise => core.async(resolve => { | ||
promise.then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitFail(catcher ? catcher(e) : e))); | ||
return core.sync(() => controller.abort()); | ||
})); | ||
}); | ||
} | ||
return core.flatMap(try_(arg), promise => core.async(resolve => { | ||
promise.then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitFail(catcher ? catcher(e) : e))); | ||
})); | ||
}; | ||
/* @internal */ | ||
exports.tryPromiseInterrupt = tryPromiseInterrupt; | ||
exports.tryPromise = tryPromise; | ||
const tryMap = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => core.flatMap(self, a => try_({ | ||
@@ -759,3 +755,3 @@ try: () => options.try(a), | ||
const tryMapPromise = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => core.flatMap(self, a => tryPromise({ | ||
try: () => options.try(a), | ||
try: options.try.length >= 1 ? signal => options.try(a, signal) : () => options.try(a), | ||
catch: options.catch | ||
@@ -765,8 +761,2 @@ }))); | ||
exports.tryMapPromise = tryMapPromise; | ||
const tryMapPromiseInterrupt = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => core.flatMap(self, a => tryPromiseInterrupt({ | ||
try: signal => options.try(a, signal), | ||
catch: options.catch | ||
}))); | ||
/* @internal */ | ||
exports.tryMapPromiseInterrupt = tryMapPromiseInterrupt; | ||
const unless = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.suspend(() => predicate() ? succeedNone : asSome(self))); | ||
@@ -788,20 +778,4 @@ /* @internal */ | ||
const updateService = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, f) => core.mapInputContext(self, context => Context.add(context, tag, f(Context.unsafeGet(context, tag))))); | ||
/** @internal */ | ||
/* @internal */ | ||
exports.updateService = updateService; | ||
const useSpan = (name, ...args) => { | ||
const options = args.length === 1 ? undefined : args[0]; | ||
const evaluate = args[args.length - 1]; | ||
return core.acquireUseRelease(tracerWith(tracer => core.flatMap(options?.parent ? succeedSome(options.parent) : options?.root ? succeedNone : core.map(core.fiberRefGet(core.currentTracerSpan), List.head), parent => core.flatMap(core.fiberRefGet(core.currentTracerSpanAnnotations), annotations => core.flatMap(currentTimeNanosTracing, startTime => core.sync(() => { | ||
const span = tracer.span(name, parent, options?.context ?? Context.empty(), startTime); | ||
HashMap.forEach(annotations, (value, key) => span.attribute(key, value)); | ||
Object.entries(options?.attributes ?? {}).forEach(([k, v]) => { | ||
span.attribute(k, v); | ||
}); | ||
return span; | ||
}))))), evaluate, (span, exit) => core.flatMap(currentTimeNanosTracing, endTime => core.sync(() => span.end(endTime, exit)))); | ||
}; | ||
exports.useSpan = useSpan; | ||
const bigint0 = /*#__PURE__*/BigInt(0); | ||
const currentTimeNanosTracing = /*#__PURE__*/core.fiberRefGetWith(core.currentTracerTimingEnabled, enabled => enabled ? Clock.currentTimeNanos : core.succeed(bigint0)); | ||
/* @internal */ | ||
const when = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.suspend(() => predicate() ? core.map(self, Option.some) : core.succeed(Option.none()))); | ||
@@ -819,8 +793,2 @@ /* @internal */ | ||
exports.withMetric = withMetric; | ||
const withSpan = /*#__PURE__*/(0, _Function.dual)(args => typeof args[0] !== "string", (self, name, options) => useSpan(name, options ?? {}, span => core.flatMap(core.fiberRefGet(core.currentTracerSpan), stack => core.fiberRefLocally(self, core.currentTracerSpan, List.prepend(stack, span))))); | ||
/* @internal */ | ||
exports.withSpan = withSpan; | ||
const spanAnnotations = /*#__PURE__*/core.fiberRefGet(core.currentTracerSpanAnnotations); | ||
/** @internal */ | ||
exports.spanAnnotations = spanAnnotations; | ||
const serviceFunctionEffect = (service, f) => (...args) => core.flatMap(service, a => f(a)(...args)); | ||
@@ -830,3 +798,71 @@ /** @internal */ | ||
const serviceFunction = (service, f) => (...args) => core.map(service, a => f(a)(...args)); | ||
// ----------------------------------------------------------------------------- | ||
// tracing | ||
// ----------------------------------------------------------------------------- | ||
/* @internal */ | ||
exports.serviceFunction = serviceFunction; | ||
const annotateCurrentSpan = function () { | ||
const args = arguments; | ||
return core.flatMap(currentSpan, span => span._tag === "Some" ? core.sync(() => { | ||
if (typeof args[0] === "string") { | ||
span.value.attribute(args[0], args[1]); | ||
} else { | ||
for (const key in args[0]) { | ||
span.value.attribute(key, args[0][key]); | ||
} | ||
} | ||
}) : core.unit); | ||
}; | ||
/* @internal */ | ||
exports.annotateCurrentSpan = annotateCurrentSpan; | ||
const annotateSpans = /*#__PURE__*/(0, _Function.dual)(args => core.isEffect(args[0]), function () { | ||
const args = arguments; | ||
return core.fiberRefLocallyWith(args[0], core.currentTracerSpanAnnotations, typeof args[1] === "string" ? HashMap.set(args[1], args[2]) : annotations => Object.entries(args[1]).reduce((acc, [key, value]) => HashMap.set(acc, key, value), annotations)); | ||
}); | ||
/* @internal */ | ||
exports.annotateSpans = annotateSpans; | ||
const currentParentSpan = /*#__PURE__*/core.map( /*#__PURE__*/core.fiberRefGet(core.currentTracerSpan), List.head); | ||
/* @internal */ | ||
exports.currentParentSpan = currentParentSpan; | ||
const currentSpan = /*#__PURE__*/core.map( /*#__PURE__*/core.fiberRefGet(core.currentTracerSpan), /*#__PURE__*/List.findFirst(span => span._tag === "Span")); | ||
exports.currentSpan = currentSpan; | ||
const bigint0 = /*#__PURE__*/BigInt(0); | ||
/** @internal */ | ||
const currentTimeNanosTracing = /*#__PURE__*/core.fiberRefGetWith(core.currentTracerTimingEnabled, enabled => enabled ? Clock.currentTimeNanos : core.succeed(bigint0)); | ||
/* @internal */ | ||
exports.currentTimeNanosTracing = currentTimeNanosTracing; | ||
const linkSpans = /*#__PURE__*/(0, _Function.dual)(args => core.isEffect(args[0]), (self, span, attributes) => core.fiberRefLocallyWith(self, core.currentTracerSpanLinks, Chunk.append({ | ||
_tag: "SpanLink", | ||
span, | ||
attributes: attributes ?? {} | ||
}))); | ||
/** @internal */ | ||
exports.linkSpans = linkSpans; | ||
const makeSpan = (name, options) => tracerWith(tracer => core.flatMap(options?.parent ? succeedSome(options.parent) : options?.root ? succeedNone : currentParentSpan, parent => core.flatMap(core.fiberRefGet(core.currentTracerSpanAnnotations), annotations => core.flatMap(core.fiberRefGet(core.currentTracerSpanLinks), links => core.flatMap(currentTimeNanosTracing, startTime => core.sync(() => { | ||
const linksArray = options?.links ? [...Chunk.toReadonlyArray(links), ...options.links] : Chunk.toReadonlyArray(links); | ||
const span = tracer.span(name, parent, options?.context ?? Context.empty(), linksArray, startTime); | ||
HashMap.forEach(annotations, (value, key) => span.attribute(key, value)); | ||
Object.entries(options?.attributes ?? {}).forEach(([k, v]) => span.attribute(k, v)); | ||
return span; | ||
})))))); | ||
/* @internal */ | ||
exports.makeSpan = makeSpan; | ||
const spanAnnotations = /*#__PURE__*/core.fiberRefGet(core.currentTracerSpanAnnotations); | ||
/* @internal */ | ||
exports.spanAnnotations = spanAnnotations; | ||
const spanLinks = /*#__PURE__*/core.fiberRefGet(core.currentTracerSpanLinks); | ||
/** @internal */ | ||
exports.spanLinks = spanLinks; | ||
const useSpan = (name, ...args) => { | ||
const options = args.length === 1 ? undefined : args[0]; | ||
const evaluate = args[args.length - 1]; | ||
return core.acquireUseRelease(makeSpan(name, options), evaluate, (span, exit) => core.flatMap(currentTimeNanosTracing, endTime => core.sync(() => span.end(endTime, exit)))); | ||
}; | ||
/** @internal */ | ||
exports.useSpan = useSpan; | ||
const withParentSpan = /*#__PURE__*/(0, _Function.dual)(2, (self, span) => core.fiberRefLocallyWith(self, core.currentTracerSpan, List.prepend(span))); | ||
/** @internal */ | ||
exports.withParentSpan = withParentSpan; | ||
const withSpan = /*#__PURE__*/(0, _Function.dual)(args => typeof args[0] !== "string", (self, name, options) => useSpan(name, options ?? {}, span => withParentSpan(self, span))); | ||
exports.withSpan = withSpan; | ||
//# sourceMappingURL=effect.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.withMinimumLogLevel = exports.setTracer = exports.setConfigProvider = exports.replaceLoggerScoped = exports.replaceLoggerEffect = exports.replaceLogger = exports.removeLogger = exports.minimumLogLevel = exports.enableWindDown = exports.enableRuntimeMetrics = exports.enableOpSupervision = exports.enableInterruption = exports.enableCooperativeYielding = exports.disableWindDown = exports.disableRuntimeMetrics = exports.disableOpSupervision = exports.disableInterruption = exports.disableCooperativeYielding = exports.addSupervisor = exports.addLoggerScoped = exports.addLoggerEffect = exports.addLogger = void 0; | ||
exports.withMinimumLogLevel = exports.setTracer = exports.setSpan = exports.setParentSpan = exports.setConfigProvider = exports.replaceLoggerScoped = exports.replaceLoggerEffect = exports.replaceLogger = exports.removeLogger = exports.minimumLogLevel = exports.enableWindDown = exports.enableRuntimeMetrics = exports.enableOpSupervision = exports.enableInterruption = exports.enableCooperativeYielding = exports.disableWindDown = exports.disableRuntimeMetrics = exports.disableOpSupervision = exports.disableInterruption = exports.disableCooperativeYielding = exports.addSupervisor = exports.addLoggerScoped = exports.addLoggerEffect = exports.addLogger = void 0; | ||
var _Function = /*#__PURE__*/require("@effect/data/Function"); | ||
@@ -84,4 +84,10 @@ var HashSet = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/HashSet")); | ||
exports.setConfigProvider = setConfigProvider; | ||
const setParentSpan = span => layer.scopedDiscard(fiberRuntime.withParentSpanScoped(span)); | ||
/** @internal */ | ||
exports.setParentSpan = setParentSpan; | ||
const setSpan = (name, options) => layer.scopedDiscard(fiberRuntime.withSpanScoped(name, options)); | ||
/** @internal */ | ||
exports.setSpan = setSpan; | ||
const setTracer = tracer => layer.scopedDiscard(fiberRuntime.withTracerScoped(tracer)); | ||
exports.setTracer = setTracer; | ||
//# sourceMappingURL=circular.js.map |
@@ -42,6 +42,6 @@ "use strict"; | ||
nextIntBetween(min, max) { | ||
return core.sync(() => this.PRNG.integer(1 + max - min) + min); | ||
return core.sync(() => this.PRNG.integer(max - min) + min); | ||
} | ||
shuffle(elements) { | ||
return shuffleWith(elements, n => this.nextIntBetween(0, n)); | ||
return shuffleWith(elements, n => this.nextIntBetween(0, n + 1)); | ||
} | ||
@@ -48,0 +48,0 @@ } |
@@ -31,6 +31,7 @@ "use strict"; | ||
class NativeSpan { | ||
constructor(name, parent, context, startTime) { | ||
constructor(name, parent, context, links, startTime) { | ||
this.name = name; | ||
this.parent = parent; | ||
this.context = context; | ||
this.links = links; | ||
this.startTime = startTime; | ||
@@ -65,5 +66,5 @@ this._tag = "Span"; | ||
const nativeTracer = /*#__PURE__*/make({ | ||
span: (name, parent, context, startTime) => new NativeSpan(name, parent, context, startTime) | ||
span: (name, parent, context, links, startTime) => new NativeSpan(name, parent, context, links, startTime) | ||
}); | ||
exports.nativeTracer = nativeTracer; | ||
//# sourceMappingURL=tracer.js.map |
{ | ||
"name": "@effect/io", | ||
"version": "0.36.1", | ||
"version": "0.37.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
/** | ||
* @since 1.0.0 | ||
*/ | ||
import type * as Chunk from "@effect/data/Chunk" | ||
import type * as Context from "@effect/data/Context" | ||
@@ -373,3 +374,3 @@ import type * as Differ from "@effect/data/Differ" | ||
*/ | ||
export const currentTracerSpan: FiberRef<List.List<Tracer.Span>> = core.currentTracerSpan | ||
export const currentTracerSpan: FiberRef<List.List<Tracer.ParentSpan>> = core.currentTracerSpan | ||
@@ -393,2 +394,8 @@ /** | ||
*/ | ||
export const currentTracerSpanLinks: FiberRef<Chunk.Chunk<Tracer.SpanLink>> = core.currentTracerSpanLinks | ||
/** | ||
* @since 1.0.0 | ||
* @category fiberRefs | ||
*/ | ||
export const interruptedCause: FiberRef<Cause.Cause<never>> = core.currentInterruptedCause |
@@ -0,1 +1,2 @@ | ||
import type * as Context from "@effect/data/Context" | ||
import { dual } from "@effect/data/Function" | ||
@@ -185,3 +186,19 @@ import * as HashSet from "@effect/data/HashSet" | ||
/** @internal */ | ||
export const setParentSpan = (span: Tracer.ParentSpan): Layer.Layer<never, never, never> => | ||
layer.scopedDiscard(fiberRuntime.withParentSpanScoped(span)) | ||
/** @internal */ | ||
export const setSpan = ( | ||
name: string, | ||
options?: { | ||
readonly attributes?: Record<string, Tracer.AttributeValue> | ||
readonly links?: ReadonlyArray<Tracer.SpanLink> | ||
readonly parent?: Tracer.ParentSpan | ||
readonly root?: boolean | ||
readonly context?: Context.Context<never> | ||
} | ||
): Layer.Layer<never, never, never> => layer.scopedDiscard(fiberRuntime.withSpanScoped(name, options)) | ||
/** @internal */ | ||
export const setTracer = (tracer: Tracer.Tracer): Layer.Layer<never, never, never> => | ||
layer.scopedDiscard(fiberRuntime.withTracerScoped(tracer)) |
@@ -46,7 +46,7 @@ import * as Chunk from "@effect/data/Chunk" | ||
nextIntBetween(min: number, max: number): Effect.Effect<never, never, number> { | ||
return core.sync(() => this.PRNG.integer(1 + max - min) + min) | ||
return core.sync(() => this.PRNG.integer(max - min) + min) | ||
} | ||
shuffle<A>(elements: Iterable<A>): Effect.Effect<never, never, Chunk.Chunk<A>> { | ||
return shuffleWith(elements, (n) => this.nextIntBetween(0, n)) | ||
return shuffleWith(elements, (n) => this.nextIntBetween(0, n + 1)) | ||
} | ||
@@ -53,0 +53,0 @@ } |
@@ -43,2 +43,3 @@ /** | ||
readonly context: Context.Context<never>, | ||
readonly links: ReadonlyArray<Tracer.SpanLink>, | ||
readonly startTime: bigint | ||
@@ -74,3 +75,3 @@ ) { | ||
export const nativeTracer: Tracer.Tracer = make({ | ||
span: (name, parent, context, startTime) => new NativeSpan(name, parent, context, startTime) | ||
span: (name, parent, context, links, startTime) => new NativeSpan(name, parent, context, links, startTime) | ||
}) |
@@ -30,2 +30,3 @@ /** | ||
context: Context.Context<never>, | ||
links: ReadonlyArray<SpanLink>, | ||
startTime: bigint | ||
@@ -79,2 +80,3 @@ ) => Span | ||
readonly attributes: ReadonlyMap<string, AttributeValue> | ||
readonly links: ReadonlyArray<SpanLink> | ||
readonly end: (endTime: bigint, exit: Exit.Exit<unknown, unknown>) => void | ||
@@ -92,2 +94,12 @@ readonly attribute: (key: string, value: AttributeValue) => void | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export interface SpanLink { | ||
readonly _tag: "SpanLink" | ||
readonly span: ParentSpan | ||
readonly attributes: Readonly<Record<string, AttributeValue>> | ||
} | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
@@ -94,0 +106,0 @@ */ |
@@ -21,3 +21,3 @@ /** | ||
readonly [TracerTypeId]: TracerTypeId; | ||
readonly span: (name: string, parent: Option.Option<ParentSpan>, context: Context.Context<never>, startTime: bigint) => Span; | ||
readonly span: (name: string, parent: Option.Option<ParentSpan>, context: Context.Context<never>, links: ReadonlyArray<SpanLink>, startTime: bigint) => Span; | ||
} | ||
@@ -65,2 +65,3 @@ /** | ||
readonly attributes: ReadonlyMap<string, AttributeValue>; | ||
readonly links: ReadonlyArray<SpanLink>; | ||
readonly end: (endTime: bigint, exit: Exit.Exit<unknown, unknown>) => void; | ||
@@ -77,2 +78,11 @@ readonly attribute: (key: string, value: AttributeValue) => void; | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export interface SpanLink { | ||
readonly _tag: "SpanLink"; | ||
readonly span: ParentSpan; | ||
readonly attributes: Readonly<Record<string, AttributeValue>>; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
@@ -79,0 +89,0 @@ */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6437745
114905