effect 3.5.9 → 3.6.0
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/DateTime/package.json +6 -0
- package/dist/cjs/DateTime.js +1514 -0
- package/dist/cjs/DateTime.js.map +1 -0
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/Metric.js.map +1 -1
- package/dist/cjs/Predicate.js +8 -0
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Random.js +16 -1
- package/dist/cjs/Random.js.map +1 -1
- package/dist/cjs/Stream.js +82 -3
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/Struct.js +23 -1
- package/dist/cjs/Struct.js.map +1 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/configProvider.js.map +1 -1
- package/dist/cjs/internal/core.js +1 -1
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/defaultServices.js +9 -2
- package/dist/cjs/internal/defaultServices.js.map +1 -1
- package/dist/cjs/internal/metric.js.map +1 -1
- package/dist/cjs/internal/stream/emit.js +73 -1
- package/dist/cjs/internal/stream/emit.js.map +1 -1
- package/dist/cjs/internal/stream.js +30 -22
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/ConfigProvider.d.ts +2 -2
- package/dist/dts/ConfigProvider.d.ts.map +1 -1
- package/dist/dts/DateTime.d.ts +1265 -0
- package/dist/dts/DateTime.d.ts.map +1 -0
- package/dist/dts/Effect.d.ts +12 -0
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/List.d.ts +2 -1
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/dts/Metric.d.ts +1 -1
- package/dist/dts/Metric.d.ts.map +1 -1
- package/dist/dts/MetricRegistry.d.ts +1 -1
- package/dist/dts/MetricRegistry.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +63 -2
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Random.d.ts +18 -0
- package/dist/dts/Random.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +91 -0
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/StreamEmit.d.ts +44 -0
- package/dist/dts/StreamEmit.d.ts.map +1 -1
- package/dist/dts/Struct.d.ts +21 -0
- package/dist/dts/Struct.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/defaultServices.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/DateTime.js +1465 -0
- package/dist/esm/DateTime.js.map +1 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/Metric.js.map +1 -1
- package/dist/esm/Predicate.js +8 -0
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Random.js +15 -0
- package/dist/esm/Random.js.map +1 -1
- package/dist/esm/Stream.js +79 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/Struct.js +21 -0
- package/dist/esm/Struct.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/configProvider.js.map +1 -1
- package/dist/esm/internal/core.js +1 -1
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/defaultServices.js +6 -0
- package/dist/esm/internal/defaultServices.js.map +1 -1
- package/dist/esm/internal/metric.js.map +1 -1
- package/dist/esm/internal/stream/emit.js +71 -0
- package/dist/esm/internal/stream/emit.js.map +1 -1
- package/dist/esm/internal/stream.js +24 -18
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +9 -1
- package/src/ConfigProvider.ts +2 -2
- package/src/DateTime.ts +2104 -0
- package/src/Effect.ts +22 -0
- package/src/List.ts +3 -2
- package/src/Metric.ts +1 -1
- package/src/MetricRegistry.ts +1 -1
- package/src/Predicate.ts +68 -8
- package/src/Random.ts +24 -0
- package/src/Stream.ts +105 -0
- package/src/StreamEmit.ts +53 -0
- package/src/Struct.ts +22 -0
- package/src/index.ts +5 -0
- package/src/internal/configProvider.ts +20 -20
- package/src/internal/core.ts +37 -12
- package/src/internal/defaultServices.ts +14 -0
- package/src/internal/metric/registry.ts +1 -1
- package/src/internal/metric.ts +2 -2
- package/src/internal/stream/emit.ts +77 -0
- package/src/internal/stream.ts +86 -18
- package/src/internal/version.ts +1 -1
package/src/Effect.ts
CHANGED
|
@@ -4029,6 +4029,12 @@ export const tap: {
|
|
|
4029
4029
|
) => [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
|
|
4030
4030
|
: [X] extends [PromiseLike<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
|
|
4031
4031
|
: Effect<A, E, R>
|
|
4032
|
+
<A, X, E1, R1>(
|
|
4033
|
+
f: (a: NoInfer<A>) => Effect<X, E1, R1>,
|
|
4034
|
+
options: { onlyEffect: true }
|
|
4035
|
+
): <E, R>(
|
|
4036
|
+
self: Effect<A, E, R>
|
|
4037
|
+
) => Effect<A, E | E1, R | R1>
|
|
4032
4038
|
<X>(
|
|
4033
4039
|
f: NotFunction<X>
|
|
4034
4040
|
): <A, E, R>(
|
|
@@ -4036,18 +4042,34 @@ export const tap: {
|
|
|
4036
4042
|
) => [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
|
|
4037
4043
|
: [X] extends [PromiseLike<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
|
|
4038
4044
|
: Effect<A, E, R>
|
|
4045
|
+
<X, E1, R1>(
|
|
4046
|
+
f: Effect<X, E1, R1>,
|
|
4047
|
+
options: { onlyEffect: true }
|
|
4048
|
+
): <A, E, R>(
|
|
4049
|
+
self: Effect<A, E, R>
|
|
4050
|
+
) => Effect<A, E | E1, R | R1>
|
|
4039
4051
|
<A, E, R, X>(
|
|
4040
4052
|
self: Effect<A, E, R>,
|
|
4041
4053
|
f: (a: NoInfer<A>) => X
|
|
4042
4054
|
): [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
|
|
4043
4055
|
: [X] extends [PromiseLike<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
|
|
4044
4056
|
: Effect<A, E, R>
|
|
4057
|
+
<A, E, R, X, E1, R1>(
|
|
4058
|
+
self: Effect<A, E, R>,
|
|
4059
|
+
f: (a: NoInfer<A>) => Effect<X, E1, R1>,
|
|
4060
|
+
options: { onlyEffect: true }
|
|
4061
|
+
): Effect<A, E | E1, R | R1>
|
|
4045
4062
|
<A, E, R, X>(
|
|
4046
4063
|
self: Effect<A, E, R>,
|
|
4047
4064
|
f: NotFunction<X>
|
|
4048
4065
|
): [X] extends [Effect<infer _A1, infer E1, infer R1>] ? Effect<A, E | E1, R | R1>
|
|
4049
4066
|
: [X] extends [PromiseLike<infer _A1>] ? Effect<A, E | Cause.UnknownException, R>
|
|
4050
4067
|
: Effect<A, E, R>
|
|
4068
|
+
<A, E, R, X, E1, R1>(
|
|
4069
|
+
self: Effect<A, E, R>,
|
|
4070
|
+
f: Effect<X, E1, R1>,
|
|
4071
|
+
options: { onlyEffect: true }
|
|
4072
|
+
): Effect<A, E | E1, R | R1>
|
|
4051
4073
|
} = core.tap
|
|
4052
4074
|
|
|
4053
4075
|
/**
|
package/src/List.ts
CHANGED
|
@@ -29,6 +29,7 @@ import * as Equivalence from "./Equivalence.js"
|
|
|
29
29
|
import { dual, identity, unsafeCoerce } from "./Function.js"
|
|
30
30
|
import * as Hash from "./Hash.js"
|
|
31
31
|
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
|
|
32
|
+
import type { nonEmpty, NonEmptyIterable } from "./NonEmptyIterable.js"
|
|
32
33
|
import * as Option from "./Option.js"
|
|
33
34
|
import type { Pipeable } from "./Pipeable.js"
|
|
34
35
|
import { pipeArguments } from "./Pipeable.js"
|
|
@@ -72,7 +73,7 @@ export interface Nil<out A> extends Iterable<A>, Equal.Equal, Pipeable, Inspecta
|
|
|
72
73
|
* @since 2.0.0
|
|
73
74
|
* @category models
|
|
74
75
|
*/
|
|
75
|
-
export interface Cons<out A> extends
|
|
76
|
+
export interface Cons<out A> extends NonEmptyIterable<A>, Equal.Equal, Pipeable, Inspectable {
|
|
76
77
|
readonly [TypeId]: TypeId
|
|
77
78
|
readonly _tag: "Cons"
|
|
78
79
|
readonly head: A
|
|
@@ -96,7 +97,7 @@ export const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equ
|
|
|
96
97
|
|
|
97
98
|
const _equivalence = getEquivalence(Equal.equals)
|
|
98
99
|
|
|
99
|
-
const ConsProto: Omit<Cons<unknown>, "head" | "tail"> = {
|
|
100
|
+
const ConsProto: Omit<Cons<unknown>, "head" | "tail" | typeof nonEmpty> = {
|
|
100
101
|
[TypeId]: TypeId,
|
|
101
102
|
_tag: "Cons",
|
|
102
103
|
toString(this: Cons<unknown>) {
|
package/src/Metric.ts
CHANGED
|
@@ -361,7 +361,7 @@ export const set: {
|
|
|
361
361
|
* @since 2.0.0
|
|
362
362
|
* @category getters
|
|
363
363
|
*/
|
|
364
|
-
export const snapshot: Effect.Effect<
|
|
364
|
+
export const snapshot: Effect.Effect<Array<MetricPair.MetricPair.Untyped>> = internal.snapshot
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
367
|
* Creates a metric that ignores input and produces constant output.
|
package/src/MetricRegistry.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type MetricRegistryTypeId = typeof MetricRegistryTypeId
|
|
|
25
25
|
*/
|
|
26
26
|
export interface MetricRegistry {
|
|
27
27
|
readonly [MetricRegistryTypeId]: MetricRegistryTypeId
|
|
28
|
-
snapshot():
|
|
28
|
+
snapshot(): Array<MetricPair.MetricPair.Untyped>
|
|
29
29
|
get<Type extends MetricKeyType.MetricKeyType<any, any>>(
|
|
30
30
|
key: MetricKey.MetricKey<Type>
|
|
31
31
|
): MetricHook.MetricHook<
|
package/src/Predicate.ts
CHANGED
|
@@ -29,6 +29,45 @@ export interface Refinement<in A, out B extends A> {
|
|
|
29
29
|
(a: A): a is B
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @since 3.6.0
|
|
34
|
+
* @category type-level
|
|
35
|
+
*/
|
|
36
|
+
export declare namespace Predicate {
|
|
37
|
+
/**
|
|
38
|
+
* @since 3.6.0
|
|
39
|
+
* @category type-level
|
|
40
|
+
*/
|
|
41
|
+
export type In<T extends Any> = [T] extends [Predicate<infer _A>] ? _A : never
|
|
42
|
+
/**
|
|
43
|
+
* @since 3.6.0
|
|
44
|
+
* @category type-level
|
|
45
|
+
*/
|
|
46
|
+
export type Any = Predicate<any>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @since 3.6.0
|
|
51
|
+
* @category type-level
|
|
52
|
+
*/
|
|
53
|
+
export declare namespace Refinement {
|
|
54
|
+
/**
|
|
55
|
+
* @since 3.6.0
|
|
56
|
+
* @category type-level
|
|
57
|
+
*/
|
|
58
|
+
export type In<T extends Any> = [T] extends [Refinement<infer _A, infer _>] ? _A : never
|
|
59
|
+
/**
|
|
60
|
+
* @since 3.6.0
|
|
61
|
+
* @category type-level
|
|
62
|
+
*/
|
|
63
|
+
export type Out<T extends Any> = [T] extends [Refinement<infer _, infer _B>] ? _B : never
|
|
64
|
+
/**
|
|
65
|
+
* @since 3.6.0
|
|
66
|
+
* @category type-level
|
|
67
|
+
*/
|
|
68
|
+
export type Any = Refinement<any, any>
|
|
69
|
+
}
|
|
70
|
+
|
|
32
71
|
/**
|
|
33
72
|
* Given a `Predicate<A>` returns a `Predicate<B>`
|
|
34
73
|
*
|
|
@@ -686,23 +725,44 @@ export const productMany = <A>(
|
|
|
686
725
|
* Similar to `Promise.all` but operates on `Predicate`s.
|
|
687
726
|
*
|
|
688
727
|
* ```
|
|
728
|
+
* [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>
|
|
689
729
|
* [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>
|
|
730
|
+
* [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>
|
|
690
731
|
* ```
|
|
691
732
|
*
|
|
692
733
|
* @since 2.0.0
|
|
693
734
|
*/
|
|
694
|
-
export const tuple
|
|
695
|
-
|
|
696
|
-
|
|
735
|
+
export const tuple: {
|
|
736
|
+
<T extends ReadonlyArray<Predicate.Any>>(
|
|
737
|
+
...elements: T
|
|
738
|
+
): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>
|
|
739
|
+
: Refinement<
|
|
740
|
+
{ readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },
|
|
741
|
+
{ readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }
|
|
742
|
+
>
|
|
743
|
+
} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any
|
|
697
744
|
|
|
698
745
|
/**
|
|
746
|
+
* ```
|
|
747
|
+
* { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>
|
|
748
|
+
* { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>
|
|
749
|
+
* { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>
|
|
750
|
+
* ```
|
|
751
|
+
*
|
|
699
752
|
* @since 2.0.0
|
|
700
753
|
*/
|
|
701
|
-
export const struct
|
|
702
|
-
|
|
703
|
-
|
|
754
|
+
export const struct: {
|
|
755
|
+
<R extends Record<string, Predicate.Any>>(
|
|
756
|
+
fields: R
|
|
757
|
+
): [Extract<R[keyof R], Refinement.Any>] extends [never] ?
|
|
758
|
+
Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :
|
|
759
|
+
Refinement<
|
|
760
|
+
{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },
|
|
761
|
+
{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }
|
|
762
|
+
>
|
|
763
|
+
} = (<R extends Record<string, Predicate.Any>>(fields: R) => {
|
|
704
764
|
const keys = Object.keys(fields)
|
|
705
|
-
return (a) => {
|
|
765
|
+
return (a: Record<string, unknown>) => {
|
|
706
766
|
for (const key of keys) {
|
|
707
767
|
if (!fields[key](a[key])) {
|
|
708
768
|
return false
|
|
@@ -710,7 +770,7 @@ export const struct = <R extends Record<string, Predicate<any>>>(
|
|
|
710
770
|
}
|
|
711
771
|
return true
|
|
712
772
|
}
|
|
713
|
-
}
|
|
773
|
+
}) as any
|
|
714
774
|
|
|
715
775
|
/**
|
|
716
776
|
* Negates the result of a given predicate.
|
package/src/Random.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 2.0.0
|
|
3
3
|
*/
|
|
4
|
+
import type * as Array from "./Array.js"
|
|
5
|
+
import type * as Cause from "./Cause.js"
|
|
4
6
|
import type * as Chunk from "./Chunk.js"
|
|
5
7
|
import type * as Context from "./Context.js"
|
|
6
8
|
import type * as Effect from "./Effect.js"
|
|
7
9
|
import * as defaultServices from "./internal/defaultServices.js"
|
|
8
10
|
import * as internal from "./internal/random.js"
|
|
11
|
+
import type * as NonEmptyIterable from "./NonEmptyIterable.js"
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* @since 2.0.0
|
|
@@ -103,6 +106,27 @@ export const nextIntBetween: (min: number, max: number) => Effect.Effect<number>
|
|
|
103
106
|
*/
|
|
104
107
|
export const shuffle: <A>(elements: Iterable<A>) => Effect.Effect<Chunk.Chunk<A>> = defaultServices.shuffle
|
|
105
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Get a random element from an iterable.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* import { Effect, Random } from "effect"
|
|
114
|
+
*
|
|
115
|
+
* Effect.gen(function* () {
|
|
116
|
+
* const randomItem = yield* Random.choice([1, 2, 3])
|
|
117
|
+
* console.log(randomItem)
|
|
118
|
+
* })
|
|
119
|
+
*
|
|
120
|
+
* @since 3.6.0
|
|
121
|
+
* @category constructors
|
|
122
|
+
*/
|
|
123
|
+
export const choice: <Self extends Iterable<unknown>>(
|
|
124
|
+
elements: Self
|
|
125
|
+
) => Self extends NonEmptyIterable.NonEmptyIterable<infer A> ? Effect.Effect<A>
|
|
126
|
+
: Self extends Array.NonEmptyReadonlyArray<infer A> ? Effect.Effect<A>
|
|
127
|
+
: Self extends Iterable<infer A> ? Effect.Effect<A, Cause.NoSuchElementException>
|
|
128
|
+
: never = defaultServices.choice
|
|
129
|
+
|
|
106
130
|
/**
|
|
107
131
|
* Retreives the `Random` service from the context and uses it to run the
|
|
108
132
|
* specified workflow.
|
package/src/Stream.ts
CHANGED
|
@@ -373,6 +373,46 @@ export const asyncEffect: <A, E = never, R = never>(
|
|
|
373
373
|
} | undefined
|
|
374
374
|
) => Stream<A, E, R> = internal.asyncEffect
|
|
375
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Creates a stream from an external push-based resource.
|
|
378
|
+
*
|
|
379
|
+
* You can use the `emit` helper to emit values to the stream. The `emit` helper
|
|
380
|
+
* returns a boolean indicating whether the value was emitted or not.
|
|
381
|
+
*
|
|
382
|
+
* You can also use the `emit` helper to signal the end of the stream by
|
|
383
|
+
* using apis such as `emit.end` or `emit.fail`.
|
|
384
|
+
*
|
|
385
|
+
* By default it uses an "unbounded" buffer size.
|
|
386
|
+
* You can customize the buffer size and strategy by passing an object as the
|
|
387
|
+
* second argument with the `bufferSize` and `strategy` fields.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* import { Effect, Stream } from "effect"
|
|
391
|
+
*
|
|
392
|
+
* Stream.asyncPush<string>((emit) =>
|
|
393
|
+
* Effect.acquireRelease(
|
|
394
|
+
* Effect.gen(function*() {
|
|
395
|
+
* yield* Effect.log("subscribing")
|
|
396
|
+
* return setInterval(() => emit.single("tick"), 1000)
|
|
397
|
+
* }),
|
|
398
|
+
* (handle) =>
|
|
399
|
+
* Effect.gen(function*() {
|
|
400
|
+
* yield* Effect.log("unsubscribing")
|
|
401
|
+
* clearInterval(handle)
|
|
402
|
+
* })
|
|
403
|
+
* ), { bufferSize: 16, strategy: "dropping" })
|
|
404
|
+
*
|
|
405
|
+
* @since 3.6.0
|
|
406
|
+
* @category constructors
|
|
407
|
+
*/
|
|
408
|
+
export const asyncPush: <A, E = never, R = never>(
|
|
409
|
+
register: (emit: Emit.EmitOpsPush<E, A>) => Effect.Effect<unknown, never, R | Scope.Scope>,
|
|
410
|
+
options?: { readonly bufferSize: "unbounded" } | {
|
|
411
|
+
readonly bufferSize?: number | undefined
|
|
412
|
+
readonly strategy?: "dropping" | "sliding" | undefined
|
|
413
|
+
} | undefined
|
|
414
|
+
) => Stream<A, E, Exclude<R, Scope.Scope>> = internal.asyncPush
|
|
415
|
+
|
|
376
416
|
/**
|
|
377
417
|
* Creates a stream from an asynchronous callback that can be called multiple
|
|
378
418
|
* times. The registration of the callback itself returns an a scoped
|
|
@@ -2887,6 +2927,38 @@ export const mkString: <E, R>(self: Stream<string, E, R>) => Effect.Effect<strin
|
|
|
2887
2927
|
*/
|
|
2888
2928
|
export const never: Stream<never> = internal.never
|
|
2889
2929
|
|
|
2930
|
+
/**
|
|
2931
|
+
* Adds an effect to be executed at the end of the stream.
|
|
2932
|
+
*
|
|
2933
|
+
* @example
|
|
2934
|
+
* import { Console, Effect, Stream } from "effect"
|
|
2935
|
+
*
|
|
2936
|
+
* const stream = Stream.make(1, 2, 3).pipe(
|
|
2937
|
+
* Stream.map((n) => n * 2),
|
|
2938
|
+
* Stream.tap((n) => Console.log(`after mapping: ${n}`)),
|
|
2939
|
+
* Stream.onEnd(Console.log("Stream ended"))
|
|
2940
|
+
* )
|
|
2941
|
+
*
|
|
2942
|
+
* Effect.runPromise(Stream.runCollect(stream)).then(console.log)
|
|
2943
|
+
* // after mapping: 2
|
|
2944
|
+
* // after mapping: 4
|
|
2945
|
+
* // after mapping: 6
|
|
2946
|
+
* // Stream ended
|
|
2947
|
+
* // { _id: 'Chunk', values: [ 2, 4, 6 ] }
|
|
2948
|
+
*
|
|
2949
|
+
* @since 3.6.0
|
|
2950
|
+
* @category sequencing
|
|
2951
|
+
*/
|
|
2952
|
+
export const onEnd: {
|
|
2953
|
+
<_, E2, R2>(
|
|
2954
|
+
effect: Effect.Effect<_, E2, R2>
|
|
2955
|
+
): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | R>
|
|
2956
|
+
<A, E, R, _, E2, R2>(
|
|
2957
|
+
self: Stream<A, E, R>,
|
|
2958
|
+
effect: Effect.Effect<_, E2, R2>
|
|
2959
|
+
): Stream<A, E | E2, R | R2>
|
|
2960
|
+
} = internal.onEnd
|
|
2961
|
+
|
|
2890
2962
|
/**
|
|
2891
2963
|
* Runs the specified effect if this stream fails, providing the error to the
|
|
2892
2964
|
* effect if it exists.
|
|
@@ -2918,6 +2990,38 @@ export const onDone: {
|
|
|
2918
2990
|
<A, E, R, X, R2>(self: Stream<A, E, R>, cleanup: () => Effect.Effect<X, never, R2>): Stream<A, E, R | R2>
|
|
2919
2991
|
} = internal.onDone
|
|
2920
2992
|
|
|
2993
|
+
/**
|
|
2994
|
+
* Adds an effect to be executed at the start of the stream.
|
|
2995
|
+
*
|
|
2996
|
+
* @example
|
|
2997
|
+
* import { Console, Effect, Stream } from "effect"
|
|
2998
|
+
*
|
|
2999
|
+
* const stream = Stream.make(1, 2, 3).pipe(
|
|
3000
|
+
* Stream.onStart(Console.log("Stream started")),
|
|
3001
|
+
* Stream.map((n) => n * 2),
|
|
3002
|
+
* Stream.tap((n) => Console.log(`after mapping: ${n}`))
|
|
3003
|
+
* )
|
|
3004
|
+
*
|
|
3005
|
+
* // Effect.runPromise(Stream.runCollect(stream)).then(console.log)
|
|
3006
|
+
* // Stream started
|
|
3007
|
+
* // after mapping: 2
|
|
3008
|
+
* // after mapping: 4
|
|
3009
|
+
* // after mapping: 6
|
|
3010
|
+
* // { _id: 'Chunk', values: [ 2, 4, 6 ] }
|
|
3011
|
+
*
|
|
3012
|
+
* @since 3.6.0
|
|
3013
|
+
* @category sequencing
|
|
3014
|
+
*/
|
|
3015
|
+
export const onStart: {
|
|
3016
|
+
<_, E2, R2>(
|
|
3017
|
+
effect: Effect.Effect<_, E2, R2>
|
|
3018
|
+
): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | R>
|
|
3019
|
+
<A, E, R, _, E2, R2>(
|
|
3020
|
+
self: Stream<A, E, R>,
|
|
3021
|
+
effect: Effect.Effect<_, E2, R2>
|
|
3022
|
+
): Stream<A, E | E2, R | R2>
|
|
3023
|
+
} = internal.onStart
|
|
3024
|
+
|
|
2921
3025
|
/**
|
|
2922
3026
|
* Translates any failure into a stream termination, making the stream
|
|
2923
3027
|
* infallible and all failures unchecked.
|
|
@@ -5923,5 +6027,6 @@ export const fromEventListener: <A = unknown>(
|
|
|
5923
6027
|
readonly capture?: boolean
|
|
5924
6028
|
readonly passive?: boolean
|
|
5925
6029
|
readonly once?: boolean
|
|
6030
|
+
readonly bufferSize?: number | "unbounded" | undefined
|
|
5926
6031
|
} | undefined
|
|
5927
6032
|
) => Stream<A> = internal.fromEventListener
|
package/src/StreamEmit.ts
CHANGED
|
@@ -81,3 +81,56 @@ export interface EmitOps<in R, in E, in A, out B> {
|
|
|
81
81
|
*/
|
|
82
82
|
single(value: A): Promise<B>
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @since 3.6.0
|
|
87
|
+
* @category models
|
|
88
|
+
*/
|
|
89
|
+
export interface EmitOpsPush<in E, in A> {
|
|
90
|
+
/**
|
|
91
|
+
* Emits a chunk containing the specified values.
|
|
92
|
+
*/
|
|
93
|
+
chunk(chunk: Chunk.Chunk<A>): boolean
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Emits a chunk containing the specified values.
|
|
97
|
+
*/
|
|
98
|
+
array(chunk: ReadonlyArray<A>): boolean
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Terminates with a cause that dies with the specified defect.
|
|
102
|
+
*/
|
|
103
|
+
die<Err>(defect: Err): void
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Terminates with a cause that dies with a `Throwable` with the specified
|
|
107
|
+
* message.
|
|
108
|
+
*/
|
|
109
|
+
dieMessage(message: string): void
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Either emits the specified value if this `Exit` is a `Success` or else
|
|
113
|
+
* terminates with the specified cause if this `Exit` is a `Failure`.
|
|
114
|
+
*/
|
|
115
|
+
done(exit: Exit.Exit<A, E>): void
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Terminates with an end of stream signal.
|
|
119
|
+
*/
|
|
120
|
+
end(): void
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Terminates with the specified error.
|
|
124
|
+
*/
|
|
125
|
+
fail(error: E): void
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Terminates the stream with the specified cause.
|
|
129
|
+
*/
|
|
130
|
+
halt(cause: Cause.Cause<E>): void
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Emits a chunk containing the specified value.
|
|
134
|
+
*/
|
|
135
|
+
single(value: A): boolean
|
|
136
|
+
}
|
package/src/Struct.ts
CHANGED
|
@@ -179,3 +179,25 @@ export const evolve: {
|
|
|
179
179
|
export const get =
|
|
180
180
|
<K extends PropertyKey>(key: K) => <S extends { [P in K]?: any }>(s: S): MatchRecord<S, S[K] | undefined, S[K]> =>
|
|
181
181
|
s[key]
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Retrieves the object keys that are strings in a typed manner
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* import { Struct } from "effect"
|
|
188
|
+
*
|
|
189
|
+
* const symbol: unique symbol = Symbol()
|
|
190
|
+
*
|
|
191
|
+
* const value = {
|
|
192
|
+
* a: 1,
|
|
193
|
+
* b: 2,
|
|
194
|
+
* [symbol]: 3
|
|
195
|
+
* }
|
|
196
|
+
*
|
|
197
|
+
* const keys: Array<"a" | "b"> = Struct.keys(value)
|
|
198
|
+
*
|
|
199
|
+
* assert.deepStrictEqual(keys, ["a", "b"])
|
|
200
|
+
*
|
|
201
|
+
* @since 3.6.0
|
|
202
|
+
*/
|
|
203
|
+
export const keys = <T extends {}>(o: T): Array<(keyof T) & string> => Object.keys(o) as Array<(keyof T) & string>
|
package/src/index.ts
CHANGED
|
@@ -68,7 +68,7 @@ export const makeFlat = (
|
|
|
68
68
|
path: ReadonlyArray<string>,
|
|
69
69
|
config: Config.Config.Primitive<A>,
|
|
70
70
|
split: boolean
|
|
71
|
-
) => Effect.Effect<
|
|
71
|
+
) => Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
72
72
|
readonly enumerateChildren: (
|
|
73
73
|
path: ReadonlyArray<string>
|
|
74
74
|
) => Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError>
|
|
@@ -114,7 +114,7 @@ export const fromEnv = (
|
|
|
114
114
|
path: ReadonlyArray<string>,
|
|
115
115
|
primitive: Config.Config.Primitive<A>,
|
|
116
116
|
split = true
|
|
117
|
-
): Effect.Effect<
|
|
117
|
+
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
|
|
118
118
|
const pathString = makePathString(path)
|
|
119
119
|
const current = getEnv()
|
|
120
120
|
const valueOpt = pathString in current ? Option.some(current[pathString]!) : Option.none()
|
|
@@ -165,7 +165,7 @@ export const fromMap = (
|
|
|
165
165
|
path: ReadonlyArray<string>,
|
|
166
166
|
primitive: Config.Config.Primitive<A>,
|
|
167
167
|
split = true
|
|
168
|
-
): Effect.Effect<
|
|
168
|
+
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
|
|
169
169
|
const pathString = makePathString(path)
|
|
170
170
|
const valueOpt = mapWithIndexSplit.has(pathString) ?
|
|
171
171
|
Option.some(mapWithIndexSplit.get(pathString)!) :
|
|
@@ -240,20 +240,20 @@ const fromFlatLoop = <A>(
|
|
|
240
240
|
prefix: ReadonlyArray<string>,
|
|
241
241
|
config: Config.Config<A>,
|
|
242
242
|
split: boolean
|
|
243
|
-
): Effect.Effect<
|
|
243
|
+
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
|
|
244
244
|
const op = config as _config.ConfigPrimitive
|
|
245
245
|
switch (op._tag) {
|
|
246
246
|
case OpCodes.OP_CONSTANT: {
|
|
247
|
-
return core.succeed(Arr.of(op.value)) as Effect.Effect<
|
|
247
|
+
return core.succeed(Arr.of(op.value)) as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
248
248
|
}
|
|
249
249
|
case OpCodes.OP_DESCRIBED: {
|
|
250
250
|
return core.suspend(
|
|
251
251
|
() => fromFlatLoop(flat, prefix, op.config, split)
|
|
252
|
-
) as unknown as Effect.Effect<
|
|
252
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
253
253
|
}
|
|
254
254
|
case OpCodes.OP_FAIL: {
|
|
255
255
|
return core.fail(configError.MissingData(prefix, op.message)) as Effect.Effect<
|
|
256
|
-
|
|
256
|
+
Array<A>,
|
|
257
257
|
ConfigError.ConfigError
|
|
258
258
|
>
|
|
259
259
|
}
|
|
@@ -269,11 +269,11 @@ const fromFlatLoop = <A>(
|
|
|
269
269
|
}
|
|
270
270
|
return core.fail(error1)
|
|
271
271
|
})
|
|
272
|
-
) as unknown as Effect.Effect<
|
|
272
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
273
273
|
}
|
|
274
274
|
case OpCodes.OP_LAZY: {
|
|
275
275
|
return core.suspend(() => fromFlatLoop(flat, prefix, op.config(), split)) as Effect.Effect<
|
|
276
|
-
|
|
276
|
+
Array<A>,
|
|
277
277
|
ConfigError.ConfigError
|
|
278
278
|
>
|
|
279
279
|
}
|
|
@@ -290,7 +290,7 @@ const fromFlatLoop = <A>(
|
|
|
290
290
|
)
|
|
291
291
|
)
|
|
292
292
|
)
|
|
293
|
-
) as unknown as Effect.Effect<
|
|
293
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
294
294
|
}
|
|
295
295
|
case OpCodes.OP_NESTED: {
|
|
296
296
|
return core.suspend(() =>
|
|
@@ -300,7 +300,7 @@ const fromFlatLoop = <A>(
|
|
|
300
300
|
op.config,
|
|
301
301
|
split
|
|
302
302
|
)
|
|
303
|
-
) as unknown as Effect.Effect<
|
|
303
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
304
304
|
}
|
|
305
305
|
case OpCodes.OP_PRIMITIVE: {
|
|
306
306
|
return pipe(
|
|
@@ -317,7 +317,7 @@ const fromFlatLoop = <A>(
|
|
|
317
317
|
})
|
|
318
318
|
)
|
|
319
319
|
)
|
|
320
|
-
) as unknown as Effect.Effect<
|
|
320
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
321
321
|
}
|
|
322
322
|
case OpCodes.OP_SEQUENCE: {
|
|
323
323
|
return pipe(
|
|
@@ -330,7 +330,7 @@ const fromFlatLoop = <A>(
|
|
|
330
330
|
if (indices.length === 0) {
|
|
331
331
|
return core.suspend(() =>
|
|
332
332
|
core.map(fromFlatLoop(flat, patchedPrefix, op.config, true), Arr.of)
|
|
333
|
-
) as unknown as Effect.Effect<
|
|
333
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
334
334
|
}
|
|
335
335
|
return pipe(
|
|
336
336
|
core.forEachSequential(
|
|
@@ -344,7 +344,7 @@ const fromFlatLoop = <A>(
|
|
|
344
344
|
}
|
|
345
345
|
return Arr.of(flattened)
|
|
346
346
|
})
|
|
347
|
-
) as unknown as Effect.Effect<
|
|
347
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
348
348
|
})
|
|
349
349
|
)
|
|
350
350
|
)
|
|
@@ -382,7 +382,7 @@ const fromFlatLoop = <A>(
|
|
|
382
382
|
)
|
|
383
383
|
)
|
|
384
384
|
)
|
|
385
|
-
) as unknown as Effect.Effect<
|
|
385
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
386
386
|
}
|
|
387
387
|
case OpCodes.OP_ZIP_WITH: {
|
|
388
388
|
return core.suspend(() =>
|
|
@@ -430,7 +430,7 @@ const fromFlatLoop = <A>(
|
|
|
430
430
|
)
|
|
431
431
|
)
|
|
432
432
|
)
|
|
433
|
-
) as unknown as Effect.Effect<
|
|
433
|
+
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
}
|
|
@@ -592,7 +592,7 @@ export const within = dual<
|
|
|
592
592
|
return orElse(nest, () => self)
|
|
593
593
|
})
|
|
594
594
|
|
|
595
|
-
const splitPathString = (text: string, delim: string):
|
|
595
|
+
const splitPathString = (text: string, delim: string): Array<string> => {
|
|
596
596
|
const split = text.split(new RegExp(`\\s*${regexp.escape(delim)}\\s*`))
|
|
597
597
|
return split
|
|
598
598
|
}
|
|
@@ -603,7 +603,7 @@ const parsePrimitive = <A>(
|
|
|
603
603
|
primitive: Config.Config.Primitive<A>,
|
|
604
604
|
delimiter: string,
|
|
605
605
|
split: boolean
|
|
606
|
-
): Effect.Effect<
|
|
606
|
+
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
|
|
607
607
|
if (!split) {
|
|
608
608
|
return pipe(
|
|
609
609
|
primitive.parse(text),
|
|
@@ -620,11 +620,11 @@ const parsePrimitive = <A>(
|
|
|
620
620
|
)
|
|
621
621
|
}
|
|
622
622
|
|
|
623
|
-
const transpose = <A>(array: ReadonlyArray<ReadonlyArray<A>>):
|
|
623
|
+
const transpose = <A>(array: ReadonlyArray<ReadonlyArray<A>>): Array<Array<A>> => {
|
|
624
624
|
return Object.keys(array[0]).map((column) => array.map((row) => row[column as any]))
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
-
const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<
|
|
627
|
+
const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<Array<number>> =>
|
|
628
628
|
pipe(
|
|
629
629
|
core.forEachSequential(quotedIndices, parseQuotedIndex),
|
|
630
630
|
core.mapBoth({
|