effect 3.8.5 → 3.9.1
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/dist/cjs/Array.js +24 -3
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Effect.js +122 -35
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/HashMap.js.map +1 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/ManagedRuntime.js +16 -1
- package/dist/cjs/ManagedRuntime.js.map +1 -1
- package/dist/cjs/Pool.js.map +1 -1
- package/dist/cjs/Predicate.js +18 -2
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/RegExp.js +20 -1
- package/dist/cjs/RegExp.js.map +1 -1
- package/dist/cjs/Resource.js.map +1 -1
- package/dist/cjs/ScopedRef.js.map +1 -1
- package/dist/cjs/Tuple.js +21 -2
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/Unify.js.map +1 -1
- package/dist/cjs/internal/context.js +0 -1
- package/dist/cjs/internal/context.js.map +1 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js +5 -1
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/layer.js +33 -19
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/managedRuntime/circular.js +10 -0
- package/dist/cjs/internal/managedRuntime/circular.js.map +1 -0
- package/dist/cjs/internal/managedRuntime.js +23 -9
- package/dist/cjs/internal/managedRuntime.js.map +1 -1
- package/dist/cjs/internal/pool.js +6 -1
- package/dist/cjs/internal/pool.js.map +1 -1
- package/dist/cjs/internal/resource.js +15 -5
- package/dist/cjs/internal/resource.js.map +1 -1
- package/dist/cjs/internal/scopedRef.js +11 -8
- package/dist/cjs/internal/scopedRef.js.map +1 -1
- package/dist/cjs/internal/stm/core.js +1 -2
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +51 -2
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +2 -3
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Deferred.d.ts +1 -1
- package/dist/dts/Deferred.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +233 -10
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +15 -0
- package/dist/dts/HashMap.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +46 -5
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/ManagedRuntime.d.ts +41 -2
- package/dist/dts/ManagedRuntime.d.ts.map +1 -1
- package/dist/dts/Pool.d.ts +21 -1
- package/dist/dts/Pool.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +15 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Queue.d.ts +2 -2
- package/dist/dts/Queue.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +12 -2
- package/dist/dts/RegExp.d.ts.map +1 -1
- package/dist/dts/Resource.d.ts +21 -1
- package/dist/dts/Resource.d.ts.map +1 -1
- package/dist/dts/ScopedRef.d.ts +21 -1
- package/dist/dts/ScopedRef.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +59 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +39 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/Unify.d.ts +8 -13
- package/dist/dts/Unify.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/dts/internal/managedRuntime/circular.d.ts +2 -0
- package/dist/dts/internal/managedRuntime/circular.d.ts.map +1 -0
- package/dist/esm/Array.js +21 -0
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Effect.js +116 -30
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/HashMap.js.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/ManagedRuntime.js +15 -0
- package/dist/esm/ManagedRuntime.js.map +1 -1
- package/dist/esm/Pool.js.map +1 -1
- package/dist/esm/Predicate.js +15 -0
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/RegExp.js +16 -0
- package/dist/esm/RegExp.js.map +1 -1
- package/dist/esm/Resource.js.map +1 -1
- package/dist/esm/ScopedRef.js.map +1 -1
- package/dist/esm/Tuple.js +19 -0
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/Unify.js.map +1 -1
- package/dist/esm/internal/context.js +0 -1
- package/dist/esm/internal/context.js.map +1 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/effect/circular.js +5 -1
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/layer.js +32 -18
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/managedRuntime/circular.js +4 -0
- package/dist/esm/internal/managedRuntime/circular.js.map +1 -0
- package/dist/esm/internal/managedRuntime.js +21 -8
- package/dist/esm/internal/managedRuntime.js.map +1 -1
- package/dist/esm/internal/pool.js +6 -1
- package/dist/esm/internal/pool.js.map +1 -1
- package/dist/esm/internal/resource.js +15 -5
- package/dist/esm/internal/resource.js.map +1 -1
- package/dist/esm/internal/scopedRef.js +11 -8
- package/dist/esm/internal/scopedRef.js.map +1 -1
- package/dist/esm/internal/stm/core.js +1 -2
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +68 -4
- package/src/Context.ts +2 -3
- package/src/Deferred.ts +1 -1
- package/src/Effect.ts +435 -56
- package/src/HashMap.ts +16 -0
- package/src/Layer.ts +49 -8
- package/src/ManagedRuntime.ts +46 -2
- package/src/Pool.ts +26 -1
- package/src/Predicate.ts +16 -0
- package/src/Queue.ts +2 -2
- package/src/RegExp.ts +17 -0
- package/src/Resource.ts +22 -1
- package/src/ScopedRef.ts +22 -1
- package/src/Tuple.ts +66 -0
- package/src/Types.ts +41 -0
- package/src/Unify.ts +9 -14
- package/src/internal/context.ts +0 -1
- package/src/internal/core-effect.ts +7 -7
- package/src/internal/effect/circular.ts +8 -2
- package/src/internal/layer.ts +105 -38
- package/src/internal/managedRuntime/circular.ts +6 -0
- package/src/internal/managedRuntime.ts +36 -22
- package/src/internal/pool.ts +7 -1
- package/src/internal/resource.ts +16 -5
- package/src/internal/scopedRef.ts +12 -8
- package/src/internal/stm/core.ts +2 -3
- package/src/internal/version.ts +1 -1
package/src/Layer.ts
CHANGED
|
@@ -76,23 +76,34 @@ export declare namespace Layer {
|
|
|
76
76
|
readonly _RIn: Types.Covariant<RIn>
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* @since 3.9.0
|
|
81
|
+
* @category type-level
|
|
82
|
+
*/
|
|
83
|
+
export interface Any {
|
|
84
|
+
readonly [LayerTypeId]: {
|
|
85
|
+
readonly _ROut: any
|
|
86
|
+
readonly _E: any
|
|
87
|
+
readonly _RIn: any
|
|
88
|
+
}
|
|
89
|
+
}
|
|
79
90
|
/**
|
|
80
91
|
* @since 2.0.0
|
|
81
92
|
* @category type-level
|
|
82
93
|
*/
|
|
83
|
-
export type Context<T extends
|
|
94
|
+
export type Context<T extends Any> = [T] extends [Layer<infer _ROut, infer _E, infer _RIn>] ? _RIn
|
|
84
95
|
: never
|
|
85
96
|
/**
|
|
86
97
|
* @since 2.0.0
|
|
87
98
|
* @category type-level
|
|
88
99
|
*/
|
|
89
|
-
export type Error<T extends
|
|
100
|
+
export type Error<T extends Any> = [T] extends [Layer<infer _ROut, infer _E, infer _RIn>] ? _E
|
|
90
101
|
: never
|
|
91
102
|
/**
|
|
92
103
|
* @since 2.0.0
|
|
93
104
|
* @category type-level
|
|
94
105
|
*/
|
|
95
|
-
export type Success<T extends
|
|
106
|
+
export type Success<T extends Any> = [T] extends [Layer<infer _ROut, infer _E, infer _RIn>] ? _ROut
|
|
96
107
|
: never
|
|
97
108
|
}
|
|
98
109
|
|
|
@@ -1157,8 +1168,24 @@ export const provide: {
|
|
|
1157
1168
|
* @category utils
|
|
1158
1169
|
*/
|
|
1159
1170
|
<RIn, E, ROut>(
|
|
1160
|
-
|
|
1161
|
-
): <RIn2, E2, ROut2>(
|
|
1171
|
+
that: Layer<ROut, E, RIn>
|
|
1172
|
+
): <RIn2, E2, ROut2>(self: Layer<ROut2, E2, RIn2>) => Layer<ROut2, E | E2, RIn | Exclude<RIn2, ROut>>
|
|
1173
|
+
/**
|
|
1174
|
+
* Feeds the output services of this builder into the input of the specified
|
|
1175
|
+
* builder, resulting in a new builder with the inputs of this builder as
|
|
1176
|
+
* well as any leftover inputs, and the outputs of the specified builder.
|
|
1177
|
+
*
|
|
1178
|
+
* @since 2.0.0
|
|
1179
|
+
* @category utils
|
|
1180
|
+
*/
|
|
1181
|
+
<const Layers extends [Layer.Any, ...Array<Layer.Any>]>(that: Layers): <A, E, R>(
|
|
1182
|
+
self: Layer<A, E, R>
|
|
1183
|
+
) => Layer<
|
|
1184
|
+
A,
|
|
1185
|
+
E | { [k in keyof Layers]: Layer.Error<Layers[k]> }[number],
|
|
1186
|
+
| { [k in keyof Layers]: Layer.Context<Layers[k]> }[number]
|
|
1187
|
+
| Exclude<R, { [k in keyof Layers]: Layer.Success<Layers[k]> }[number]>
|
|
1188
|
+
>
|
|
1162
1189
|
/**
|
|
1163
1190
|
* Feeds the output services of this builder into the input of the specified
|
|
1164
1191
|
* builder, resulting in a new builder with the inputs of this builder as
|
|
@@ -1168,9 +1195,23 @@ export const provide: {
|
|
|
1168
1195
|
* @category utils
|
|
1169
1196
|
*/
|
|
1170
1197
|
<RIn2, E2, ROut2, RIn, E, ROut>(
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
): Layer<ROut2,
|
|
1198
|
+
self: Layer<ROut2, E2, RIn2>,
|
|
1199
|
+
that: Layer<ROut, E, RIn>
|
|
1200
|
+
): Layer<ROut2, E | E2, RIn | Exclude<RIn2, ROut>>
|
|
1201
|
+
/**
|
|
1202
|
+
* Feeds the output services of this builder into the input of the specified
|
|
1203
|
+
* builder, resulting in a new builder with the inputs of this builder as
|
|
1204
|
+
* well as any leftover inputs, and the outputs of the specified builder.
|
|
1205
|
+
*
|
|
1206
|
+
* @since 2.0.0
|
|
1207
|
+
* @category utils
|
|
1208
|
+
*/
|
|
1209
|
+
<A, E, R, const Layers extends [Layer.Any, ...Array<Layer.Any>]>(self: Layer<A, E, R>, that: Layers): Layer<
|
|
1210
|
+
A,
|
|
1211
|
+
E | { [k in keyof Layers]: Layer.Error<Layers[k]> }[number],
|
|
1212
|
+
| { [k in keyof Layers]: Layer.Context<Layers[k]> }[number]
|
|
1213
|
+
| Exclude<R, { [k in keyof Layers]: Layer.Success<Layers[k]> }[number]>
|
|
1214
|
+
>
|
|
1174
1215
|
} = internal.provide
|
|
1175
1216
|
|
|
1176
1217
|
/**
|
package/src/ManagedRuntime.ts
CHANGED
|
@@ -5,9 +5,32 @@ import type * as Effect from "./Effect.js"
|
|
|
5
5
|
import type * as Exit from "./Exit.js"
|
|
6
6
|
import type * as Fiber from "./Fiber.js"
|
|
7
7
|
import * as internal from "./internal/managedRuntime.js"
|
|
8
|
+
import * as circular from "./internal/managedRuntime/circular.js"
|
|
8
9
|
import type * as Layer from "./Layer.js"
|
|
9
|
-
import type { Pipeable } from "./Pipeable.js"
|
|
10
10
|
import type * as Runtime from "./Runtime.js"
|
|
11
|
+
import type * as Unify from "./Unify.js"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @since 3.9.0
|
|
15
|
+
* @category symbol
|
|
16
|
+
*/
|
|
17
|
+
export const TypeId: unique symbol = circular.TypeId as TypeId
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @since 3.9.0
|
|
21
|
+
* @category symbol
|
|
22
|
+
*/
|
|
23
|
+
export type TypeId = typeof TypeId
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the provided argument is a `ManagedRuntime`.
|
|
27
|
+
*
|
|
28
|
+
* @param input - The value to be checked if it is a `ManagedRuntime`.
|
|
29
|
+
|
|
30
|
+
* @since 3.9.0
|
|
31
|
+
* @category guards
|
|
32
|
+
*/
|
|
33
|
+
export const isManagedRuntime: (input: unknown) => input is ManagedRuntime<unknown, unknown> = internal.isManagedRuntime
|
|
11
34
|
|
|
12
35
|
/**
|
|
13
36
|
* @since 3.4.0
|
|
@@ -29,7 +52,8 @@ export declare namespace ManagedRuntime {
|
|
|
29
52
|
* @since 2.0.0
|
|
30
53
|
* @category models
|
|
31
54
|
*/
|
|
32
|
-
export interface ManagedRuntime<in R, out ER> extends
|
|
55
|
+
export interface ManagedRuntime<in R, out ER> extends Effect.Effect<Runtime.Runtime<R>, ER> {
|
|
56
|
+
readonly [TypeId]: TypeId
|
|
33
57
|
readonly memoMap: Layer.MemoMap
|
|
34
58
|
readonly runtimeEffect: Effect.Effect<Runtime.Runtime<R>, ER>
|
|
35
59
|
readonly runtime: () => Promise<Runtime.Runtime<R>>
|
|
@@ -103,6 +127,26 @@ export interface ManagedRuntime<in R, out ER> extends Pipeable {
|
|
|
103
127
|
* Dispose of the resources associated with the runtime.
|
|
104
128
|
*/
|
|
105
129
|
readonly disposeEffect: Effect.Effect<void, never, never>
|
|
130
|
+
|
|
131
|
+
readonly [Unify.typeSymbol]?: unknown
|
|
132
|
+
readonly [Unify.unifySymbol]?: ManagedRuntimeUnify<this>
|
|
133
|
+
readonly [Unify.ignoreSymbol]?: ManagedRuntimeUnifyIgnore
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @category models
|
|
138
|
+
* @since 3.9.0
|
|
139
|
+
*/
|
|
140
|
+
export interface ManagedRuntimeUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
|
141
|
+
ManagedRuntime?: () => Extract<A[Unify.typeSymbol], ManagedRuntime<any, any>>
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @category models
|
|
146
|
+
* @since 3.9.0
|
|
147
|
+
*/
|
|
148
|
+
export interface ManagedRuntimeUnifyIgnore extends Effect.EffectUnifyIgnore {
|
|
149
|
+
Effect?: true
|
|
106
150
|
}
|
|
107
151
|
|
|
108
152
|
/**
|
package/src/Pool.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as internal from "./internal/pool.js"
|
|
|
7
7
|
import type { Pipeable } from "./Pipeable.js"
|
|
8
8
|
import type * as Scope from "./Scope.js"
|
|
9
9
|
import type * as Types from "./Types.js"
|
|
10
|
+
import type * as Unify from "./Unify.js"
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @since 2.0.0
|
|
@@ -28,7 +29,7 @@ export type PoolTypeId = typeof PoolTypeId
|
|
|
28
29
|
* @since 2.0.0
|
|
29
30
|
* @category models
|
|
30
31
|
*/
|
|
31
|
-
export interface Pool<in out A, out E = never> extends Pool.Variance<A, E>, Pipeable {
|
|
32
|
+
export interface Pool<in out A, out E = never> extends Pool.Variance<A, E>, Effect.Effect<A, E, Scope.Scope>, Pipeable {
|
|
32
33
|
/**
|
|
33
34
|
* Retrieves an item from the pool in a scoped effect. Note that if
|
|
34
35
|
* acquisition fails, then the returned effect will fail for that same reason.
|
|
@@ -42,6 +43,30 @@ export interface Pool<in out A, out E = never> extends Pool.Variance<A, E>, Pipe
|
|
|
42
43
|
* than eagerly.
|
|
43
44
|
*/
|
|
44
45
|
invalidate(item: A): Effect.Effect<void>
|
|
46
|
+
|
|
47
|
+
readonly [Unify.typeSymbol]?: unknown
|
|
48
|
+
readonly [Unify.unifySymbol]?: PoolUnify<this>
|
|
49
|
+
readonly [Unify.ignoreSymbol]?: PoolUnifyIgnore
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @category models
|
|
54
|
+
* @since 3.9.0
|
|
55
|
+
*/
|
|
56
|
+
export interface PoolUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
|
57
|
+
Pool?: () => Extract<A[Unify.typeSymbol], Pool<any, any>> extends Pool<infer A0, infer _E0> | infer _ ?
|
|
58
|
+
A0 extends any ? Extract<A[Unify.typeSymbol], Pool<A0, any>> extends Pool<A0, infer E1> ? Pool<A0, E1>
|
|
59
|
+
: never
|
|
60
|
+
: never :
|
|
61
|
+
never
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @category models
|
|
66
|
+
* @since 3.9.0
|
|
67
|
+
*/
|
|
68
|
+
export interface PoolUnifyIgnore extends Effect.EffectUnifyIgnore {
|
|
69
|
+
Effect?: true
|
|
45
70
|
}
|
|
46
71
|
|
|
47
72
|
/**
|
package/src/Predicate.ts
CHANGED
|
@@ -855,6 +855,22 @@ export const isPromiseLike = (
|
|
|
855
855
|
input: unknown
|
|
856
856
|
): input is PromiseLike<unknown> => hasProperty(input, "then") && isFunction(input.then)
|
|
857
857
|
|
|
858
|
+
/**
|
|
859
|
+
* Tests if a value is a `RegExp`.
|
|
860
|
+
*
|
|
861
|
+
* @param input - The value to test.
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* import { Predicate } from "effect"
|
|
865
|
+
*
|
|
866
|
+
* assert.deepStrictEqual(Predicate.isRegExp(/a/), true)
|
|
867
|
+
* assert.deepStrictEqual(Predicate.isRegExp("a"), false)
|
|
868
|
+
*
|
|
869
|
+
* @category guards
|
|
870
|
+
* @since 3.9.0
|
|
871
|
+
*/
|
|
872
|
+
export const isRegExp = (input: unknown): input is RegExp => input instanceof RegExp
|
|
873
|
+
|
|
858
874
|
/**
|
|
859
875
|
* @since 2.0.0
|
|
860
876
|
*/
|
package/src/Queue.ts
CHANGED
|
@@ -64,7 +64,7 @@ export type BackingQueueTypeId = typeof BackingQueueTypeId
|
|
|
64
64
|
* @since 2.0.0
|
|
65
65
|
* @category models
|
|
66
66
|
*/
|
|
67
|
-
export interface Queue<in out A> extends Enqueue<A>, Dequeue<A
|
|
67
|
+
export interface Queue<in out A> extends Enqueue<A>, Dequeue<A> {
|
|
68
68
|
/** @internal */
|
|
69
69
|
readonly queue: BackingQueue<A>
|
|
70
70
|
/** @internal */
|
|
@@ -134,7 +134,7 @@ export interface Enqueue<in A> extends Queue.EnqueueVariance<A>, BaseQueue, Pipe
|
|
|
134
134
|
* @since 2.0.0
|
|
135
135
|
* @category models
|
|
136
136
|
*/
|
|
137
|
-
export interface Dequeue<out A> extends Effect.Effect<A>, Queue.DequeueVariance<A>, BaseQueue
|
|
137
|
+
export interface Dequeue<out A> extends Effect.Effect<A>, Queue.DequeueVariance<A>, BaseQueue {
|
|
138
138
|
/**
|
|
139
139
|
* Takes the oldest value in the queue. If the queue is empty, this will return
|
|
140
140
|
* a computation that resumes when an item has been added to the queue.
|
package/src/RegExp.ts
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @since 2.0.0
|
|
5
5
|
*/
|
|
6
|
+
import * as predicate from "./Predicate.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Tests if a value is a `RegExp`.
|
|
10
|
+
*
|
|
11
|
+
* @param input - The value to test.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { RegExp } from "effect"
|
|
15
|
+
*
|
|
16
|
+
* assert.deepStrictEqual(RegExp.isRegExp(/a/), true)
|
|
17
|
+
* assert.deepStrictEqual(RegExp.isRegExp("a"), false)
|
|
18
|
+
*
|
|
19
|
+
* @category guards
|
|
20
|
+
* @since 3.9.0
|
|
21
|
+
*/
|
|
22
|
+
export const isRegExp: (input: unknown) => input is RegExp = predicate.isRegExp
|
|
6
23
|
|
|
7
24
|
/**
|
|
8
25
|
* Escapes special characters in a regular expression pattern.
|
package/src/Resource.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type * as Schedule from "./Schedule.js"
|
|
|
8
8
|
import type * as Scope from "./Scope.js"
|
|
9
9
|
import type * as ScopedRef from "./ScopedRef.js"
|
|
10
10
|
import type * as Types from "./Types.js"
|
|
11
|
+
import type * as Unify from "./Unify.js"
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @since 2.0.0
|
|
@@ -28,11 +29,31 @@ export type ResourceTypeId = typeof ResourceTypeId
|
|
|
28
29
|
* @since 2.0.0
|
|
29
30
|
* @category models
|
|
30
31
|
*/
|
|
31
|
-
export interface Resource<in out A, in out E = never> extends Resource.Variance<A, E> {
|
|
32
|
+
export interface Resource<in out A, in out E = never> extends Effect.Effect<A, E>, Resource.Variance<A, E> {
|
|
32
33
|
/** @internal */
|
|
33
34
|
readonly scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>
|
|
34
35
|
/** @internal */
|
|
35
36
|
readonly acquire: Effect.Effect<A, E, Scope.Scope>
|
|
37
|
+
|
|
38
|
+
readonly [Unify.typeSymbol]?: unknown
|
|
39
|
+
readonly [Unify.unifySymbol]?: ResourceUnify<this>
|
|
40
|
+
readonly [Unify.ignoreSymbol]?: ResourceUnifyIgnore
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @category models
|
|
45
|
+
* @since 3.9.0
|
|
46
|
+
*/
|
|
47
|
+
export interface ResourceUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
|
48
|
+
Resource?: () => Extract<A[Unify.typeSymbol], Resource<any, any>>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @category models
|
|
53
|
+
* @since 3.9.0
|
|
54
|
+
*/
|
|
55
|
+
export interface ResourceUnifyIgnore extends Effect.EffectUnifyIgnore {
|
|
56
|
+
Effect?: true
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
/**
|
package/src/ScopedRef.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { Pipeable } from "./Pipeable.js"
|
|
|
8
8
|
import type * as Scope from "./Scope.js"
|
|
9
9
|
import type * as Synchronized from "./SynchronizedRef.js"
|
|
10
10
|
import type * as Types from "./Types.js"
|
|
11
|
+
import type * as Unify from "./Unify.js"
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @since 2.0.0
|
|
@@ -31,9 +32,29 @@ export type ScopedRefTypeId = typeof ScopedRefTypeId
|
|
|
31
32
|
* @since 2.0.0
|
|
32
33
|
* @category models
|
|
33
34
|
*/
|
|
34
|
-
export interface ScopedRef<in out A> extends ScopedRef.Variance<A>, Pipeable {
|
|
35
|
+
export interface ScopedRef<in out A> extends Effect.Effect<A>, ScopedRef.Variance<A>, Pipeable {
|
|
35
36
|
/** @internal */
|
|
36
37
|
readonly ref: Synchronized.SynchronizedRef<readonly [Scope.Scope.Closeable, A]>
|
|
38
|
+
|
|
39
|
+
readonly [Unify.typeSymbol]?: unknown
|
|
40
|
+
readonly [Unify.unifySymbol]?: ScopedRefUnify<this>
|
|
41
|
+
readonly [Unify.ignoreSymbol]?: ScopedRefUnifyIgnore
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @category models
|
|
46
|
+
* @since 3.9.0
|
|
47
|
+
*/
|
|
48
|
+
export interface ScopedRefUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
|
49
|
+
ScopedRef?: () => Extract<A[Unify.typeSymbol], ScopedRef<any>>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @category models
|
|
54
|
+
* @since 3.9.0
|
|
55
|
+
*/
|
|
56
|
+
export interface ScopedRefUnifyIgnore extends Effect.EffectUnifyIgnore {
|
|
57
|
+
Effect?: true
|
|
37
58
|
}
|
|
38
59
|
|
|
39
60
|
/**
|
package/src/Tuple.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as Equivalence from "./Equivalence.js"
|
|
|
7
7
|
import { dual } from "./Function.js"
|
|
8
8
|
import type { TypeLambda } from "./HKT.js"
|
|
9
9
|
import * as order from "./Order.js"
|
|
10
|
+
import type { TupleOf } from "./Types.js"
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @category type lambdas
|
|
@@ -61,6 +62,71 @@ export const getFirst = <L, R>(self: readonly [L, R]): L => self[0]
|
|
|
61
62
|
*/
|
|
62
63
|
export const getSecond = <L, R>(self: readonly [L, R]): R => self[1]
|
|
63
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Transforms each element of tuple using the given function, treating tuple homomorphically
|
|
67
|
+
*
|
|
68
|
+
* @param self - A tuple.
|
|
69
|
+
* @param f - The function to transform elements of the tuple.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* import { pipe, Tuple } from "effect"
|
|
73
|
+
*
|
|
74
|
+
* const result = pipe(
|
|
75
|
+
* ["a", 1, false] as const,
|
|
76
|
+
* Tuple.map((el) => el.toString().toUpperCase())
|
|
77
|
+
* )
|
|
78
|
+
* assert.deepStrictEqual(result, ['A', '1', 'FALSE'])
|
|
79
|
+
*
|
|
80
|
+
* @category mapping
|
|
81
|
+
* @since 3.9.0
|
|
82
|
+
*/
|
|
83
|
+
export const map: {
|
|
84
|
+
/**
|
|
85
|
+
* Transforms each element of tuple using the given function, treating tuple homomorphically
|
|
86
|
+
*
|
|
87
|
+
* @param self - A tuple.
|
|
88
|
+
* @param f - The function to transform elements of the tuple.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* import { pipe, Tuple } from "effect"
|
|
92
|
+
*
|
|
93
|
+
* const result = pipe(
|
|
94
|
+
* ["a", 1, false] as const,
|
|
95
|
+
* Tuple.map((el) => el.toString().toUpperCase())
|
|
96
|
+
* )
|
|
97
|
+
* assert.deepStrictEqual(result, ['A', '1', 'FALSE'])
|
|
98
|
+
*
|
|
99
|
+
* @category mapping
|
|
100
|
+
* @since 3.9.0
|
|
101
|
+
*/
|
|
102
|
+
<T extends ReadonlyArray<any> | [], B>(fn: (element: T[number]) => B): (self: T) => TupleOf<T["length"], B>
|
|
103
|
+
/**
|
|
104
|
+
* Transforms each element of tuple using the given function, treating tuple homomorphically
|
|
105
|
+
*
|
|
106
|
+
* @param self - A tuple.
|
|
107
|
+
* @param f - The function to transform elements of the tuple.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* import { pipe, Tuple } from "effect"
|
|
111
|
+
*
|
|
112
|
+
* const result = pipe(
|
|
113
|
+
* ["a", 1, false] as const,
|
|
114
|
+
* Tuple.map((el) => el.toString().toUpperCase())
|
|
115
|
+
* )
|
|
116
|
+
* assert.deepStrictEqual(result, ['A', '1', 'FALSE'])
|
|
117
|
+
*
|
|
118
|
+
* @category mapping
|
|
119
|
+
* @since 3.9.0
|
|
120
|
+
*/
|
|
121
|
+
<B, T extends ReadonlyArray<any> | []>(self: T, fn: (element: T[number]) => B): TupleOf<T["length"], B>
|
|
122
|
+
} = dual(
|
|
123
|
+
2,
|
|
124
|
+
<N extends number, A, B>(
|
|
125
|
+
self: TupleOf<N, A>,
|
|
126
|
+
fn: (element: A) => B
|
|
127
|
+
): TupleOf<N, B> => self.map((element) => fn(element)) as TupleOf<N, B>
|
|
128
|
+
)
|
|
129
|
+
|
|
64
130
|
/**
|
|
65
131
|
* Transforms both elements of a tuple using the given functions.
|
|
66
132
|
*
|
package/src/Types.ts
CHANGED
|
@@ -254,6 +254,18 @@ export type NoInfer<A> = [A][A extends any ? 0 : never]
|
|
|
254
254
|
*/
|
|
255
255
|
export type Invariant<A> = (_: A) => A
|
|
256
256
|
|
|
257
|
+
/**
|
|
258
|
+
* @since 3.9.0
|
|
259
|
+
* @category models
|
|
260
|
+
*/
|
|
261
|
+
export declare namespace Invariant {
|
|
262
|
+
/**
|
|
263
|
+
* @since 3.9.0
|
|
264
|
+
* @category models
|
|
265
|
+
*/
|
|
266
|
+
export type Type<A> = A extends Invariant<infer U> ? U : never
|
|
267
|
+
}
|
|
268
|
+
|
|
257
269
|
/**
|
|
258
270
|
* Covariant helper.
|
|
259
271
|
*
|
|
@@ -262,6 +274,18 @@ export type Invariant<A> = (_: A) => A
|
|
|
262
274
|
*/
|
|
263
275
|
export type Covariant<A> = (_: never) => A
|
|
264
276
|
|
|
277
|
+
/**
|
|
278
|
+
* @since 3.9.0
|
|
279
|
+
* @category models
|
|
280
|
+
*/
|
|
281
|
+
export declare namespace Covariant {
|
|
282
|
+
/**
|
|
283
|
+
* @since 3.9.0
|
|
284
|
+
* @category models
|
|
285
|
+
*/
|
|
286
|
+
export type Type<A> = A extends Covariant<infer U> ? U : never
|
|
287
|
+
}
|
|
288
|
+
|
|
265
289
|
/**
|
|
266
290
|
* Contravariant helper.
|
|
267
291
|
*
|
|
@@ -270,6 +294,18 @@ export type Covariant<A> = (_: never) => A
|
|
|
270
294
|
*/
|
|
271
295
|
export type Contravariant<A> = (_: A) => void
|
|
272
296
|
|
|
297
|
+
/**
|
|
298
|
+
* @since 3.9.0
|
|
299
|
+
* @category models
|
|
300
|
+
*/
|
|
301
|
+
export declare namespace Contravariant {
|
|
302
|
+
/**
|
|
303
|
+
* @since 3.9.0
|
|
304
|
+
* @category models
|
|
305
|
+
*/
|
|
306
|
+
export type Type<A> = A extends Contravariant<infer U> ? U : never
|
|
307
|
+
}
|
|
308
|
+
|
|
273
309
|
/**
|
|
274
310
|
* @since 2.0.0
|
|
275
311
|
*/
|
|
@@ -279,3 +315,8 @@ export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse
|
|
|
279
315
|
* @since 2.0.0
|
|
280
316
|
*/
|
|
281
317
|
export type NotFunction<T> = T extends Function ? never : T
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @since 3.9.0
|
|
321
|
+
*/
|
|
322
|
+
export type NoExcessProperties<T, U> = T & { readonly [K in Exclude<keyof U, keyof T>]: never }
|
package/src/Unify.ts
CHANGED
|
@@ -34,26 +34,21 @@ export declare const ignoreSymbol: unique symbol
|
|
|
34
34
|
*/
|
|
35
35
|
export type ignoreSymbol = typeof ignoreSymbol
|
|
36
36
|
|
|
37
|
-
type MaybeReturn<F> = F extends () =>
|
|
37
|
+
type MaybeReturn<F> = F extends () => infer R ? R : NonNullable<F>
|
|
38
38
|
|
|
39
|
-
type Values<X extends [any, any]> = X extends
|
|
40
|
-
?
|
|
39
|
+
type Values<X extends [any, any]> = X extends [infer A, infer Ignore]
|
|
40
|
+
? Exclude<keyof A, Ignore> extends infer k ? k extends keyof A ? MaybeReturn<A[k]> : never : never
|
|
41
41
|
: never
|
|
42
42
|
|
|
43
|
-
type Ignore<X> = X extends {
|
|
44
|
-
[ignoreSymbol]?: any
|
|
45
|
-
} ? keyof NonNullable<X[ignoreSymbol]>
|
|
43
|
+
type Ignore<X> = X extends { [ignoreSymbol]?: infer Obj } ? keyof NonNullable<Obj>
|
|
46
44
|
: never
|
|
47
45
|
|
|
48
46
|
type ExtractTypes<
|
|
49
|
-
X
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
NonNullable<X[unifySymbol]>,
|
|
55
|
-
Ignore<X>
|
|
56
|
-
]
|
|
47
|
+
X
|
|
48
|
+
> = X extends {
|
|
49
|
+
[typeSymbol]?: infer _Type
|
|
50
|
+
[unifySymbol]?: infer _Unify
|
|
51
|
+
} ? [NonNullable<_Unify>, Ignore<X>]
|
|
57
52
|
: never
|
|
58
53
|
|
|
59
54
|
type FilterIn<A> = A extends any ? typeSymbol extends keyof A ? A : never : never
|
package/src/internal/context.ts
CHANGED
|
@@ -1055,17 +1055,17 @@ const loopDiscard = <S, X, E, R>(
|
|
|
1055
1055
|
|
|
1056
1056
|
/* @internal */
|
|
1057
1057
|
export const mapAccum: {
|
|
1058
|
-
<S, A, B, E, R>(
|
|
1058
|
+
<S, A, B, E, R, I extends Iterable<A> = Iterable<A>>(
|
|
1059
1059
|
zero: S,
|
|
1060
1060
|
f: (s: S, a: A, i: number) => Effect.Effect<readonly [S, B], E, R>
|
|
1061
|
-
): (elements:
|
|
1062
|
-
<A, S, B, E, R>(
|
|
1063
|
-
elements:
|
|
1061
|
+
): (elements: I) => Effect.Effect<[S, Arr.ReadonlyArray.With<I, B>], E, R>
|
|
1062
|
+
<A, S, B, E, R, I extends Iterable<A> = Iterable<A>>(
|
|
1063
|
+
elements: I,
|
|
1064
1064
|
zero: S,
|
|
1065
1065
|
f: (s: S, a: A, i: number) => Effect.Effect<readonly [S, B], E, R>
|
|
1066
|
-
): Effect.Effect<[S,
|
|
1067
|
-
} = dual(3, <A, S, B, E, R>(
|
|
1068
|
-
elements:
|
|
1066
|
+
): Effect.Effect<[S, Arr.ReadonlyArray.With<I, B>], E, R>
|
|
1067
|
+
} = dual(3, <A, S, B, E, R, I extends Iterable<A> = Iterable<A>>(
|
|
1068
|
+
elements: I,
|
|
1069
1069
|
zero: S,
|
|
1070
1070
|
f: (s: S, a: A, i: number) => Effect.Effect<readonly [S, B], E, R>
|
|
1071
1071
|
): Effect.Effect<[S, Array<B>], E, R> =>
|
|
@@ -112,10 +112,16 @@ export const unsafeMakeSemaphore = (permits: number): Semaphore => new Semaphore
|
|
|
112
112
|
/** @internal */
|
|
113
113
|
export const makeSemaphore = (permits: number) => core.sync(() => unsafeMakeSemaphore(permits))
|
|
114
114
|
|
|
115
|
-
class Latch implements Effect.Latch {
|
|
115
|
+
class Latch extends Effectable.Class<void> implements Effect.Latch {
|
|
116
116
|
waiters: Array<(_: Effect.Effect<void>) => void> = []
|
|
117
117
|
scheduled = false
|
|
118
|
-
constructor(private isOpen: boolean) {
|
|
118
|
+
constructor(private isOpen: boolean) {
|
|
119
|
+
super()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
commit() {
|
|
123
|
+
return this.await
|
|
124
|
+
}
|
|
119
125
|
|
|
120
126
|
private unsafeSchedule(fiber: Fiber.RuntimeFiber<void>) {
|
|
121
127
|
if (this.scheduled || this.waiters.length === 0) {
|