@effect/io
Advanced tools
Comparing version 0.35.3 to 0.36.0
@@ -245,3 +245,3 @@ /** | ||
*/ | ||
export declare const currentLogAnnotations: FiberRef<HashMap.HashMap<string, string>>; | ||
export declare const currentLogAnnotations: FiberRef<HashMap.HashMap<string, Logger.AnnotationValue>>; | ||
/** | ||
@@ -251,3 +251,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const currentLoggers: FiberRef<HashSet.HashSet<Logger.Logger<string, any>>>; | ||
export declare const currentLoggers: FiberRef<HashSet.HashSet<Logger.Logger<unknown, any>>>; | ||
/** | ||
@@ -297,2 +297,7 @@ * @since 1.0.0 | ||
*/ | ||
export declare const currentTracerTimingEnabled: FiberRef<boolean>; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiberRefs | ||
*/ | ||
export declare const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, Tracer.AttributeValue>>; | ||
@@ -299,0 +304,0 @@ /** |
@@ -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.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.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")); | ||
@@ -259,2 +259,8 @@ var fiberRuntime = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/fiberRuntime")); | ||
exports.currentTracerSpan = currentTracerSpan; | ||
const currentTracerTimingEnabled = core.currentTracerTimingEnabled; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiberRefs | ||
*/ | ||
exports.currentTracerTimingEnabled = currentTracerTimingEnabled; | ||
const currentTracerSpanAnnotations = core.currentTracerSpanAnnotations; | ||
@@ -261,0 +267,0 @@ /** |
@@ -80,3 +80,3 @@ "use strict"; | ||
sleep(duration) { | ||
return core.asyncInterruptEither(cb => { | ||
return core.asyncEither(cb => { | ||
const canceler = globalClockScheduler.unsafeSchedule(() => cb(core.unit), duration); | ||
@@ -83,0 +83,0 @@ return Either.left(core.asUnit(core.sync(canceler))); |
@@ -6,5 +6,5 @@ "use strict"; | ||
}); | ||
exports.fail = 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.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.asyncInterruptEither = exports.asyncInterrupt = 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.withFiberRuntime = 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 = void 0; | ||
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zipFlatten = exports.zip = exports.yieldNow = exports.withUnhandledErrorLogLevel = exports.withSchedulingPriority = exports.withScheduler = exports.withRuntimeFlags = exports.withRequestBatching = exports.withMaxFiberOps = 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.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.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; | ||
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; | ||
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk")); | ||
@@ -194,30 +194,31 @@ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context")); | ||
exports.asUnit = asUnit; | ||
const async = (register, blockingOn = FiberId.none) => { | ||
const async = (register, blockingOn = FiberId.none) => suspend(() => { | ||
let cancelerRef = undefined; | ||
const effect = new EffectPrimitive(OpCodes.OP_ASYNC); | ||
effect.i0 = register; | ||
effect.i0 = resume => { | ||
cancelerRef = register(resume); | ||
}; | ||
effect.i1 = blockingOn; | ||
return effect; | ||
}; | ||
return onInterrupt(effect, () => cancelerRef ?? unit); | ||
}); | ||
/* @internal */ | ||
exports.async = async; | ||
const asyncInterruptEither = (register, blockingOn = FiberId.none) => suspend(() => { | ||
let cancelerRef = unit; | ||
return async(resume => { | ||
const result = register(resume); | ||
if (Either.isRight(result)) { | ||
resume(result.right); | ||
} else { | ||
cancelerRef = result.left; | ||
} | ||
}, blockingOn).pipe(onInterrupt(() => cancelerRef)); | ||
}); | ||
const asyncEither = (register, blockingOn = FiberId.none) => async(resume => { | ||
const result = register(resume); | ||
if (Either.isRight(result)) { | ||
resume(result.right); | ||
} else { | ||
return result.left; | ||
} | ||
}, blockingOn); | ||
/** @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.asyncInterruptEither = asyncInterruptEither; | ||
const asyncInterrupt = (register, blockingOn = FiberId.none) => suspend(() => { | ||
let cancelerRef = unit; | ||
return async(resume => { | ||
cancelerRef = register(resume); | ||
}, blockingOn).pipe(onInterrupt(() => cancelerRef)); | ||
}); | ||
/* @internal */ | ||
exports.asyncInterrupt = asyncInterrupt; | ||
@@ -659,4 +660,7 @@ const catchAllCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => { | ||
}); | ||
/** @internal */ | ||
exports.withRuntimeFlags = withRuntimeFlags; | ||
const withTracerTiming = /*#__PURE__*/(0, _Function.dual)(2, (effect, enabled) => fiberRefLocally(effect, currentTracerTimingEnabled, enabled)); | ||
/* @internal */ | ||
exports.withRuntimeFlags = withRuntimeFlags; | ||
exports.withTracerTiming = withTracerTiming; | ||
const yieldNow = options => { | ||
@@ -683,3 +687,3 @@ const effect = new EffectPrimitive(OpCodes.OP_YIELD); | ||
exports.zipWith = zipWith; | ||
const never = /*#__PURE__*/asyncInterruptEither(() => { | ||
const never = /*#__PURE__*/asyncEither(() => { | ||
const interval = setInterval(() => { | ||
@@ -1025,2 +1029,5 @@ // | ||
exports.currentTracerSpan = currentTracerSpan; | ||
const currentTracerTimingEnabled = /*#__PURE__*/(0, _Global.globalValue)( /*#__PURE__*/Symbol.for("@effect/io/FiberRef/currentTracerTiming"), () => fiberRefUnsafeMake(true)); | ||
/** @internal */ | ||
exports.currentTracerTimingEnabled = currentTracerTimingEnabled; | ||
const currentTracerSpanAnnotations = /*#__PURE__*/(0, _Global.globalValue)( /*#__PURE__*/Symbol.for("@effect/io/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(HashMap.empty())); | ||
@@ -1515,3 +1522,3 @@ // ----------------------------------------------------------------------------- | ||
exports.deferredMakeAs = deferredMakeAs; | ||
const deferredAwait = self => asyncInterruptEither(k => { | ||
const deferredAwait = self => asyncEither(k => { | ||
const state = MutableRef.get(self.state); | ||
@@ -1518,0 +1525,0 @@ switch (state._tag) { |
@@ -34,6 +34,6 @@ "use strict"; | ||
/* @internal */ | ||
const annotateLogs = /*#__PURE__*/(0, _Function.dual)(3, (effect, key, value) => core.flatMap(core.fiberRefGet(core.currentLogAnnotations), annotations => core.suspend(() => core.fiberRefLocally(core.currentLogAnnotations, HashMap.set(annotations, key, value))(effect)))); | ||
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))))); | ||
/* @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(core.currentTracerSpanAnnotations, HashMap.set(annotations, key, value))(self)))); | ||
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 */ | ||
@@ -47,3 +47,3 @@ exports.annotateSpans = annotateSpans; | ||
exports.asSomeError = asSomeError; | ||
const asyncOption = (register, blockingOn = FiberId.none) => core.asyncInterruptEither(cb => { | ||
const asyncOption = (register, blockingOn = FiberId.none) => core.asyncEither(cb => { | ||
const option = register(cb); | ||
@@ -404,12 +404,12 @@ switch (option._tag) { | ||
exports.iterate = iterate; | ||
const logWithLevel = level => (messageOrCause, supplementry) => { | ||
const logWithLevel = level => (messageOrCause, supplementary) => { | ||
const levelOption = Option.fromNullable(level); | ||
let message; | ||
let cause; | ||
if (typeof messageOrCause === "string") { | ||
if (internalCause.isCause(messageOrCause)) { | ||
cause = messageOrCause; | ||
message = supplementary ?? ""; | ||
} else { | ||
message = messageOrCause; | ||
cause = supplementry ?? internalCause.empty; | ||
} else { | ||
cause = messageOrCause; | ||
message = supplementry ?? ""; | ||
cause = supplementary ?? internalCause.empty; | ||
} | ||
@@ -539,3 +539,3 @@ return core.withFiberRuntime(fiberState => { | ||
exports.promise = promise; | ||
const promiseInterrupt = evaluate => core.asyncInterruptEither(resolve => { | ||
const promiseInterrupt = evaluate => core.asyncEither(resolve => { | ||
const controller = new AbortController(); | ||
@@ -742,3 +742,3 @@ evaluate(controller.signal).then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitDie(e))); | ||
catch: arg.catch | ||
}) : try_(evaluate), ([controller, promise]) => core.asyncInterruptEither(resolve => { | ||
}) : try_(evaluate), ([controller, promise]) => core.asyncEither(resolve => { | ||
promise.then(a => resolve(core.exitSucceed(a))).catch(e => resolve(core.exitFail(hasCatch ? arg.catch(e) : e))); | ||
@@ -789,3 +789,3 @@ return Either.left(core.sync(() => controller.abort())); | ||
const evaluate = args[args.length - 1]; | ||
return core.acquireUseRelease(tracerWith(tracer => core.flatMap(options?.parent ? core.succeed(Option.some(options.parent)) : options?.root ? core.succeed(Option.none()) : core.map(core.fiberRefGet(core.currentTracerSpan), List.head), parent => core.flatMap(core.fiberRefGet(core.currentTracerSpanAnnotations), annotations => core.flatMap(Clock.currentTimeNanos, startTime => core.sync(() => { | ||
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); | ||
@@ -797,6 +797,8 @@ HashMap.forEach(annotations, (value, key) => span.attribute(key, value)); | ||
return span; | ||
}))))), evaluate, (span, exit) => core.flatMap(Clock.clockWith(clock => clock.currentTimeNanos), endTime => core.sync(() => span.end(endTime, exit)))); | ||
}))))), 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 */ | ||
exports.useSpan = useSpan; | ||
const when = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.suspend(() => predicate() ? core.map(self, Option.some) : core.succeed(Option.none()))); | ||
@@ -803,0 +805,0 @@ /* @internal */ |
@@ -36,3 +36,3 @@ "use strict"; | ||
this.taken = 0; | ||
this.take = n => core.asyncInterruptEither(resume => { | ||
this.take = n => core.asyncEither(resume => { | ||
if (this.free < n) { | ||
@@ -39,0 +39,0 @@ const observer = () => { |
@@ -101,5 +101,6 @@ "use strict"; | ||
let output = outputArray.join(" "); | ||
if (message.length > 0) { | ||
const stringMessage = serializeUnknown(message); | ||
if (stringMessage.length > 0) { | ||
output = output + " message="; | ||
output = appendQuoted(message, output); | ||
output = appendQuoted(stringMessage, output); | ||
} | ||
@@ -133,3 +134,3 @@ if (cause != null && cause != Cause.empty) { | ||
output = output + "="; | ||
output = appendQuoted(value, output); | ||
output = appendQuoted(String(value), output); | ||
} | ||
@@ -139,4 +140,11 @@ } | ||
}); | ||
exports.stringLogger = stringLogger; | ||
const serializeUnknown = u => { | ||
try { | ||
return typeof u === "object" ? JSON.stringify(u) : String(u); | ||
} catch (_) { | ||
return String(u); | ||
} | ||
}; | ||
/** @internal */ | ||
exports.stringLogger = stringLogger; | ||
const escapeDoubleQuotes = str => `"${str.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`; | ||
@@ -159,5 +167,6 @@ const textOnly = /^[^\s"=]+$/; | ||
let output = outputArray.join(" "); | ||
if (message.length > 0) { | ||
const stringMessage = serializeUnknown(message); | ||
if (stringMessage.length > 0) { | ||
output = output + " message="; | ||
output = appendQuotedLogfmt(message, output); | ||
output = appendQuotedLogfmt(stringMessage, output); | ||
} | ||
@@ -191,3 +200,3 @@ if (cause != null && cause != Cause.empty) { | ||
output = output + "="; | ||
output = appendQuotedLogfmt(value, output); | ||
output = appendQuotedLogfmt(String(value), output); | ||
} | ||
@@ -194,0 +203,0 @@ } |
@@ -14,2 +14,3 @@ "use strict"; | ||
var FiberRefs = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/FiberRefs")); | ||
var _cause = /*#__PURE__*/require("@effect/io/internal/cause"); | ||
var CausePretty = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/cause-pretty")); | ||
@@ -68,16 +69,8 @@ var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/core")); | ||
const unsafeRunSync = runtime => effect => { | ||
const scheduler = new _scheduler.SyncScheduler(); | ||
const fiberRuntime = unsafeFork(runtime)(effect, { | ||
scheduler | ||
}); | ||
scheduler.flush(); | ||
const result = fiberRuntime.unsafePoll(); | ||
if (result) { | ||
if (result._tag === "Failure") { | ||
throw fiberFailure(result.i0); | ||
} else { | ||
return result.i0; | ||
} | ||
const result = unsafeRunSyncExit(runtime)(effect); | ||
if (result._tag === "Failure") { | ||
throw fiberFailure(result.i0); | ||
} else { | ||
return result.i0; | ||
} | ||
throw asyncFiberException(fiberRuntime); | ||
}; | ||
@@ -153,7 +146,39 @@ /** @internal */ | ||
const isFiberFailure = u => typeof u === "object" && u !== null && FiberFailureId in u; | ||
exports.isFiberFailure = isFiberFailure; | ||
const fastPath = effect => { | ||
const op = effect; | ||
switch (op._tag) { | ||
case "Failure": | ||
case "Success": | ||
{ | ||
// @ts-expect-error | ||
return op; | ||
} | ||
case "Left": | ||
{ | ||
return core.exitFail(op.left); | ||
} | ||
case "Right": | ||
{ | ||
return core.exitSucceed(op.right); | ||
} | ||
case "Some": | ||
{ | ||
return core.exitSucceed(op.value); | ||
} | ||
case "None": | ||
{ | ||
// @ts-expect-error | ||
return core.exitFail((0, _cause.NoSuchElementException)()); | ||
} | ||
} | ||
}; | ||
/** @internal */ | ||
exports.isFiberFailure = isFiberFailure; | ||
const unsafeRunSyncExit = runtime => effect => { | ||
const op = fastPath(effect); | ||
if (op) { | ||
return op; | ||
} | ||
const scheduler = new _scheduler.SyncScheduler(); | ||
const fiberRuntime = unsafeFork(runtime)(core.exit(effect), { | ||
const fiberRuntime = unsafeFork(runtime)(effect, { | ||
scheduler | ||
@@ -164,7 +189,3 @@ }); | ||
if (result) { | ||
if (result._tag === "Failure") { | ||
throw fiberFailure(result.i0); | ||
} else { | ||
return result.i0; | ||
} | ||
return result; | ||
} | ||
@@ -175,34 +196,23 @@ throw asyncFiberException(fiberRuntime); | ||
exports.unsafeRunSyncExit = unsafeRunSyncExit; | ||
const unsafeRunPromise = runtime => effect => new Promise((resolve, reject) => { | ||
unsafeFork(runtime)(effect).unsafeAddObserver(result => { | ||
switch (result._tag) { | ||
case OpCodes.OP_SUCCESS: | ||
{ | ||
resolve(result.i0); | ||
break; | ||
} | ||
case OpCodes.OP_FAILURE: | ||
{ | ||
reject(fiberFailure(result.i0)); | ||
break; | ||
} | ||
} | ||
}); | ||
const unsafeRunPromise = runtime => effect => unsafeRunPromiseExit(runtime)(effect).then(result => { | ||
switch (result._tag) { | ||
case OpCodes.OP_SUCCESS: | ||
{ | ||
return result.i0; | ||
} | ||
case OpCodes.OP_FAILURE: | ||
{ | ||
throw fiberFailure(result.i0); | ||
} | ||
} | ||
}); | ||
/** @internal */ | ||
exports.unsafeRunPromise = unsafeRunPromise; | ||
const unsafeRunPromiseExit = runtime => effect => new Promise((resolve, reject) => { | ||
unsafeFork(runtime)(core.exit(effect)).unsafeAddObserver(exit => { | ||
switch (exit._tag) { | ||
case OpCodes.OP_SUCCESS: | ||
{ | ||
resolve(exit.i0); | ||
break; | ||
} | ||
case OpCodes.OP_FAILURE: | ||
{ | ||
reject(fiberFailure(exit.i0)); | ||
break; | ||
} | ||
} | ||
const unsafeRunPromiseExit = runtime => effect => new Promise(resolve => { | ||
const op = fastPath(effect); | ||
if (op) { | ||
resolve(op); | ||
} | ||
unsafeFork(runtime)(effect).unsafeAddObserver(exit => { | ||
resolve(exit); | ||
}); | ||
@@ -209,0 +219,0 @@ }); |
@@ -39,3 +39,3 @@ /** | ||
readonly spans: List.List<LogSpan.LogSpan>; | ||
readonly annotations: HashMap.HashMap<string, string>; | ||
readonly annotations: HashMap.HashMap<string, AnnotationValue>; | ||
readonly date: Date; | ||
@@ -60,2 +60,7 @@ }) => Output; | ||
/** | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export type AnnotationValue = string | number | boolean; | ||
/** | ||
* @category constructors | ||
@@ -71,3 +76,3 @@ * @since 1.0.0 | ||
readonly spans: List.List<LogSpan.LogSpan>; | ||
readonly annotations: HashMap.HashMap<string, string>; | ||
readonly annotations: HashMap.HashMap<string, AnnotationValue>; | ||
readonly date: Date; | ||
@@ -79,3 +84,3 @@ }) => Output) => Logger<Message, Output>; | ||
*/ | ||
export declare const add: <B>(logger: Logger<string, B>) => Layer.Layer<never, never, never>; | ||
export declare const add: <B>(logger: Logger<unknown, B>) => Layer.Layer<never, never, never>; | ||
/** | ||
@@ -85,3 +90,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const addEffect: <R, E, A>(effect: Effect<R, E, Logger<string, A>>) => Layer.Layer<R, E, never>; | ||
export declare const addEffect: <R, E, A>(effect: Effect<R, E, Logger<unknown, A>>) => Layer.Layer<R, E, never>; | ||
/** | ||
@@ -91,3 +96,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const addScoped: <R, E, A>(effect: Effect<R | Scope, E, Logger<string, A>>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
export declare const addScoped: <R, E, A>(effect: Effect<R | Scope, E, Logger<unknown, A>>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
/** | ||
@@ -131,3 +136,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const remove: <A>(logger: Logger<string, A>) => Layer.Layer<never, never, never>; | ||
export declare const remove: <A>(logger: Logger<unknown, A>) => Layer.Layer<never, never, never>; | ||
/** | ||
@@ -138,4 +143,4 @@ * @since 1.0.0 | ||
export declare const replace: { | ||
<B>(that: Logger<string, B>): <A>(self: Logger<string, A>) => Layer.Layer<never, never, never>; | ||
<A, B>(self: Logger<string, A>, that: Logger<string, B>): Layer.Layer<never, never, never>; | ||
<B>(that: Logger<unknown, B>): <A>(self: Logger<unknown, A>) => Layer.Layer<never, never, never>; | ||
<A, B>(self: Logger<unknown, A>, that: Logger<unknown, B>): Layer.Layer<never, never, never>; | ||
}; | ||
@@ -147,4 +152,4 @@ /** | ||
export declare const replaceEffect: { | ||
<R, E, B>(that: Effect<R, E, Logger<string, B>>): <A>(self: Logger<string, A>) => Layer.Layer<R, E, never>; | ||
<A, R, E, B>(self: Logger<string, A>, that: Effect<R, E, Logger<string, B>>): Layer.Layer<R, E, never>; | ||
<R, E, B>(that: Effect<R, E, Logger<unknown, B>>): <A>(self: Logger<unknown, A>) => Layer.Layer<R, E, never>; | ||
<A, R, E, B>(self: Logger<unknown, A>, that: Effect<R, E, Logger<unknown, B>>): Layer.Layer<R, E, never>; | ||
}; | ||
@@ -156,4 +161,4 @@ /** | ||
export declare const replaceScoped: { | ||
<R, E, B>(that: Effect<Scope | R, E, Logger<string, B>>): <A>(self: Logger<string, A>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
<A, R, E, B>(self: Logger<string, A>, that: Effect<Scope | R, E, Logger<string, B>>): Layer.Layer<Exclude<R, Scope>, E, never>; | ||
<R, E, B>(that: Effect<Scope | R, E, Logger<unknown, B>>): <A>(self: Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never>; | ||
<A, R, E, B>(self: Logger<unknown, A>, that: Effect<Scope | R, E, Logger<unknown, B>>): Layer.Layer<Exclude<R, Scope>, E, never>; | ||
}; | ||
@@ -222,3 +227,3 @@ /** | ||
*/ | ||
export declare const defaultLogger: Logger<string, void>; | ||
export declare const defaultLogger: Logger<unknown, void>; | ||
/** | ||
@@ -228,3 +233,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const logfmtLogger: Logger<string, string>; | ||
export declare const logfmtLogger: Logger<unknown, string>; | ||
/** | ||
@@ -234,3 +239,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const stringLogger: Logger<string, string>; | ||
export declare const stringLogger: Logger<unknown, string>; | ||
/** | ||
@@ -240,3 +245,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const tracerLogger: Logger<string, void>; | ||
export declare const tracerLogger: Logger<unknown, void>; | ||
/** | ||
@@ -243,0 +248,0 @@ * @since 1.0.0 |
{ | ||
"name": "@effect/io", | ||
"version": "0.35.3", | ||
"version": "0.36.0", | ||
"license": "MIT", | ||
@@ -10,3 +10,3 @@ "repository": { | ||
"dependencies": { | ||
"@effect/data": "^0.16.0" | ||
"@effect/data": "^0.17.0" | ||
}, | ||
@@ -13,0 +13,0 @@ "publishConfig": { |
@@ -318,3 +318,4 @@ /** | ||
*/ | ||
export const currentLogAnnotations: FiberRef<HashMap.HashMap<string, string>> = core.currentLogAnnotations | ||
export const currentLogAnnotations: FiberRef<HashMap.HashMap<string, Logger.AnnotationValue>> = | ||
core.currentLogAnnotations | ||
@@ -325,3 +326,3 @@ /** | ||
*/ | ||
export const currentLoggers: FiberRef<HashSet.HashSet<Logger.Logger<string, any>>> = fiberRuntime.currentLoggers | ||
export const currentLoggers: FiberRef<HashSet.HashSet<Logger.Logger<unknown, any>>> = fiberRuntime.currentLoggers | ||
@@ -380,2 +381,8 @@ /** | ||
*/ | ||
export const currentTracerTimingEnabled: FiberRef<boolean> = core.currentTracerTimingEnabled | ||
/** | ||
* @since 1.0.0 | ||
* @category fiberRefs | ||
*/ | ||
export const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, Tracer.AttributeValue>> = | ||
@@ -382,0 +389,0 @@ core.currentTracerSpanAnnotations |
@@ -88,3 +88,3 @@ import * as Context from "@effect/data/Context" | ||
sleep(duration: Duration.Duration): Effect.Effect<never, never, void> { | ||
return core.asyncInterruptEither<never, never, void>((cb) => { | ||
return core.asyncEither<never, never, void>((cb) => { | ||
const canceler = globalClockScheduler.unsafeSchedule(() => cb(core.unit), duration) | ||
@@ -91,0 +91,0 @@ return Either.left(core.asUnit(core.sync(canceler))) |
@@ -27,2 +27,3 @@ import * as Chunk from "@effect/data/Chunk" | ||
import * as SingleShotGen from "@effect/io/internal/singleShotGen" | ||
import type * as Logger from "@effect/io/Logger" | ||
import * as LogLevel from "@effect/io/Logger/Level" | ||
@@ -38,3 +39,3 @@ import * as LogSpan from "@effect/io/Logger/Span" | ||
export const annotateLogs = dual< | ||
(key: string, value: string) => <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>, | ||
(key: string, value: Logger.AnnotationValue) => <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>, | ||
<R, E, A>(effect: Effect.Effect<R, E, A>, key: string, value: string) => Effect.Effect<R, E, A> | ||
@@ -49,5 +50,6 @@ >( | ||
core.fiberRefLocally( | ||
effect, | ||
core.currentLogAnnotations, | ||
HashMap.set(annotations, key, value) | ||
)(effect) | ||
) | ||
) | ||
@@ -69,5 +71,6 @@ ) | ||
core.fiberRefLocally( | ||
self, | ||
core.currentTracerSpanAnnotations, | ||
HashMap.set(annotations, key, value) | ||
)(self) | ||
) | ||
) | ||
@@ -90,3 +93,3 @@ ) | ||
): Effect.Effect<R, E, A> => | ||
core.asyncInterruptEither<R, E, A>( | ||
core.asyncEither<R, E, A>( | ||
(cb) => { | ||
@@ -870,15 +873,15 @@ const option = register(cb) | ||
const logWithLevel = (level?: LogLevel.LogLevel) => | ||
<A extends string | Cause.Cause<unknown>>( | ||
<A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
): Effect.Effect<never, never, void> => { | ||
const levelOption = Option.fromNullable(level) | ||
let message: string | ||
let message: unknown | ||
let cause: Cause.Cause<unknown> | ||
if (typeof messageOrCause === "string") { | ||
if (internalCause.isCause(messageOrCause)) { | ||
cause = messageOrCause | ||
message = (supplementary as unknown) ?? "" | ||
} else { | ||
message = messageOrCause | ||
cause = (supplementry as Cause.Cause<unknown>) ?? internalCause.empty | ||
} else { | ||
cause = messageOrCause | ||
message = (supplementry as string) ?? "" | ||
cause = (supplementary as Cause.Cause<unknown>) ?? internalCause.empty | ||
} | ||
@@ -892,41 +895,41 @@ return core.withFiberRuntime<never, never, void>((fiberState) => { | ||
/** @internal */ | ||
export const log: <A extends string | Cause.Cause<unknown>>( | ||
export const log: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel() | ||
/** @internal */ | ||
export const logTrace: <A extends string | Cause.Cause<unknown>>( | ||
export const logTrace: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel(LogLevel.Trace) | ||
/** @internal */ | ||
export const logDebug: <A extends string | Cause.Cause<unknown>>( | ||
export const logDebug: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel(LogLevel.Debug) | ||
/** @internal */ | ||
export const logInfo: <A extends string | Cause.Cause<unknown>>( | ||
export const logInfo: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel(LogLevel.Info) | ||
/** @internal */ | ||
export const logWarning: <A extends string | Cause.Cause<unknown>>( | ||
export const logWarning: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel(LogLevel.Warning) | ||
/** @internal */ | ||
export const logError: <A extends string | Cause.Cause<unknown>>( | ||
export const logError: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel(LogLevel.Error) | ||
/** @internal */ | ||
export const logFatal: <A extends string | Cause.Cause<unknown>>( | ||
export const logFatal: <A>( | ||
messageOrCause: A, | ||
supplementry?: A extends string ? Cause.Cause<unknown> : string | ||
supplementary?: A extends Cause.Cause<any> ? unknown : Cause.Cause<unknown> | ||
) => Effect.Effect<never, never, void> = logWithLevel(LogLevel.Fatal) | ||
@@ -952,5 +955,6 @@ | ||
/* @internal */ | ||
export const logAnnotations: Effect.Effect<never, never, HashMap.HashMap<string, string>> = core.fiberRefGet( | ||
core.currentLogAnnotations | ||
) | ||
export const logAnnotations: Effect.Effect<never, never, HashMap.HashMap<string, Logger.AnnotationValue>> = core | ||
.fiberRefGet( | ||
core.currentLogAnnotations | ||
) | ||
@@ -1174,3 +1178,3 @@ /* @internal */ | ||
export const promiseInterrupt = <A>(evaluate: (signal: AbortSignal) => Promise<A>): Effect.Effect<never, never, A> => | ||
core.asyncInterruptEither<never, never, A>((resolve) => { | ||
core.asyncEither<never, never, A>((resolve) => { | ||
const controller = new AbortController() | ||
@@ -1633,3 +1637,3 @@ evaluate(controller.signal) | ||
([controller, promise]) => | ||
core.asyncInterruptEither<never, E, A>((resolve) => { | ||
core.asyncEither<never, E, A>((resolve) => { | ||
promise | ||
@@ -1794,5 +1798,5 @@ .then((a) => resolve(core.exitSucceed(a))) | ||
options?.parent ? | ||
core.succeed(Option.some(options.parent)) : | ||
succeedSome(options.parent) : | ||
options?.root ? | ||
core.succeed(Option.none()) : | ||
succeedNone : | ||
core.map( | ||
@@ -1807,3 +1811,3 @@ core.fiberRefGet(core.currentTracerSpan), | ||
core.flatMap( | ||
Clock.currentTimeNanos, | ||
currentTimeNanosTracing, | ||
(startTime) => | ||
@@ -1825,3 +1829,3 @@ core.sync(() => { | ||
core.flatMap( | ||
Clock.clockWith((clock) => clock.currentTimeNanos), | ||
currentTimeNanosTracing, | ||
(endTime) => core.sync(() => span.end(endTime, exit)) | ||
@@ -1832,2 +1836,8 @@ ) | ||
const bigint0 = BigInt(0) | ||
const currentTimeNanosTracing = core.fiberRefGetWith( | ||
core.currentTracerTimingEnabled, | ||
(enabled) => enabled ? Clock.currentTimeNanos : core.succeed(bigint0) | ||
) | ||
/* @internal */ | ||
@@ -1834,0 +1844,0 @@ export const when = dual< |
@@ -46,3 +46,3 @@ import * as Duration from "@effect/data/Duration" | ||
readonly take = (n: number): Effect.Effect<never, never, number> => | ||
core.asyncInterruptEither<never, never, number>((resume) => { | ||
core.asyncEither<never, never, number>((resume) => { | ||
if (this.free < n) { | ||
@@ -49,0 +49,0 @@ const observer = () => { |
@@ -40,3 +40,3 @@ import { dual } from "@effect/data/Function" | ||
/** @internal */ | ||
export const addLogger = <A>(logger: Logger.Logger<string, A>): Layer.Layer<never, never, never> => | ||
export const addLogger = <A>(logger: Logger.Logger<unknown, A>): Layer.Layer<never, never, never> => | ||
layer.scopedDiscard( | ||
@@ -51,3 +51,3 @@ fiberRuntime.fiberRefLocallyScopedWith( | ||
export const addLoggerEffect = <R, E, A>( | ||
effect: Effect.Effect<R, E, Logger.Logger<string, A>> | ||
effect: Effect.Effect<R, E, Logger.Logger<unknown, A>> | ||
): Layer.Layer<R, E, never> => | ||
@@ -60,3 +60,3 @@ Layer.unwrapEffect( | ||
export const addLoggerScoped = <R, E, A>( | ||
effect: Effect.Effect<R | Scope, E, Logger.Logger<string, A>> | ||
effect: Effect.Effect<R | Scope, E, Logger.Logger<unknown, A>> | ||
): Layer.Layer<Exclude<R, Scope>, E, never> => | ||
@@ -68,3 +68,3 @@ Layer.unwrapScoped( | ||
/** @internal */ | ||
export const removeLogger = <A>(logger: Logger.Logger<string, A>): Layer.Layer<never, never, never> => | ||
export const removeLogger = <A>(logger: Logger.Logger<unknown, A>): Layer.Layer<never, never, never> => | ||
layer.scopedDiscard( | ||
@@ -79,4 +79,4 @@ fiberRuntime.fiberRefLocallyScopedWith( | ||
export const replaceLogger = dual< | ||
<B>(that: Logger.Logger<string, B>) => <A>(self: Logger.Logger<string, A>) => Layer.Layer<never, never, never>, | ||
<A, B>(self: Logger.Logger<string, A>, that: Logger.Logger<string, B>) => Layer.Layer<never, never, never> | ||
<B>(that: Logger.Logger<unknown, B>) => <A>(self: Logger.Logger<unknown, A>) => Layer.Layer<never, never, never>, | ||
<A, B>(self: Logger.Logger<unknown, A>, that: Logger.Logger<unknown, B>) => Layer.Layer<never, never, never> | ||
>(2, (self, that) => layer.flatMap(removeLogger(self), () => addLogger(that))) | ||
@@ -87,7 +87,7 @@ | ||
<R, E, B>( | ||
that: Effect.Effect<R, E, Logger.Logger<string, B>> | ||
) => <A>(self: Logger.Logger<string, A>) => Layer.Layer<R, E, never>, | ||
that: Effect.Effect<R, E, Logger.Logger<unknown, B>> | ||
) => <A>(self: Logger.Logger<unknown, A>) => Layer.Layer<R, E, never>, | ||
<A, R, E, B>( | ||
self: Logger.Logger<string, A>, | ||
that: Effect.Effect<R, E, Logger.Logger<string, B>> | ||
self: Logger.Logger<unknown, A>, | ||
that: Effect.Effect<R, E, Logger.Logger<unknown, B>> | ||
) => Layer.Layer<R, E, never> | ||
@@ -99,7 +99,7 @@ >(2, (self, that) => layer.flatMap(removeLogger(self), () => addLoggerEffect(that))) | ||
<R, E, B>( | ||
that: Effect.Effect<R | Scope, E, Logger.Logger<string, B>> | ||
) => <A>(self: Logger.Logger<string, A>) => Layer.Layer<Exclude<R, Scope>, E, never>, | ||
that: Effect.Effect<R | Scope, E, Logger.Logger<unknown, B>> | ||
) => <A>(self: Logger.Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never>, | ||
<A, R, E, B>( | ||
self: Logger.Logger<string, A>, | ||
that: Effect.Effect<R | Scope, E, Logger.Logger<string, B>> | ||
self: Logger.Logger<unknown, A>, | ||
that: Effect.Effect<R | Scope, E, Logger.Logger<unknown, B>> | ||
) => Layer.Layer<Exclude<R, Scope>, E, never> | ||
@@ -106,0 +106,0 @@ >(2, (self, that) => layer.flatMap(removeLogger(self), () => addLoggerScoped(that))) |
@@ -41,3 +41,3 @@ import type { LazyArg } from "@effect/data/Function" | ||
readonly spans: List.List<LogSpan.LogSpan> | ||
readonly annotations: HashMap.HashMap<string, string> | ||
readonly annotations: HashMap.HashMap<string, Logger.AnnotationValue> | ||
readonly date: Date | ||
@@ -163,3 +163,3 @@ } | ||
/** @internal */ | ||
export const stringLogger: Logger.Logger<string, string> = makeLogger<string, string>( | ||
export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown, string>( | ||
({ annotations, cause, date, fiberId, logLevel, message, spans }) => { | ||
@@ -175,6 +175,7 @@ const nowMillis = date.getTime() | ||
let output = outputArray.join(" ") | ||
const stringMessage = serializeUnknown(message) | ||
if (message.length > 0) { | ||
if (stringMessage.length > 0) { | ||
output = output + " message=" | ||
output = appendQuoted(message, output) | ||
output = appendQuoted(stringMessage, output) | ||
} | ||
@@ -213,3 +214,3 @@ | ||
output = output + "=" | ||
output = appendQuoted(value, output) | ||
output = appendQuoted(String(value), output) | ||
} | ||
@@ -222,2 +223,10 @@ } | ||
const serializeUnknown = (u: unknown): string => { | ||
try { | ||
return typeof u === "object" ? JSON.stringify(u) : String(u) | ||
} catch (_) { | ||
return String(u) | ||
} | ||
} | ||
/** @internal */ | ||
@@ -233,3 +242,3 @@ const escapeDoubleQuotes = (str: string) => `"${str.replace(/\\([\s\S])|(")/g, "\\$1$2")}"` | ||
/** @internal */ | ||
export const logfmtLogger = makeLogger<string, string>( | ||
export const logfmtLogger = makeLogger<unknown, string>( | ||
({ annotations, cause, date, fiberId, logLevel, message, spans }) => { | ||
@@ -245,6 +254,7 @@ const nowMillis = date.getTime() | ||
let output = outputArray.join(" ") | ||
const stringMessage = serializeUnknown(message) | ||
if (message.length > 0) { | ||
if (stringMessage.length > 0) { | ||
output = output + " message=" | ||
output = appendQuotedLogfmt(message, output) | ||
output = appendQuotedLogfmt(stringMessage, output) | ||
} | ||
@@ -283,3 +293,3 @@ | ||
output = output + "=" | ||
output = appendQuotedLogfmt(value, output) | ||
output = appendQuotedLogfmt(String(value), output) | ||
} | ||
@@ -286,0 +296,0 @@ } |
@@ -13,2 +13,3 @@ import * as Context from "@effect/data/Context" | ||
import * as FiberRefs from "@effect/io/FiberRefs" | ||
import { NoSuchElementException } from "@effect/io/internal/cause" | ||
import * as CausePretty from "@effect/io/internal/cause-pretty" | ||
@@ -98,14 +99,8 @@ import * as core from "@effect/io/internal/core" | ||
<E, A>(effect: Effect.Effect<R, E, A>): A => { | ||
const scheduler = new _scheduler.SyncScheduler() | ||
const fiberRuntime = unsafeFork(runtime)(effect, { scheduler }) | ||
scheduler.flush() | ||
const result = fiberRuntime.unsafePoll() | ||
if (result) { | ||
if (result._tag === "Failure") { | ||
throw fiberFailure(result.i0) | ||
} else { | ||
return result.i0 | ||
} | ||
const result = unsafeRunSyncExit(runtime)(effect) | ||
if (result._tag === "Failure") { | ||
throw fiberFailure(result.i0) | ||
} else { | ||
return result.i0 | ||
} | ||
throw asyncFiberException(fiberRuntime) | ||
} | ||
@@ -190,15 +185,39 @@ | ||
const fastPath = <R, E, A>(effect: Effect.Effect<R, E, A>): Exit.Exit<E, A> | undefined => { | ||
const op = effect as core.Primitive | ||
switch (op._tag) { | ||
case "Failure": | ||
case "Success": { | ||
// @ts-expect-error | ||
return op | ||
} | ||
case "Left": { | ||
return core.exitFail(op.left) | ||
} | ||
case "Right": { | ||
return core.exitSucceed(op.right) | ||
} | ||
case "Some": { | ||
return core.exitSucceed(op.value) | ||
} | ||
case "None": { | ||
// @ts-expect-error | ||
return core.exitFail(NoSuchElementException()) | ||
} | ||
} | ||
} | ||
/** @internal */ | ||
export const unsafeRunSyncExit = <R>(runtime: Runtime.Runtime<R>) => | ||
<E, A>(effect: Effect.Effect<R, E, A>) => { | ||
<E, A>(effect: Effect.Effect<R, E, A>): Exit.Exit<E, A> => { | ||
const op = fastPath(effect) | ||
if (op) { | ||
return op | ||
} | ||
const scheduler = new _scheduler.SyncScheduler() | ||
const fiberRuntime = unsafeFork(runtime)(core.exit(effect), { scheduler }) | ||
const fiberRuntime = unsafeFork(runtime)(effect, { scheduler }) | ||
scheduler.flush() | ||
const result = fiberRuntime.unsafePoll() | ||
if (result) { | ||
if (result._tag === "Failure") { | ||
throw fiberFailure(result.i0) | ||
} else { | ||
return result.i0 | ||
} | ||
return result | ||
} | ||
@@ -211,16 +230,11 @@ throw asyncFiberException(fiberRuntime) | ||
<E, A>(effect: Effect.Effect<R, E, A>): Promise<A> => | ||
new Promise((resolve, reject) => { | ||
unsafeFork(runtime)(effect) | ||
.unsafeAddObserver((result) => { | ||
switch (result._tag) { | ||
case OpCodes.OP_SUCCESS: { | ||
resolve(result.i0) | ||
break | ||
} | ||
case OpCodes.OP_FAILURE: { | ||
reject(fiberFailure(result.i0)) | ||
break | ||
} | ||
} | ||
}) | ||
unsafeRunPromiseExit(runtime)(effect).then((result) => { | ||
switch (result._tag) { | ||
case OpCodes.OP_SUCCESS: { | ||
return result.i0 | ||
} | ||
case OpCodes.OP_FAILURE: { | ||
throw fiberFailure(result.i0) | ||
} | ||
} | ||
}) | ||
@@ -231,16 +245,10 @@ | ||
<E, A>(effect: Effect.Effect<R, E, A>): Promise<Exit.Exit<E, A>> => | ||
new Promise((resolve, reject) => { | ||
unsafeFork(runtime)(core.exit(effect)) | ||
.unsafeAddObserver((exit) => { | ||
switch (exit._tag) { | ||
case OpCodes.OP_SUCCESS: { | ||
resolve(exit.i0) | ||
break | ||
} | ||
case OpCodes.OP_FAILURE: { | ||
reject(fiberFailure(exit.i0)) | ||
break | ||
} | ||
} | ||
}) | ||
new Promise((resolve) => { | ||
const op = fastPath(effect) | ||
if (op) { | ||
resolve(op) | ||
} | ||
unsafeFork(runtime)(effect).unsafeAddObserver((exit) => { | ||
resolve(exit) | ||
}) | ||
}) | ||
@@ -247,0 +255,0 @@ |
@@ -47,3 +47,3 @@ /** | ||
readonly spans: List.List<LogSpan.LogSpan> | ||
readonly annotations: HashMap.HashMap<string, string> | ||
readonly annotations: HashMap.HashMap<string, AnnotationValue> | ||
readonly date: Date | ||
@@ -71,2 +71,8 @@ } | ||
/** | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export type AnnotationValue = string | number | boolean | ||
/** | ||
* @category constructors | ||
@@ -84,3 +90,3 @@ * @since 1.0.0 | ||
readonly spans: List.List<LogSpan.LogSpan> | ||
readonly annotations: HashMap.HashMap<string, string> | ||
readonly annotations: HashMap.HashMap<string, AnnotationValue> | ||
readonly date: Date | ||
@@ -95,3 +101,3 @@ } | ||
*/ | ||
export const add: <B>(logger: Logger<string, B>) => Layer.Layer<never, never, never> = circular.addLogger | ||
export const add: <B>(logger: Logger<unknown, B>) => Layer.Layer<never, never, never> = circular.addLogger | ||
@@ -102,3 +108,3 @@ /** | ||
*/ | ||
export const addEffect: <R, E, A>(effect: Effect<R, E, Logger<string, A>>) => Layer.Layer<R, E, never> = | ||
export const addEffect: <R, E, A>(effect: Effect<R, E, Logger<unknown, A>>) => Layer.Layer<R, E, never> = | ||
circular.addLoggerEffect | ||
@@ -111,3 +117,3 @@ | ||
export const addScoped: <R, E, A>( | ||
effect: Effect<R | Scope, E, Logger<string, A>> | ||
effect: Effect<R | Scope, E, Logger<unknown, A>> | ||
) => Layer.Layer<Exclude<R, Scope>, E, never> = circular.addLoggerScoped | ||
@@ -172,3 +178,3 @@ | ||
*/ | ||
export const remove: <A>(logger: Logger<string, A>) => Layer.Layer<never, never, never> = circular.removeLogger | ||
export const remove: <A>(logger: Logger<unknown, A>) => Layer.Layer<never, never, never> = circular.removeLogger | ||
@@ -180,4 +186,4 @@ /** | ||
export const replace: { | ||
<B>(that: Logger<string, B>): <A>(self: Logger<string, A>) => Layer.Layer<never, never, never> | ||
<A, B>(self: Logger<string, A>, that: Logger<string, B>): Layer.Layer<never, never, never> | ||
<B>(that: Logger<unknown, B>): <A>(self: Logger<unknown, A>) => Layer.Layer<never, never, never> | ||
<A, B>(self: Logger<unknown, A>, that: Logger<unknown, B>): Layer.Layer<never, never, never> | ||
} = circular.replaceLogger | ||
@@ -190,4 +196,4 @@ | ||
export const replaceEffect: { | ||
<R, E, B>(that: Effect<R, E, Logger<string, B>>): <A>(self: Logger<string, A>) => Layer.Layer<R, E, never> | ||
<A, R, E, B>(self: Logger<string, A>, that: Effect<R, E, Logger<string, B>>): Layer.Layer<R, E, never> | ||
<R, E, B>(that: Effect<R, E, Logger<unknown, B>>): <A>(self: Logger<unknown, A>) => Layer.Layer<R, E, never> | ||
<A, R, E, B>(self: Logger<unknown, A>, that: Effect<R, E, Logger<unknown, B>>): Layer.Layer<R, E, never> | ||
} = circular.replaceLoggerEffect | ||
@@ -201,7 +207,7 @@ | ||
<R, E, B>( | ||
that: Effect<Scope | R, E, Logger<string, B>> | ||
): <A>(self: Logger<string, A>) => Layer.Layer<Exclude<R, Scope>, E, never> | ||
that: Effect<Scope | R, E, Logger<unknown, B>> | ||
): <A>(self: Logger<unknown, A>) => Layer.Layer<Exclude<R, Scope>, E, never> | ||
<A, R, E, B>( | ||
self: Logger<string, A>, | ||
that: Effect<Scope | R, E, Logger<string, B>> | ||
self: Logger<unknown, A>, | ||
that: Effect<Scope | R, E, Logger<unknown, B>> | ||
): Layer.Layer<Exclude<R, Scope>, E, never> | ||
@@ -295,3 +301,3 @@ } = circular.replaceLoggerScoped | ||
*/ | ||
export const defaultLogger: Logger<string, void> = fiberRuntime.defaultLogger | ||
export const defaultLogger: Logger<unknown, void> = fiberRuntime.defaultLogger | ||
@@ -302,3 +308,3 @@ /** | ||
*/ | ||
export const logfmtLogger: Logger<string, string> = internal.logfmtLogger | ||
export const logfmtLogger: Logger<unknown, string> = internal.logfmtLogger | ||
@@ -309,3 +315,3 @@ /** | ||
*/ | ||
export const stringLogger: Logger<string, string> = internal.stringLogger | ||
export const stringLogger: Logger<unknown, string> = internal.stringLogger | ||
@@ -316,3 +322,3 @@ /** | ||
*/ | ||
export const tracerLogger: Logger<string, void> = fiberRuntime.tracerLogger | ||
export const tracerLogger: Logger<unknown, void> = fiberRuntime.tracerLogger | ||
@@ -319,0 +325,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 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 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
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
6400622
114209
+ Added@effect/data@0.17.6(transitive)
- Removed@effect/data@0.16.3(transitive)
Updated@effect/data@^0.17.0