effect 2.4.16 → 2.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Iterable/package.json +6 -0
- package/dist/cjs/Effect.js +11 -4
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Inspectable.js +23 -1
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/Iterable.js +938 -0
- package/dist/cjs/Iterable.js.map +1 -0
- package/dist/cjs/Logger.js +11 -1
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/ReadonlyArray.js +2 -17
- package/dist/cjs/ReadonlyArray.js.map +1 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +19 -25
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +8 -22
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/runtime.js +42 -50
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/schedule.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Config.d.ts +2 -2
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +30 -20
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Inspectable.d.ts +8 -0
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +495 -0
- package/dist/dts/Iterable.d.ts.map +1 -0
- package/dist/dts/Logger.d.ts +10 -0
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/ReadonlyArray.d.ts.map +1 -1
- package/dist/dts/index.d.ts +6 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/logger.d.ts +0 -1
- package/dist/dts/internal/logger.d.ts.map +1 -1
- package/dist/esm/Effect.js +7 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Inspectable.js +20 -0
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/Iterable.js +893 -0
- package/dist/esm/Iterable.js.map +1 -0
- package/dist/esm/Logger.js +10 -0
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/ReadonlyArray.js +2 -17
- package/dist/esm/ReadonlyArray.js.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +16 -23
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +6 -19
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/runtime.js +42 -50
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/schedule.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +9 -1
- package/src/Config.ts +2 -2
- package/src/Effect.ts +64 -47
- package/src/Inspectable.ts +30 -0
- package/src/Iterable.ts +1009 -0
- package/src/Logger.ts +12 -0
- package/src/ReadonlyArray.ts +2 -20
- package/src/index.ts +7 -0
- package/src/internal/config.ts +2 -2
- package/src/internal/core-effect.ts +11 -9
- package/src/internal/effect/circular.ts +19 -7
- package/src/internal/fiberRuntime.ts +63 -54
- package/src/internal/logger.ts +6 -28
- package/src/internal/runtime.ts +45 -52
- package/src/internal/schedule.ts +3 -3
- package/src/internal/version.ts +1 -1
package/src/Logger.ts
CHANGED
|
@@ -192,6 +192,18 @@ export const batched: {
|
|
|
192
192
|
): Effect<Logger<Message, void>, never, Scope | R>
|
|
193
193
|
} = fiberRuntime.batchedLogger
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* @since 2.0.0
|
|
197
|
+
* @category console
|
|
198
|
+
*/
|
|
199
|
+
export const withConsoleLog: <M, O>(self: Logger<M, O>) => Logger<M, void> = fiberRuntime.loggerWithConsoleLog
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @since 2.0.0
|
|
203
|
+
* @category console
|
|
204
|
+
*/
|
|
205
|
+
export const withConsoleError: <M, O>(self: Logger<M, O>) => Logger<M, void> = fiberRuntime.loggerWithConsoleError
|
|
206
|
+
|
|
195
207
|
/**
|
|
196
208
|
* A logger that does nothing in response to logging events.
|
|
197
209
|
*
|
package/src/ReadonlyArray.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { LazyArg } from "./Function.js"
|
|
|
12
12
|
import { dual, identity } from "./Function.js"
|
|
13
13
|
import type { TypeLambda } from "./HKT.js"
|
|
14
14
|
import * as readonlyArray from "./internal/readonlyArray.js"
|
|
15
|
+
import * as EffectIterable from "./Iterable.js"
|
|
15
16
|
import type { Option } from "./Option.js"
|
|
16
17
|
import * as O from "./Option.js"
|
|
17
18
|
import * as Order from "./Order.js"
|
|
@@ -713,26 +714,7 @@ export const findFirst: {
|
|
|
713
714
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>
|
|
714
715
|
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>
|
|
715
716
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>
|
|
716
|
-
} =
|
|
717
|
-
2,
|
|
718
|
-
<A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {
|
|
719
|
-
let i = 0
|
|
720
|
-
for (const a of self) {
|
|
721
|
-
const o = f(a, i)
|
|
722
|
-
if (isBoolean(o)) {
|
|
723
|
-
if (o) {
|
|
724
|
-
return O.some(a)
|
|
725
|
-
}
|
|
726
|
-
} else {
|
|
727
|
-
if (O.isSome(o)) {
|
|
728
|
-
return o
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
i++
|
|
732
|
-
}
|
|
733
|
-
return O.none()
|
|
734
|
-
}
|
|
735
|
-
)
|
|
717
|
+
} = EffectIterable.findFirst
|
|
736
718
|
|
|
737
719
|
/**
|
|
738
720
|
* Find the last element for which a predicate holds.
|
package/src/index.ts
CHANGED
|
@@ -330,6 +330,13 @@ export * as HashSet from "./HashSet.js"
|
|
|
330
330
|
*/
|
|
331
331
|
export * as Inspectable from "./Inspectable.js"
|
|
332
332
|
|
|
333
|
+
/**
|
|
334
|
+
* This module provides utility functions for working with Iterables in TypeScript.
|
|
335
|
+
*
|
|
336
|
+
* @since 2.0.0
|
|
337
|
+
*/
|
|
338
|
+
export * as Iterable from "./Iterable.js"
|
|
339
|
+
|
|
333
340
|
/**
|
|
334
341
|
* @since 2.0.0
|
|
335
342
|
*/
|
package/src/internal/config.ts
CHANGED
|
@@ -582,8 +582,8 @@ export const validate = dual<
|
|
|
582
582
|
|
|
583
583
|
/** @internal */
|
|
584
584
|
export const withDefault = dual<
|
|
585
|
-
<A2>(def: A2) => <A>(self: Config.Config<A>) => Config.Config<A | A2>,
|
|
586
|
-
<A, A2>(self: Config.Config<A>, def: A2) => Config.Config<A | A2>
|
|
585
|
+
<const A2>(def: A2) => <A>(self: Config.Config<A>) => Config.Config<A | A2>,
|
|
586
|
+
<A, const A2>(self: Config.Config<A>, def: A2) => Config.Config<A | A2>
|
|
587
587
|
>(2, (self, def) =>
|
|
588
588
|
orElseIf(self, {
|
|
589
589
|
orElse: () => succeed(def),
|
|
@@ -500,13 +500,13 @@ export const eventually = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect
|
|
|
500
500
|
|
|
501
501
|
/* @internal */
|
|
502
502
|
export const filterMap = dual<
|
|
503
|
-
<
|
|
504
|
-
pf: (a:
|
|
505
|
-
) =>
|
|
506
|
-
<
|
|
507
|
-
elements: Iterable<
|
|
508
|
-
pf: (a:
|
|
509
|
-
) => Effect.Effect<Array<B>,
|
|
503
|
+
<Eff extends Effect.Effect<any, any, any>, B>(
|
|
504
|
+
pf: (a: Effect.Effect.Success<Eff>) => Option.Option<B>
|
|
505
|
+
) => (elements: Iterable<Eff>) => Effect.Effect<Array<B>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>,
|
|
506
|
+
<Eff extends Effect.Effect<any, any, any>, B>(
|
|
507
|
+
elements: Iterable<Eff>,
|
|
508
|
+
pf: (a: Effect.Effect.Success<Eff>) => Option.Option<B>
|
|
509
|
+
) => Effect.Effect<Array<B>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
|
510
510
|
>(2, (elements, pf) =>
|
|
511
511
|
core.map(
|
|
512
512
|
core.forEachSequential(elements, identity),
|
|
@@ -683,7 +683,9 @@ const findLoop = <A, E, R>(
|
|
|
683
683
|
})
|
|
684
684
|
|
|
685
685
|
/* @internal */
|
|
686
|
-
export const firstSuccessOf = <
|
|
686
|
+
export const firstSuccessOf = <Eff extends Effect.Effect<any, any, any>>(
|
|
687
|
+
effects: Iterable<Eff>
|
|
688
|
+
): Effect.Effect<Effect.Effect.Success<Eff>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> =>
|
|
687
689
|
core.suspend(() => {
|
|
688
690
|
const list = Chunk.fromIterable(effects)
|
|
689
691
|
if (!Chunk.isNonEmpty(list)) {
|
|
@@ -691,7 +693,7 @@ export const firstSuccessOf = <A, E, R>(effects: Iterable<Effect.Effect<A, E, R>
|
|
|
691
693
|
}
|
|
692
694
|
return pipe(
|
|
693
695
|
Chunk.tailNonEmpty(list),
|
|
694
|
-
ReadonlyArray.reduce(Chunk.headNonEmpty(list), (left, right) => core.orElse(left, () => right))
|
|
696
|
+
ReadonlyArray.reduce(Chunk.headNonEmpty(list), (left, right) => core.orElse(left, () => right) as Eff)
|
|
695
697
|
)
|
|
696
698
|
})
|
|
697
699
|
|
|
@@ -239,19 +239,31 @@ export const forkAll: {
|
|
|
239
239
|
options?: {
|
|
240
240
|
readonly discard?: false | undefined
|
|
241
241
|
}
|
|
242
|
-
): <
|
|
242
|
+
): <Eff extends Effect.Effect<any, any, any>>(
|
|
243
|
+
effects: Iterable<Eff>
|
|
244
|
+
) => Effect.Effect<
|
|
245
|
+
Fiber.Fiber<Array<Effect.Effect.Success<Eff>>, Effect.Effect.Error<Eff>>,
|
|
246
|
+
never,
|
|
247
|
+
Effect.Effect.Context<Eff>
|
|
248
|
+
>
|
|
243
249
|
(options: {
|
|
244
250
|
readonly discard: true
|
|
245
|
-
}): <
|
|
246
|
-
|
|
247
|
-
|
|
251
|
+
}): <Eff extends Effect.Effect<any, any, any>>(
|
|
252
|
+
effects: Iterable<Eff>
|
|
253
|
+
) => Effect.Effect<void, never, Effect.Effect.Context<Eff>>
|
|
254
|
+
<Eff extends Effect.Effect<any, any, any>>(
|
|
255
|
+
effects: Iterable<Eff>,
|
|
248
256
|
options?: {
|
|
249
257
|
readonly discard?: false | undefined
|
|
250
258
|
}
|
|
251
|
-
): Effect.Effect<
|
|
252
|
-
|
|
259
|
+
): Effect.Effect<
|
|
260
|
+
Fiber.Fiber<Array<Effect.Effect.Success<Eff>>, Effect.Effect.Error<Eff>>,
|
|
261
|
+
never,
|
|
262
|
+
Effect.Effect.Context<Eff>
|
|
263
|
+
>
|
|
264
|
+
<Eff extends Effect.Effect<any, any, any>>(effects: Iterable<Eff>, options: {
|
|
253
265
|
readonly discard: true
|
|
254
|
-
}): Effect.Effect<void, never,
|
|
266
|
+
}): Effect.Effect<void, never, Effect.Effect.Context<Eff>>
|
|
255
267
|
} = dual((args) => Predicate.isIterable(args[0]), <A, E, R>(effects: Iterable<Effect.Effect<A, E, R>>, options: {
|
|
256
268
|
readonly discard: true
|
|
257
269
|
}): Effect.Effect<void, never, R> =>
|
|
@@ -22,6 +22,7 @@ import { dual, identity, pipe } from "../Function.js"
|
|
|
22
22
|
import { globalValue } from "../GlobalValue.js"
|
|
23
23
|
import * as HashMap from "../HashMap.js"
|
|
24
24
|
import * as HashSet from "../HashSet.js"
|
|
25
|
+
import * as Inspectable from "../Inspectable.js"
|
|
25
26
|
import type { Logger } from "../Logger.js"
|
|
26
27
|
import * as LogLevel from "../LogLevel.js"
|
|
27
28
|
import type * as MetricLabel from "../MetricLabel.js"
|
|
@@ -125,7 +126,9 @@ const runtimeFiberVariance = {
|
|
|
125
126
|
|
|
126
127
|
const absurd = (_: never): never => {
|
|
127
128
|
throw new Error(
|
|
128
|
-
`BUG: FiberRuntime - ${
|
|
129
|
+
`BUG: FiberRuntime - ${
|
|
130
|
+
Inspectable.toStringUnknown(_)
|
|
131
|
+
} - please report an issue at https://github.com/Effect-TS/effect/issues`
|
|
129
132
|
)
|
|
130
133
|
}
|
|
131
134
|
|
|
@@ -1352,50 +1355,41 @@ export const currentMinimumLogLevel: FiberRef.FiberRef<LogLevel.LogLevel> = glob
|
|
|
1352
1355
|
)
|
|
1353
1356
|
|
|
1354
1357
|
/** @internal */
|
|
1355
|
-
export const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
}
|
|
1358
|
+
export const loggerWithConsoleLog = <M, O>(self: Logger<M, O>): Logger<M, void> =>
|
|
1359
|
+
internalLogger.makeLogger((opts) => {
|
|
1360
|
+
const services = FiberRefs.getOrDefault(opts.context, defaultServices.currentServices)
|
|
1361
|
+
Context.get(services, consoleTag).unsafe.log(self.log(opts))
|
|
1362
|
+
})
|
|
1363
|
+
|
|
1364
|
+
/** @internal */
|
|
1365
|
+
export const loggerWithConsoleError = <M, O>(self: Logger<M, O>): Logger<M, void> =>
|
|
1366
|
+
internalLogger.makeLogger((opts) => {
|
|
1367
|
+
const services = FiberRefs.getOrDefault(opts.context, defaultServices.currentServices)
|
|
1368
|
+
Context.get(services, consoleTag).unsafe.error(self.log(opts))
|
|
1369
|
+
})
|
|
1360
1370
|
|
|
1361
1371
|
/** @internal */
|
|
1362
1372
|
export const defaultLogger: Logger<unknown, void> = globalValue(
|
|
1363
1373
|
Symbol.for("effect/Logger/defaultLogger"),
|
|
1364
|
-
() =>
|
|
1365
|
-
internalLogger.makeLogger((options) => {
|
|
1366
|
-
const formatted = internalLogger.stringLogger.log(options)
|
|
1367
|
-
getConsole(options.context).log(formatted)
|
|
1368
|
-
})
|
|
1374
|
+
() => loggerWithConsoleLog(internalLogger.stringLogger)
|
|
1369
1375
|
)
|
|
1370
1376
|
|
|
1371
1377
|
/** @internal */
|
|
1372
1378
|
export const jsonLogger: Logger<unknown, void> = globalValue(
|
|
1373
1379
|
Symbol.for("effect/Logger/jsonLogger"),
|
|
1374
|
-
() =>
|
|
1375
|
-
internalLogger.makeLogger((options) => {
|
|
1376
|
-
const formatted = internalLogger.jsonLogger.log(options)
|
|
1377
|
-
getConsole(options.context).log(formatted)
|
|
1378
|
-
})
|
|
1380
|
+
() => loggerWithConsoleLog(internalLogger.jsonLogger)
|
|
1379
1381
|
)
|
|
1380
1382
|
|
|
1381
1383
|
/** @internal */
|
|
1382
1384
|
export const logFmtLogger: Logger<unknown, void> = globalValue(
|
|
1383
1385
|
Symbol.for("effect/Logger/logFmtLogger"),
|
|
1384
|
-
() =>
|
|
1385
|
-
internalLogger.makeLogger((options) => {
|
|
1386
|
-
const formatted = internalLogger.logfmtLogger.log(options)
|
|
1387
|
-
getConsole(options.context).log(formatted)
|
|
1388
|
-
})
|
|
1386
|
+
() => loggerWithConsoleLog(internalLogger.logfmtLogger)
|
|
1389
1387
|
)
|
|
1390
1388
|
|
|
1391
1389
|
/** @internal */
|
|
1392
1390
|
export const structuredLogger: Logger<unknown, void> = globalValue(
|
|
1393
1391
|
Symbol.for("effect/Logger/structuredLogger"),
|
|
1394
|
-
() =>
|
|
1395
|
-
internalLogger.makeLogger((options) => {
|
|
1396
|
-
const formatted = internalLogger.structuredLogger.log(options)
|
|
1397
|
-
getConsole(options.context).log(formatted)
|
|
1398
|
-
})
|
|
1392
|
+
() => loggerWithConsoleLog(internalLogger.structuredLogger)
|
|
1399
1393
|
)
|
|
1400
1394
|
|
|
1401
1395
|
/** @internal */
|
|
@@ -1419,7 +1413,7 @@ export const tracerLogger = globalValue(
|
|
|
1419
1413
|
return
|
|
1420
1414
|
}
|
|
1421
1415
|
|
|
1422
|
-
const attributes = Object.fromEntries(HashMap.map(annotations,
|
|
1416
|
+
const attributes = Object.fromEntries(HashMap.map(annotations, Inspectable.toStringUnknown))
|
|
1423
1417
|
attributes["effect.fiberId"] = FiberId.threadName(fiberId)
|
|
1424
1418
|
attributes["effect.logLevel"] = logLevel.label
|
|
1425
1419
|
|
|
@@ -1828,13 +1822,13 @@ export const allWith = <
|
|
|
1828
1822
|
): Effect.All.Return<Arg, O> => all(arg, options)
|
|
1829
1823
|
|
|
1830
1824
|
/* @internal */
|
|
1831
|
-
export const allSuccesses = <
|
|
1832
|
-
elements: Iterable<
|
|
1825
|
+
export const allSuccesses = <Eff extends Effect.Effect<any, any, any>>(
|
|
1826
|
+
elements: Iterable<Eff>,
|
|
1833
1827
|
options?: {
|
|
1834
1828
|
readonly concurrency?: Concurrency | undefined
|
|
1835
1829
|
readonly batching?: boolean | "inherit" | undefined
|
|
1836
1830
|
}
|
|
1837
|
-
): Effect.Effect<Array<
|
|
1831
|
+
): Effect.Effect<Array<Effect.Effect.Success<Eff>>, never, Effect.Effect.Context<Eff>> =>
|
|
1838
1832
|
core.map(
|
|
1839
1833
|
all(RA.fromIterable(elements).map(core.exit), options),
|
|
1840
1834
|
RA.filterMap((exit) => core.exitIsSuccess(exit) ? Option.some(exit.effect_instruction_i0) : Option.none())
|
|
@@ -2299,14 +2293,23 @@ const forkWithScopeOverride = <A, E, R>(
|
|
|
2299
2293
|
|
|
2300
2294
|
/* @internal */
|
|
2301
2295
|
export const mergeAll = dual<
|
|
2302
|
-
<Z,
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2296
|
+
<Z, Eff extends Effect.Effect<any, any, any>>(
|
|
2297
|
+
zero: Z,
|
|
2298
|
+
f: (z: Z, a: Effect.Effect.Success<Eff>, i: number) => Z,
|
|
2299
|
+
options?: {
|
|
2300
|
+
readonly concurrency?: Concurrency | undefined
|
|
2301
|
+
readonly batching?: boolean | "inherit" | undefined
|
|
2302
|
+
}
|
|
2303
|
+
) => (elements: Iterable<Eff>) => Effect.Effect<Z, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>,
|
|
2304
|
+
<Eff extends Effect.Effect<any, any, any>, Z>(
|
|
2305
|
+
elements: Iterable<Eff>,
|
|
2306
|
+
zero: Z,
|
|
2307
|
+
f: (z: Z, a: Effect.Effect.Success<Eff>, i: number) => Z,
|
|
2308
|
+
options?: {
|
|
2309
|
+
readonly concurrency?: Concurrency | undefined
|
|
2310
|
+
readonly batching?: boolean | "inherit" | undefined
|
|
2311
|
+
}
|
|
2312
|
+
) => Effect.Effect<Z, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
|
2310
2313
|
>(
|
|
2311
2314
|
(args) => Predicate.isFunction(args[2]),
|
|
2312
2315
|
<A, E, R, Z>(elements: Iterable<Effect.Effect<A, E, R>>, zero: Z, f: (z: Z, a: A, i: number) => Z, options?: {
|
|
@@ -2416,7 +2419,13 @@ export const validateAll = dual<
|
|
|
2416
2419
|
)
|
|
2417
2420
|
|
|
2418
2421
|
/* @internal */
|
|
2419
|
-
export const raceAll
|
|
2422
|
+
export const raceAll: <Eff extends Effect.Effect<any, any, any>>(
|
|
2423
|
+
all: Iterable<Eff>
|
|
2424
|
+
) => Effect.Effect<Effect.Effect.Success<Eff>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> = <
|
|
2425
|
+
A,
|
|
2426
|
+
E,
|
|
2427
|
+
R
|
|
2428
|
+
>(all: Iterable<Effect.Effect<A, E, R>>): Effect.Effect<A, E, R> => {
|
|
2420
2429
|
const list = Chunk.fromIterable(all)
|
|
2421
2430
|
if (!Chunk.isNonEmpty(list)) {
|
|
2422
2431
|
return core.dieSync(() => new core.IllegalArgumentException(`Received an empty collection of effects`))
|
|
@@ -2525,27 +2534,27 @@ const raceAllArbiter = <E, E1, A, A1>(
|
|
|
2525
2534
|
|
|
2526
2535
|
/* @internal */
|
|
2527
2536
|
export const reduceEffect = dual<
|
|
2528
|
-
<
|
|
2529
|
-
zero: Effect.Effect<
|
|
2530
|
-
f: (acc: NoInfer<
|
|
2537
|
+
<Z, E, R, Eff extends Effect.Effect<any, any, any>>(
|
|
2538
|
+
zero: Effect.Effect<Z, E, R>,
|
|
2539
|
+
f: (acc: NoInfer<Z>, a: Effect.Effect.Success<Eff>, i: number) => Z,
|
|
2531
2540
|
options?: {
|
|
2532
2541
|
readonly concurrency?: Concurrency | undefined
|
|
2533
2542
|
readonly batching?: boolean | "inherit" | undefined
|
|
2534
2543
|
}
|
|
2535
|
-
) => (elements: Iterable<Effect.Effect<
|
|
2536
|
-
<
|
|
2537
|
-
elements: Iterable<
|
|
2538
|
-
zero: Effect.Effect<
|
|
2539
|
-
f: (acc: NoInfer<
|
|
2544
|
+
) => (elements: Iterable<Eff>) => Effect.Effect<Z, E | Effect.Effect.Error<Eff>, R | Effect.Effect.Context<Eff>>,
|
|
2545
|
+
<Eff extends Effect.Effect<any, any, any>, Z, E, R>(
|
|
2546
|
+
elements: Iterable<Eff>,
|
|
2547
|
+
zero: Effect.Effect<Z, E, R>,
|
|
2548
|
+
f: (acc: NoInfer<Z>, a: Effect.Effect.Success<Eff>, i: number) => Z,
|
|
2540
2549
|
options?: {
|
|
2541
2550
|
readonly concurrency?: Concurrency | undefined
|
|
2542
2551
|
readonly batching?: boolean | "inherit" | undefined
|
|
2543
2552
|
}
|
|
2544
|
-
) => Effect.Effect<
|
|
2545
|
-
>((args) => Predicate.isIterable(args[0]), <A, E, R>(
|
|
2553
|
+
) => Effect.Effect<Z, E | Effect.Effect.Error<Eff>, R | Effect.Effect.Context<Eff>>
|
|
2554
|
+
>((args) => Predicate.isIterable(args[0]), <A, E, R, Z>(
|
|
2546
2555
|
elements: Iterable<Effect.Effect<A, E, R>>,
|
|
2547
|
-
zero: Effect.Effect<
|
|
2548
|
-
f: (acc: NoInfer<
|
|
2556
|
+
zero: Effect.Effect<Z, E, R>,
|
|
2557
|
+
f: (acc: NoInfer<Z>, a: NoInfer<A>, i: number) => Z,
|
|
2549
2558
|
options?: {
|
|
2550
2559
|
readonly concurrency?: Concurrency | undefined
|
|
2551
2560
|
readonly batching?: boolean | "inherit" | undefined
|
|
@@ -2559,14 +2568,14 @@ export const reduceEffect = dual<
|
|
|
2559
2568
|
pipe(
|
|
2560
2569
|
mergeAll(
|
|
2561
2570
|
[zero, ...elements],
|
|
2562
|
-
Option.none()
|
|
2571
|
+
Option.none<Z>(),
|
|
2563
2572
|
(acc, elem, i) => {
|
|
2564
2573
|
switch (acc._tag) {
|
|
2565
2574
|
case "None": {
|
|
2566
|
-
return Option.some(elem)
|
|
2575
|
+
return Option.some(elem as Z)
|
|
2567
2576
|
}
|
|
2568
2577
|
case "Some": {
|
|
2569
|
-
return Option.some(f(acc.value, elem, i))
|
|
2578
|
+
return Option.some(f(acc.value, elem as A, i))
|
|
2570
2579
|
}
|
|
2571
2580
|
}
|
|
2572
2581
|
},
|
package/src/internal/logger.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LazyArg } from "../Function.js"
|
|
2
2
|
import { constVoid, dual, pipe } from "../Function.js"
|
|
3
3
|
import * as HashMap from "../HashMap.js"
|
|
4
|
+
import * as Inspectable from "../Inspectable.js"
|
|
4
5
|
import * as List from "../List.js"
|
|
5
6
|
import type * as Logger from "../Logger.js"
|
|
6
7
|
import type * as LogLevel from "../LogLevel.js"
|
|
@@ -167,7 +168,7 @@ export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown,
|
|
|
167
168
|
]
|
|
168
169
|
|
|
169
170
|
let output = outputArray.join(" ")
|
|
170
|
-
const stringMessage =
|
|
171
|
+
const stringMessage = Inspectable.toStringUnknown(message)
|
|
171
172
|
|
|
172
173
|
if (stringMessage.length > 0) {
|
|
173
174
|
output = output + " message="
|
|
@@ -205,7 +206,7 @@ export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown,
|
|
|
205
206
|
}
|
|
206
207
|
output = output + filterKeyName(key)
|
|
207
208
|
output = output + "="
|
|
208
|
-
output = appendQuoted(
|
|
209
|
+
output = appendQuoted(Inspectable.toStringUnknown(value), output)
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
|
|
@@ -213,14 +214,6 @@ export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown,
|
|
|
213
214
|
}
|
|
214
215
|
)
|
|
215
216
|
|
|
216
|
-
export const serializeUnknown = (u: unknown): string => {
|
|
217
|
-
try {
|
|
218
|
-
return typeof u === "object" ? jsonStringifyCircular(u) : String(u)
|
|
219
|
-
} catch (_) {
|
|
220
|
-
return String(u)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
217
|
/** @internal */
|
|
225
218
|
const escapeDoubleQuotes = (str: string) => `"${str.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`
|
|
226
219
|
|
|
@@ -242,7 +235,7 @@ export const logfmtLogger = makeLogger<unknown, string>(
|
|
|
242
235
|
]
|
|
243
236
|
|
|
244
237
|
let output = outputArray.join(" ")
|
|
245
|
-
const stringMessage =
|
|
238
|
+
const stringMessage = Inspectable.toStringUnknown(message, 0)
|
|
246
239
|
|
|
247
240
|
if (stringMessage.length > 0) {
|
|
248
241
|
output = output + " message="
|
|
@@ -280,7 +273,7 @@ export const logfmtLogger = makeLogger<unknown, string>(
|
|
|
280
273
|
}
|
|
281
274
|
output = output + filterKeyName(key)
|
|
282
275
|
output = output + "="
|
|
283
|
-
output = appendQuotedLogfmt(
|
|
276
|
+
output = appendQuotedLogfmt(Inspectable.toStringUnknown(value, 0), output)
|
|
284
277
|
}
|
|
285
278
|
}
|
|
286
279
|
|
|
@@ -340,23 +333,8 @@ export const structuredMessage = (u: unknown): unknown => {
|
|
|
340
333
|
}
|
|
341
334
|
}
|
|
342
335
|
|
|
343
|
-
const jsonStringifyCircular = (obj: unknown) => {
|
|
344
|
-
let cache: Array<unknown> = []
|
|
345
|
-
const retVal = JSON.stringify(
|
|
346
|
-
obj,
|
|
347
|
-
(_key, value) =>
|
|
348
|
-
typeof value === "object" && value !== null
|
|
349
|
-
? cache.includes(value)
|
|
350
|
-
? undefined // circular reference
|
|
351
|
-
: cache.push(value) && value
|
|
352
|
-
: value
|
|
353
|
-
)
|
|
354
|
-
;(cache as any) = undefined
|
|
355
|
-
return retVal
|
|
356
|
-
}
|
|
357
|
-
|
|
358
336
|
/** @internal */
|
|
359
|
-
export const jsonLogger = map(structuredLogger,
|
|
337
|
+
export const jsonLogger = map(structuredLogger, Inspectable.stringifyCircular)
|
|
360
338
|
|
|
361
339
|
/** @internal */
|
|
362
340
|
const filterKeyName = (key: string) => key.replace(/[\s="]/g, "_")
|
package/src/internal/runtime.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as FiberId from "../FiberId.js"
|
|
|
8
8
|
import type * as FiberRef from "../FiberRef.js"
|
|
9
9
|
import * as FiberRefs from "../FiberRefs.js"
|
|
10
10
|
import { dual, pipe } from "../Function.js"
|
|
11
|
-
import
|
|
11
|
+
import * as Inspectable from "../Inspectable.js"
|
|
12
12
|
import * as Option from "../Option.js"
|
|
13
13
|
import { pipeArguments } from "../Pipeable.js"
|
|
14
14
|
import * as Predicate from "../Predicate.js"
|
|
@@ -131,38 +131,22 @@ export const unsafeRunSync = <R>(runtime: Runtime.Runtime<R>) => <A, E>(effect:
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
class AsyncFiberExceptionImpl<A, E = never> extends Error implements Runtime.AsyncFiberException<A, E> {
|
|
135
|
+
readonly _tag = "AsyncFiberException"
|
|
136
|
+
constructor(readonly fiber: Fiber.RuntimeFiber<A, E>) {
|
|
137
|
+
super(
|
|
138
|
+
`Fiber #${fiber.id().id} cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
|
|
139
|
+
)
|
|
140
|
+
this.name = this._tag
|
|
141
|
+
this.stack = this.message
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
const asyncFiberException = <A, E>(fiber: Fiber.RuntimeFiber<A, E>): Runtime.AsyncFiberException<A, E> => {
|
|
135
146
|
const limit = Error.stackTraceLimit
|
|
136
147
|
Error.stackTraceLimit = 0
|
|
137
|
-
const error =
|
|
148
|
+
const error = new AsyncFiberExceptionImpl(fiber)
|
|
138
149
|
Error.stackTraceLimit = limit
|
|
139
|
-
const message =
|
|
140
|
-
`Fiber #${fiber.id().id} cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
|
|
141
|
-
const _tag = "AsyncFiberException"
|
|
142
|
-
Object.defineProperties(error, {
|
|
143
|
-
_tag: {
|
|
144
|
-
value: _tag
|
|
145
|
-
},
|
|
146
|
-
fiber: {
|
|
147
|
-
value: fiber
|
|
148
|
-
},
|
|
149
|
-
message: {
|
|
150
|
-
value: message
|
|
151
|
-
},
|
|
152
|
-
name: {
|
|
153
|
-
value: _tag
|
|
154
|
-
},
|
|
155
|
-
toString: {
|
|
156
|
-
get() {
|
|
157
|
-
return () => message
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
[NodeInspectSymbol]: {
|
|
161
|
-
get() {
|
|
162
|
-
return () => message
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
150
|
return error
|
|
167
151
|
}
|
|
168
152
|
|
|
@@ -177,37 +161,46 @@ export const FiberFailureCauseId: Runtime.FiberFailureCauseId = Symbol.for(
|
|
|
177
161
|
"effect/Runtime/FiberFailure/Cause"
|
|
178
162
|
) as any
|
|
179
163
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
164
|
+
class FiberFailureImpl extends Error implements Runtime.FiberFailure {
|
|
165
|
+
readonly [FiberFailureId]: Runtime.FiberFailureId
|
|
166
|
+
readonly [FiberFailureCauseId]: Cause.Cause<unknown>
|
|
167
|
+
constructor(cause: Cause.Cause<unknown>) {
|
|
168
|
+
super()
|
|
169
|
+
|
|
170
|
+
this[FiberFailureId] = FiberFailureId
|
|
171
|
+
this[FiberFailureCauseId] = cause
|
|
172
|
+
|
|
173
|
+
const prettyErrors = InternalCause.prettyErrors(cause)
|
|
174
|
+
if (prettyErrors.length > 0) {
|
|
175
|
+
const head = prettyErrors[0]
|
|
176
|
+
this.name = head.message.split(":")[0]
|
|
177
|
+
this.message = head.message.substring(this.name.length + 2)
|
|
178
|
+
this.stack = InternalCause.pretty(cause)
|
|
179
|
+
}
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
export const fiberFailure = <E>(cause: Cause.Cause<E>): Runtime.FiberFailure => {
|
|
186
|
-
const limit = Error.stackTraceLimit
|
|
187
|
-
Error.stackTraceLimit = 0
|
|
188
|
-
const error = (new Error()) as Mutable<Runtime.FiberFailure>
|
|
189
|
-
Error.stackTraceLimit = limit
|
|
190
|
-
const prettyErrors = InternalCause.prettyErrors(cause)
|
|
191
|
-
if (prettyErrors.length > 0) {
|
|
192
|
-
const head = prettyErrors[0]
|
|
193
|
-
error.name = head.message.split(":")[0]
|
|
194
|
-
error.message = head.message.substring(error.name.length + 2)
|
|
195
|
-
error.stack = InternalCause.pretty(cause)
|
|
181
|
+
this.name = `(FiberFailure) ${this.name}`
|
|
196
182
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
error.toJSON = () => {
|
|
183
|
+
|
|
184
|
+
toJSON(): unknown {
|
|
200
185
|
return {
|
|
201
186
|
_id: "FiberFailure",
|
|
202
|
-
cause:
|
|
187
|
+
cause: this[FiberFailureCauseId].toJSON()
|
|
203
188
|
}
|
|
204
189
|
}
|
|
205
|
-
|
|
206
|
-
return
|
|
190
|
+
toString(): string {
|
|
191
|
+
return "(FiberFailure) " + InternalCause.pretty(this[FiberFailureCauseId])
|
|
207
192
|
}
|
|
208
|
-
|
|
209
|
-
return
|
|
193
|
+
[Inspectable.NodeInspectSymbol](): unknown {
|
|
194
|
+
return this.toString()
|
|
210
195
|
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @internal */
|
|
199
|
+
export const fiberFailure = <E>(cause: Cause.Cause<E>): Runtime.FiberFailure => {
|
|
200
|
+
const limit = Error.stackTraceLimit
|
|
201
|
+
Error.stackTraceLimit = 0
|
|
202
|
+
const error = new FiberFailureImpl(cause)
|
|
203
|
+
Error.stackTraceLimit = limit
|
|
211
204
|
return error
|
|
212
205
|
}
|
|
213
206
|
|
package/src/internal/schedule.ts
CHANGED
|
@@ -1951,12 +1951,12 @@ export const retryOrElse_Effect = dual<
|
|
|
1951
1951
|
<A1, E, R1, A2, E2, R2>(
|
|
1952
1952
|
policy: Schedule.Schedule<A1, Types.NoInfer<E>, R1>,
|
|
1953
1953
|
orElse: (e: Types.NoInfer<E>, out: A1) => Effect.Effect<A2, E2, R2>
|
|
1954
|
-
) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2,
|
|
1954
|
+
) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2, R | R1 | R2>,
|
|
1955
1955
|
<A, E, R, A1, R1, A2, E2, R2>(
|
|
1956
1956
|
self: Effect.Effect<A, E, R>,
|
|
1957
1957
|
policy: Schedule.Schedule<A1, Types.NoInfer<E>, R1>,
|
|
1958
1958
|
orElse: (e: Types.NoInfer<E>, out: A1) => Effect.Effect<A2, E2, R2>
|
|
1959
|
-
) => Effect.Effect<A | A2,
|
|
1959
|
+
) => Effect.Effect<A | A2, E2, R | R1 | R2>
|
|
1960
1960
|
>(3, (self, policy, orElse) =>
|
|
1961
1961
|
core.flatMap(
|
|
1962
1962
|
driver(policy),
|
|
@@ -1968,7 +1968,7 @@ const retryOrElse_EffectLoop = <A, E, R, R1, A1, A2, E2, R2>(
|
|
|
1968
1968
|
self: Effect.Effect<A, E, R>,
|
|
1969
1969
|
driver: Schedule.ScheduleDriver<A1, E, R1>,
|
|
1970
1970
|
orElse: (e: E, out: A1) => Effect.Effect<A2, E2, R2>
|
|
1971
|
-
): Effect.Effect<A | A2,
|
|
1971
|
+
): Effect.Effect<A | A2, E2, R | R1 | R2> => {
|
|
1972
1972
|
return core.catchAll(
|
|
1973
1973
|
self,
|
|
1974
1974
|
(e) =>
|
package/src/internal/version.ts
CHANGED