effect 3.2.8 → 3.3.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/Redacted/package.json +6 -0
- package/dist/cjs/Config.js +9 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Either.js +2 -1
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/Iterable.js +15 -2
- package/dist/cjs/Iterable.js.map +1 -1
- package/dist/cjs/Layer.js +11 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/Option.js +7 -1
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/Pool.js +26 -0
- package/dist/cjs/Pool.js.map +1 -1
- package/dist/cjs/Predicate.js +51 -1
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Redacted.js +65 -0
- package/dist/cjs/Redacted.js.map +1 -0
- package/dist/cjs/STM.js.map +1 -1
- package/dist/cjs/Secret.js +7 -0
- package/dist/cjs/Secret.js.map +1 -1
- package/dist/cjs/Stream.js +32 -1
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/Tuple.js +15 -1
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +14 -18
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/clock.js +1 -1
- package/dist/cjs/internal/clock.js.map +1 -1
- package/dist/cjs/internal/config.js +8 -1
- package/dist/cjs/internal/config.js.map +1 -1
- package/dist/cjs/internal/layer.js +14 -2
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/pool.js +206 -235
- package/dist/cjs/internal/pool.js.map +1 -1
- package/dist/cjs/internal/redacted.js +87 -0
- package/dist/cjs/internal/redacted.js.map +1 -0
- package/dist/cjs/internal/secret.js +40 -23
- package/dist/cjs/internal/secret.js.map +1 -1
- package/dist/cjs/internal/stm/stm.js +2 -1
- package/dist/cjs/internal/stm/stm.js.map +1 -1
- package/dist/cjs/internal/stream.js +15 -7
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Config.d.ts +13 -6
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +1 -1
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +7 -0
- package/dist/dts/Iterable.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +20 -0
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/Pool.d.ts +31 -0
- package/dist/dts/Pool.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +57 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Redacted.d.ts +68 -0
- package/dist/dts/Redacted.d.ts.map +1 -0
- package/dist/dts/STM.d.ts +4 -1
- package/dist/dts/STM.d.ts.map +1 -1
- package/dist/dts/Secret.d.ts +14 -1
- package/dist/dts/Secret.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +61 -4
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +51 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +46 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/Utils.d.ts +6 -5
- package/dist/dts/Utils.d.ts.map +1 -1
- package/dist/dts/index.d.ts +5 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts +15 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/dts/internal/redacted.d.ts +2 -0
- package/dist/dts/internal/redacted.d.ts.map +1 -0
- package/dist/dts/internal/stm/stm.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Config.js +8 -0
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Either.js +2 -1
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/Iterable.js +12 -0
- package/dist/esm/Iterable.js.map +1 -1
- package/dist/esm/Layer.js +10 -0
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/Option.js +7 -1
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/Pool.js +26 -0
- package/dist/esm/Pool.js.map +1 -1
- package/dist/esm/Predicate.js +50 -0
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Redacted.js +33 -0
- package/dist/esm/Redacted.js.map +1 -0
- package/dist/esm/STM.js.map +1 -1
- package/dist/esm/Secret.js +7 -0
- package/dist/esm/Secret.js.map +1 -1
- package/dist/esm/Stream.js +31 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/Tuple.js +51 -0
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +14 -18
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/clock.js +1 -1
- package/dist/esm/internal/clock.js.map +1 -1
- package/dist/esm/internal/config.js +6 -0
- package/dist/esm/internal/config.js.map +1 -1
- package/dist/esm/internal/layer.js +12 -0
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/pool.js +205 -235
- package/dist/esm/internal/pool.js.map +1 -1
- package/dist/esm/internal/redacted.js +52 -0
- package/dist/esm/internal/redacted.js.map +1 -0
- package/dist/esm/internal/secret.js +39 -22
- package/dist/esm/internal/secret.js.map +1 -1
- package/dist/esm/internal/stm/stm.js +2 -1
- package/dist/esm/internal/stm/stm.js.map +1 -1
- package/dist/esm/internal/stream.js +13 -4
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +9 -1
- package/src/Config.ts +15 -7
- package/src/Context.ts +1 -1
- package/src/Either.ts +4 -1
- package/src/Iterable.ts +13 -0
- package/src/Layer.ts +22 -0
- package/src/Option.ts +7 -1
- package/src/Pool.ts +39 -6
- package/src/Predicate.ts +59 -0
- package/src/Redacted.ts +79 -0
- package/src/STM.ts +7 -2
- package/src/Secret.ts +14 -1
- package/src/Stream.ts +67 -7
- package/src/Tuple.ts +53 -0
- package/src/Types.ts +48 -0
- package/src/Utils.ts +9 -6
- package/src/index.ts +6 -0
- package/src/internal/cause.ts +14 -17
- package/src/internal/clock.ts +1 -6
- package/src/internal/config.ts +11 -0
- package/src/internal/layer.ts +63 -0
- package/src/internal/pool.ts +320 -447
- package/src/internal/redacted.ts +69 -0
- package/src/internal/secret.ts +39 -28
- package/src/internal/stm/stm.ts +4 -1
- package/src/internal/stream.ts +111 -50
- package/src/internal/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "The missing standard library for TypeScript, for writing production-grade software.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -482,6 +482,11 @@
|
|
|
482
482
|
"import": "./dist/esm/RedBlackTree.js",
|
|
483
483
|
"default": "./dist/cjs/RedBlackTree.js"
|
|
484
484
|
},
|
|
485
|
+
"./Redacted": {
|
|
486
|
+
"types": "./dist/dts/Redacted.d.ts",
|
|
487
|
+
"import": "./dist/esm/Redacted.js",
|
|
488
|
+
"default": "./dist/cjs/Redacted.js"
|
|
489
|
+
},
|
|
485
490
|
"./Ref": {
|
|
486
491
|
"types": "./dist/dts/Ref.d.ts",
|
|
487
492
|
"import": "./dist/esm/Ref.js",
|
|
@@ -1081,6 +1086,9 @@
|
|
|
1081
1086
|
"RedBlackTree": [
|
|
1082
1087
|
"./dist/dts/RedBlackTree.d.ts"
|
|
1083
1088
|
],
|
|
1089
|
+
"Redacted": [
|
|
1090
|
+
"./dist/dts/Redacted.d.ts"
|
|
1091
|
+
],
|
|
1084
1092
|
"Ref": [
|
|
1085
1093
|
"./dist/dts/Ref.d.ts"
|
|
1086
1094
|
],
|
package/src/Config.ts
CHANGED
|
@@ -13,6 +13,7 @@ import * as internal from "./internal/config.js"
|
|
|
13
13
|
import type * as LogLevel from "./LogLevel.js"
|
|
14
14
|
import type * as Option from "./Option.js"
|
|
15
15
|
import type { Predicate, Refinement } from "./Predicate.js"
|
|
16
|
+
import type * as Redacted from "./Redacted.js"
|
|
16
17
|
import type * as Secret from "./Secret.js"
|
|
17
18
|
import type * as Types from "./Types.js"
|
|
18
19
|
|
|
@@ -69,13 +70,11 @@ export declare namespace Config {
|
|
|
69
70
|
* @since 2.0.0
|
|
70
71
|
* @category models
|
|
71
72
|
*/
|
|
72
|
-
export type Wrap<A> = [NonNullable<A>] extends [infer T] ?
|
|
73
|
-
[T] extends [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
| Config<A>
|
|
73
|
+
export type Wrap<A> = [NonNullable<A>] extends [infer T] ?
|
|
74
|
+
[T] extends [Record<string, any>] ? [Exclude<keyof T, string>] extends [never] ?
|
|
75
|
+
| { readonly [K in keyof A]: Wrap<A[K]> }
|
|
76
|
+
| Config<A>
|
|
77
|
+
: Config<A>
|
|
79
78
|
: Config<A>
|
|
80
79
|
: Config<A>
|
|
81
80
|
}
|
|
@@ -332,9 +331,18 @@ export const repeat: <A>(self: Config<A>) => Config<Array<A>> = internal.repeat
|
|
|
332
331
|
*
|
|
333
332
|
* @since 2.0.0
|
|
334
333
|
* @category constructors
|
|
334
|
+
* @deprecated
|
|
335
335
|
*/
|
|
336
336
|
export const secret: (name?: string) => Config<Secret.Secret> = internal.secret
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Constructs a config for a redacted value.
|
|
340
|
+
*
|
|
341
|
+
* @since 2.0.0
|
|
342
|
+
* @category constructors
|
|
343
|
+
*/
|
|
344
|
+
export const redacted: (name?: string) => Config<Redacted.Redacted> = internal.redacted
|
|
345
|
+
|
|
338
346
|
/**
|
|
339
347
|
* Constructs a config for a sequence of values.
|
|
340
348
|
*
|
package/src/Context.ts
CHANGED
|
@@ -89,7 +89,7 @@ export declare namespace Tag {
|
|
|
89
89
|
* @since 2.0.0
|
|
90
90
|
*/
|
|
91
91
|
export type Identifier<T extends Tag<any, any> | TagClassShape<any, any>> = T extends Tag<infer A, any> ? A
|
|
92
|
-
: T extends TagClassShape<
|
|
92
|
+
: T extends TagClassShape<any, any> ? T
|
|
93
93
|
: never
|
|
94
94
|
}
|
|
95
95
|
|
package/src/Either.ts
CHANGED
|
@@ -700,7 +700,10 @@ const adapter = Gen.adapter<EitherTypeLambda>()
|
|
|
700
700
|
* @category generators
|
|
701
701
|
* @since 2.0.0
|
|
702
702
|
*/
|
|
703
|
-
export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (
|
|
703
|
+
export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {
|
|
704
|
+
const f = (args.length === 1)
|
|
705
|
+
? args[0]
|
|
706
|
+
: args[1].bind(args[0])
|
|
704
707
|
const iterator = f(adapter)
|
|
705
708
|
let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()
|
|
706
709
|
if (state.done) {
|
package/src/Iterable.ts
CHANGED
|
@@ -265,6 +265,19 @@ export const head = <A>(self: Iterable<A>): Option<A> => {
|
|
|
265
265
|
return result.done ? O.none() : O.some(result.value)
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Get the first element of a `Iterable`, or throw an error if the `Iterable` is empty.
|
|
270
|
+
*
|
|
271
|
+
* @category getters
|
|
272
|
+
* @since 3.3.0
|
|
273
|
+
*/
|
|
274
|
+
export const unsafeHead = <A>(self: Iterable<A>): A => {
|
|
275
|
+
const iterator = self[Symbol.iterator]()
|
|
276
|
+
const result = iterator.next()
|
|
277
|
+
if (result.done) throw new Error("unsafeHead: empty iterable")
|
|
278
|
+
return result.value
|
|
279
|
+
}
|
|
280
|
+
|
|
268
281
|
/**
|
|
269
282
|
* Keep only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.
|
|
270
283
|
*
|
package/src/Layer.ts
CHANGED
|
@@ -139,6 +139,28 @@ export const isLayer: (u: unknown) => u is Layer<unknown, unknown, unknown> = in
|
|
|
139
139
|
*/
|
|
140
140
|
export const isFresh: <RIn, E, ROut>(self: Layer<ROut, E, RIn>) => boolean = internal.isFresh
|
|
141
141
|
|
|
142
|
+
/**
|
|
143
|
+
* @since 3.3.0
|
|
144
|
+
* @category tracing
|
|
145
|
+
*/
|
|
146
|
+
export const annotateLogs: {
|
|
147
|
+
(key: string, value: unknown): <A, E, R>(self: Layer<A, E, R>) => Layer<A, E, R>
|
|
148
|
+
(values: Record<string, unknown>): <A, E, R>(self: Layer<A, E, R>) => Layer<A, E, R>
|
|
149
|
+
<A, E, R>(self: Layer<A, E, R>, key: string, value: unknown): Layer<A, E, R>
|
|
150
|
+
<A, E, R>(self: Layer<A, E, R>, values: Record<string, unknown>): Layer<A, E, R>
|
|
151
|
+
} = internal.annotateLogs
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @since 3.3.0
|
|
155
|
+
* @category tracing
|
|
156
|
+
*/
|
|
157
|
+
export const annotateSpans: {
|
|
158
|
+
(key: string, value: unknown): <A, E, R>(self: Layer<A, E, R>) => Layer<A, E, R>
|
|
159
|
+
(values: Record<string, unknown>): <A, E, R>(self: Layer<A, E, R>) => Layer<A, E, R>
|
|
160
|
+
<A, E, R>(self: Layer<A, E, R>, key: string, value: unknown): Layer<A, E, R>
|
|
161
|
+
<A, E, R>(self: Layer<A, E, R>, values: Record<string, unknown>): Layer<A, E, R>
|
|
162
|
+
} = internal.annotateSpans
|
|
163
|
+
|
|
142
164
|
/**
|
|
143
165
|
* Builds a layer into a scoped value.
|
|
144
166
|
*
|
package/src/Option.ts
CHANGED
|
@@ -1345,7 +1345,13 @@ const adapter = Gen.adapter<OptionTypeLambda>()
|
|
|
1345
1345
|
* @category generators
|
|
1346
1346
|
* @since 2.0.0
|
|
1347
1347
|
*/
|
|
1348
|
-
export const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (
|
|
1348
|
+
export const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {
|
|
1349
|
+
let f: any
|
|
1350
|
+
if (args.length === 1) {
|
|
1351
|
+
f = args[0]
|
|
1352
|
+
} else {
|
|
1353
|
+
f = args[1].bind(args[0])
|
|
1354
|
+
}
|
|
1349
1355
|
const iterator = f(adapter)
|
|
1350
1356
|
let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()
|
|
1351
1357
|
if (state.done) {
|
package/src/Pool.ts
CHANGED
|
@@ -74,6 +74,16 @@ export const isPool: (u: unknown) => u is Pool<unknown, unknown> = internal.isPo
|
|
|
74
74
|
* because the `Scope` is closed, the individual items allocated by the pool
|
|
75
75
|
* will be released in some unspecified order.
|
|
76
76
|
*
|
|
77
|
+
* By setting the `concurrency` parameter, you can control the level of concurrent
|
|
78
|
+
* access per pool item. By default, the number of permits is set to `1`.
|
|
79
|
+
*
|
|
80
|
+
* `targetUtilization` determines when to create new pool items. It is a value
|
|
81
|
+
* between 0 and 1, where 1 means only create new pool items when all the existing
|
|
82
|
+
* items are fully utilized.
|
|
83
|
+
*
|
|
84
|
+
* A `targetUtilization` of 0.5 will create new pool items when the existing items are
|
|
85
|
+
* 50% utilized.
|
|
86
|
+
*
|
|
77
87
|
* @since 2.0.0
|
|
78
88
|
* @category constructors
|
|
79
89
|
*/
|
|
@@ -81,6 +91,8 @@ export const make: <A, E, R>(
|
|
|
81
91
|
options: {
|
|
82
92
|
readonly acquire: Effect.Effect<A, E, R>
|
|
83
93
|
readonly size: number
|
|
94
|
+
readonly concurrency?: number | undefined
|
|
95
|
+
readonly targetUtilization?: number | undefined
|
|
84
96
|
}
|
|
85
97
|
) => Effect.Effect<Pool<A, E>, never, Scope.Scope | R> = internal.make
|
|
86
98
|
|
|
@@ -92,6 +104,22 @@ export const make: <A, E, R>(
|
|
|
92
104
|
* used, the individual items allocated by the pool will be released in some
|
|
93
105
|
* unspecified order.
|
|
94
106
|
*
|
|
107
|
+
* By setting the `concurrency` parameter, you can control the level of concurrent
|
|
108
|
+
* access per pool item. By default, the number of permits is set to `1`.
|
|
109
|
+
*
|
|
110
|
+
* `targetUtilization` determines when to create new pool items. It is a value
|
|
111
|
+
* between 0 and 1, where 1 means only create new pool items when all the existing
|
|
112
|
+
* items are fully utilized.
|
|
113
|
+
*
|
|
114
|
+
* A `targetUtilization` of 0.5 will create new pool items when the existing items are
|
|
115
|
+
* 50% utilized.
|
|
116
|
+
*
|
|
117
|
+
* The `timeToLiveStrategy` determines how items are invalidated. If set to
|
|
118
|
+
* "creation", then items are invalidated based on their creation time. If set
|
|
119
|
+
* to "usage", then items are invalidated based on pool usage.
|
|
120
|
+
*
|
|
121
|
+
* By default, the `timeToLiveStrategy` is set to "usage".
|
|
122
|
+
*
|
|
95
123
|
* ```ts
|
|
96
124
|
* import { createConnection } from "mysql2";
|
|
97
125
|
* import { Duration, Effect, Pool } from "effect"
|
|
@@ -115,12 +143,17 @@ export const make: <A, E, R>(
|
|
|
115
143
|
* @since 2.0.0
|
|
116
144
|
* @category constructors
|
|
117
145
|
*/
|
|
118
|
-
export const makeWithTTL: <A, E, R>(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
export const makeWithTTL: <A, E, R>(
|
|
147
|
+
options: {
|
|
148
|
+
readonly acquire: Effect.Effect<A, E, R>
|
|
149
|
+
readonly min: number
|
|
150
|
+
readonly max: number
|
|
151
|
+
readonly concurrency?: number | undefined
|
|
152
|
+
readonly targetUtilization?: number | undefined
|
|
153
|
+
readonly timeToLive: Duration.DurationInput
|
|
154
|
+
readonly timeToLiveStrategy?: "creation" | "usage" | undefined
|
|
155
|
+
}
|
|
156
|
+
) => Effect.Effect<Pool<A, E>, never, Scope.Scope | R> = internal.makeWithTTL
|
|
124
157
|
|
|
125
158
|
/**
|
|
126
159
|
* Retrieves an item from the pool in a scoped effect. Note that if
|
package/src/Predicate.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { dual, isFunction as isFunction_ } from "./Function.js"
|
|
5
5
|
import type { TypeLambda } from "./HKT.js"
|
|
6
|
+
import type { TupleOf, TupleOfAtLeast } from "./Types.js"
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @category models
|
|
@@ -52,6 +53,64 @@ export const mapInput: {
|
|
|
52
53
|
<A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>
|
|
53
54
|
} = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))
|
|
54
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.
|
|
58
|
+
*
|
|
59
|
+
* An `Array` is considered to be a `TupleOf` if its length is exactly `N`.
|
|
60
|
+
*
|
|
61
|
+
* @param self - The `Array` to check.
|
|
62
|
+
* @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* import { isTupleOf } from "effect/Predicate"
|
|
66
|
+
*
|
|
67
|
+
* assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);
|
|
68
|
+
* assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);
|
|
69
|
+
* assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);
|
|
70
|
+
*
|
|
71
|
+
* const arr: number[] = [1, 2, 3];
|
|
72
|
+
* if (isTupleOf(arr, 3)) {
|
|
73
|
+
* console.log(arr);
|
|
74
|
+
* // ^? [number, number, number]
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* @category guards
|
|
78
|
+
* @since 3.3.0
|
|
79
|
+
*/
|
|
80
|
+
export const isTupleOf: {
|
|
81
|
+
<N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>
|
|
82
|
+
<T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>
|
|
83
|
+
} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.
|
|
87
|
+
*
|
|
88
|
+
* An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.
|
|
89
|
+
*
|
|
90
|
+
* @param self - The `Array` to check.
|
|
91
|
+
* @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* import { isTupleOfAtLeast } from "effect/Predicate"
|
|
95
|
+
*
|
|
96
|
+
* assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);
|
|
97
|
+
* assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);
|
|
98
|
+
* assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);
|
|
99
|
+
*
|
|
100
|
+
* const arr: number[] = [1, 2, 3, 4];
|
|
101
|
+
* if (isTupleOfAtLeast(arr, 3)) {
|
|
102
|
+
* console.log(arr);
|
|
103
|
+
* // ^? [number, number, number, ...number[]]
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* @category guards
|
|
107
|
+
* @since 3.3.0
|
|
108
|
+
*/
|
|
109
|
+
export const isTupleOfAtLeast: {
|
|
110
|
+
<N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>
|
|
111
|
+
<T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>
|
|
112
|
+
} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)
|
|
113
|
+
|
|
55
114
|
/**
|
|
56
115
|
* Tests if a value is `truthy`.
|
|
57
116
|
*
|
package/src/Redacted.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 3.3.0
|
|
3
|
+
*/
|
|
4
|
+
import type * as Equal from "./Equal.js"
|
|
5
|
+
import * as Equivalence from "./Equivalence.js"
|
|
6
|
+
import * as redacted_ from "./internal/redacted.js"
|
|
7
|
+
import type { Pipeable } from "./Pipeable.js"
|
|
8
|
+
import type { Covariant } from "./Types.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @since 3.3.0
|
|
12
|
+
* @category symbols
|
|
13
|
+
*/
|
|
14
|
+
export const RedactedTypeId: unique symbol = redacted_.RedactedTypeId
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @since 3.3.0
|
|
18
|
+
* @category symbols
|
|
19
|
+
*/
|
|
20
|
+
export type RedactedTypeId = typeof RedactedTypeId
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @since 3.3.0
|
|
24
|
+
* @category models
|
|
25
|
+
*/
|
|
26
|
+
export interface Redacted<out A = string> extends Redacted.Variance<A>, Equal.Equal, Pipeable {
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @since 3.3.0
|
|
31
|
+
*/
|
|
32
|
+
export declare namespace Redacted {
|
|
33
|
+
/**
|
|
34
|
+
* @since 3.3.0
|
|
35
|
+
* @category models
|
|
36
|
+
*/
|
|
37
|
+
export interface Variance<out A> {
|
|
38
|
+
readonly [RedactedTypeId]: {
|
|
39
|
+
readonly _A: Covariant<A>
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @since 3.3.0
|
|
45
|
+
* @category type-level
|
|
46
|
+
*/
|
|
47
|
+
export type Value<T extends Redacted<any>> = [T] extends [Redacted<infer _A>] ? _A : never
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @since 3.3.0
|
|
52
|
+
* @category refinements
|
|
53
|
+
*/
|
|
54
|
+
export const isRedacted: (u: unknown) => u is Redacted<unknown> = redacted_.isRedacted
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @since 3.3.0
|
|
58
|
+
* @category constructors
|
|
59
|
+
*/
|
|
60
|
+
export const make: <A>(value: A) => Redacted<A> = redacted_.make
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @since 3.3.0
|
|
64
|
+
* @category getters
|
|
65
|
+
*/
|
|
66
|
+
export const value: <A>(self: Redacted<A>) => A = redacted_.value
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @since 3.3.0
|
|
70
|
+
* @category unsafe
|
|
71
|
+
*/
|
|
72
|
+
export const unsafeWipe: <A>(self: Redacted<A>) => boolean = redacted_.unsafeWipe
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @category equivalence
|
|
76
|
+
* @since 3.3.0
|
|
77
|
+
*/
|
|
78
|
+
export const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Redacted<A>> =>
|
|
79
|
+
Equivalence.make((x, y) => x === y || (isEquivalent(value(x), value(y))))
|
package/src/STM.ts
CHANGED
|
@@ -1065,8 +1065,13 @@ export interface Adapter {
|
|
|
1065
1065
|
* @since 2.0.0
|
|
1066
1066
|
* @category constructors
|
|
1067
1067
|
*/
|
|
1068
|
-
export const gen: <Eff extends YieldWrap<STM<any, any, any>>, AEff>(
|
|
1069
|
-
|
|
1068
|
+
export const gen: <Self, Eff extends YieldWrap<STM<any, any, any>>, AEff>(
|
|
1069
|
+
...args:
|
|
1070
|
+
| [
|
|
1071
|
+
self: Self,
|
|
1072
|
+
body: (this: Self, resume: Adapter) => Generator<Eff, AEff, never>
|
|
1073
|
+
]
|
|
1074
|
+
| [body: (resume: Adapter) => Generator<Eff, AEff, never>]
|
|
1070
1075
|
) => STM<
|
|
1071
1076
|
AEff,
|
|
1072
1077
|
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<STM<infer _A, infer E, infer _R>>] ? E : never,
|
package/src/Secret.ts
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 2.0.0
|
|
3
|
+
* @deprecated
|
|
3
4
|
*/
|
|
4
5
|
import type * as Equal from "./Equal.js"
|
|
5
6
|
import * as InternalSecret from "./internal/secret.js"
|
|
7
|
+
import type * as Redacted from "./Redacted.js"
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @since 2.0.0
|
|
9
11
|
* @category symbols
|
|
12
|
+
* @deprecated
|
|
10
13
|
*/
|
|
11
14
|
export const SecretTypeId: unique symbol = InternalSecret.SecretTypeId
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* @since 2.0.0
|
|
15
18
|
* @category symbols
|
|
19
|
+
* @deprecated
|
|
16
20
|
*/
|
|
17
21
|
export type SecretTypeId = typeof SecretTypeId
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* @since 2.0.0
|
|
21
25
|
* @category models
|
|
26
|
+
* @deprecated
|
|
22
27
|
*/
|
|
23
|
-
export interface Secret extends Secret.Proto, Equal.Equal {
|
|
28
|
+
export interface Secret extends Redacted.Redacted, Secret.Proto, Equal.Equal {
|
|
24
29
|
/** @internal */
|
|
25
30
|
readonly raw: Array<number>
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* @since 2.0.0
|
|
35
|
+
* @deprecated
|
|
30
36
|
*/
|
|
31
37
|
export declare namespace Secret {
|
|
32
38
|
/**
|
|
33
39
|
* @since 2.0.0
|
|
34
40
|
* @category models
|
|
41
|
+
* @deprecated
|
|
35
42
|
*/
|
|
36
43
|
export interface Proto {
|
|
37
44
|
readonly [SecretTypeId]: SecretTypeId
|
|
@@ -41,35 +48,41 @@ export declare namespace Secret {
|
|
|
41
48
|
/**
|
|
42
49
|
* @since 2.0.0
|
|
43
50
|
* @category refinements
|
|
51
|
+
* @deprecated
|
|
44
52
|
*/
|
|
45
53
|
export const isSecret: (u: unknown) => u is Secret = InternalSecret.isSecret
|
|
46
54
|
|
|
47
55
|
/**
|
|
48
56
|
* @since 2.0.0
|
|
49
57
|
* @category constructors
|
|
58
|
+
* @deprecated
|
|
50
59
|
*/
|
|
51
60
|
export const make: (bytes: Array<number>) => Secret = InternalSecret.make
|
|
52
61
|
|
|
53
62
|
/**
|
|
54
63
|
* @since 2.0.0
|
|
55
64
|
* @category constructors
|
|
65
|
+
* @deprecated
|
|
56
66
|
*/
|
|
57
67
|
export const fromIterable: (iterable: Iterable<string>) => Secret = InternalSecret.fromIterable
|
|
58
68
|
|
|
59
69
|
/**
|
|
60
70
|
* @since 2.0.0
|
|
61
71
|
* @category constructors
|
|
72
|
+
* @deprecated
|
|
62
73
|
*/
|
|
63
74
|
export const fromString: (text: string) => Secret = InternalSecret.fromString
|
|
64
75
|
|
|
65
76
|
/**
|
|
66
77
|
* @since 2.0.0
|
|
67
78
|
* @category getters
|
|
79
|
+
* @deprecated
|
|
68
80
|
*/
|
|
69
81
|
export const value: (self: Secret) => string = InternalSecret.value
|
|
70
82
|
|
|
71
83
|
/**
|
|
72
84
|
* @since 2.0.0
|
|
73
85
|
* @category unsafe
|
|
86
|
+
* @deprecated
|
|
74
87
|
*/
|
|
75
88
|
export const unsafeWipe: (self: Secret) => void = InternalSecret.unsafeWipe
|
package/src/Stream.ts
CHANGED
|
@@ -3860,7 +3860,17 @@ export const toQueueOfElements: {
|
|
|
3860
3860
|
* @since 2.0.0
|
|
3861
3861
|
* @category destructors
|
|
3862
3862
|
*/
|
|
3863
|
-
export const toReadableStream:
|
|
3863
|
+
export const toReadableStream: {
|
|
3864
|
+
<A>(
|
|
3865
|
+
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
|
|
3866
|
+
): <E>(
|
|
3867
|
+
self: Stream<A, E>
|
|
3868
|
+
) => ReadableStream<A>
|
|
3869
|
+
<A, E>(
|
|
3870
|
+
self: Stream<A, E>,
|
|
3871
|
+
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
|
|
3872
|
+
): ReadableStream<A>
|
|
3873
|
+
} = internal.toReadableStream
|
|
3864
3874
|
|
|
3865
3875
|
/**
|
|
3866
3876
|
* Converts the stream to a `Effect<ReadableStream>`.
|
|
@@ -3870,8 +3880,17 @@ export const toReadableStream: <A, E>(self: Stream<A, E>) => ReadableStream<A> =
|
|
|
3870
3880
|
* @since 2.0.0
|
|
3871
3881
|
* @category destructors
|
|
3872
3882
|
*/
|
|
3873
|
-
export const toReadableStreamEffect:
|
|
3874
|
-
|
|
3883
|
+
export const toReadableStreamEffect: {
|
|
3884
|
+
<A>(
|
|
3885
|
+
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
|
|
3886
|
+
): <E, R>(
|
|
3887
|
+
self: Stream<A, E, R>
|
|
3888
|
+
) => Effect.Effect<ReadableStream<A>, never, R>
|
|
3889
|
+
<A, E, R>(
|
|
3890
|
+
self: Stream<A, E, R>,
|
|
3891
|
+
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
|
|
3892
|
+
): Effect.Effect<ReadableStream<A>, never, R>
|
|
3893
|
+
} = internal.toReadableStreamEffect
|
|
3875
3894
|
|
|
3876
3895
|
/**
|
|
3877
3896
|
* Converts the stream to a `ReadableStream` using the provided runtime.
|
|
@@ -3882,12 +3901,14 @@ export const toReadableStreamEffect: <A, E, R>(self: Stream<A, E, R>) => Effect.
|
|
|
3882
3901
|
* @category destructors
|
|
3883
3902
|
*/
|
|
3884
3903
|
export const toReadableStreamRuntime: {
|
|
3885
|
-
<XR>(
|
|
3886
|
-
runtime: Runtime<XR
|
|
3887
|
-
|
|
3904
|
+
<A, XR>(
|
|
3905
|
+
runtime: Runtime<XR>,
|
|
3906
|
+
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
|
|
3907
|
+
): <E, R extends XR>(self: Stream<A, E, R>) => ReadableStream<A>
|
|
3888
3908
|
<A, E, XR, R extends XR>(
|
|
3889
3909
|
self: Stream<A, E, R>,
|
|
3890
|
-
runtime: Runtime<XR
|
|
3910
|
+
runtime: Runtime<XR>,
|
|
3911
|
+
options?: { readonly strategy?: QueuingStrategy<A> | undefined }
|
|
3891
3912
|
): ReadableStream<A>
|
|
3892
3913
|
} = internal.toReadableStreamRuntime
|
|
3893
3914
|
|
|
@@ -4329,6 +4350,45 @@ export const zipLatest: {
|
|
|
4329
4350
|
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<[A, A2], E | E2, R | R2>
|
|
4330
4351
|
} = internal.zipLatest
|
|
4331
4352
|
|
|
4353
|
+
/**
|
|
4354
|
+
* Zips multiple streams so that when a value is emitted by any of the streams,
|
|
4355
|
+
* it is combined with the latest values from the other streams to produce a result.
|
|
4356
|
+
*
|
|
4357
|
+
* Note: tracking the latest value is done on a per-chunk basis. That means
|
|
4358
|
+
* that emitted elements that are not the last value in chunks will never be
|
|
4359
|
+
* used for zipping.
|
|
4360
|
+
*
|
|
4361
|
+
* @example
|
|
4362
|
+
* import { Stream, Schedule, Console, Effect } from "effect"
|
|
4363
|
+
*
|
|
4364
|
+
* const stream = Stream.zipLatestAll(
|
|
4365
|
+
* Stream.fromSchedule(Schedule.spaced('1 millis')),
|
|
4366
|
+
* Stream.fromSchedule(Schedule.spaced('2 millis')),
|
|
4367
|
+
* Stream.fromSchedule(Schedule.spaced('4 millis')),
|
|
4368
|
+
* ).pipe(Stream.take(6), Stream.tap(Console.log))
|
|
4369
|
+
*
|
|
4370
|
+
* Effect.runPromise(Stream.runDrain(stream))
|
|
4371
|
+
* // Output:
|
|
4372
|
+
* // [ 0, 0, 0 ]
|
|
4373
|
+
* // [ 1, 0, 0 ]
|
|
4374
|
+
* // [ 1, 1, 0 ]
|
|
4375
|
+
* // [ 2, 1, 0 ]
|
|
4376
|
+
* // [ 3, 1, 0 ]
|
|
4377
|
+
* // [ 3, 1, 1 ]
|
|
4378
|
+
* // .....
|
|
4379
|
+
*
|
|
4380
|
+
* @since 3.3.0
|
|
4381
|
+
* @category zipping
|
|
4382
|
+
*/
|
|
4383
|
+
export const zipLatestAll: <T extends ReadonlyArray<Stream<any, any, any>>>(
|
|
4384
|
+
...streams: T
|
|
4385
|
+
) => Stream<
|
|
4386
|
+
[T[number]] extends [never] ? never
|
|
4387
|
+
: { [K in keyof T]: T[K] extends Stream<infer A, infer _E, infer _R> ? A : never },
|
|
4388
|
+
[T[number]] extends [never] ? never : T[number] extends Stream<infer _A, infer _E, infer _R> ? _E : never,
|
|
4389
|
+
[T[number]] extends [never] ? never : T[number] extends Stream<infer _A, infer _E, infer _R> ? _R : never
|
|
4390
|
+
> = internal.zipLatestAll
|
|
4391
|
+
|
|
4332
4392
|
/**
|
|
4333
4393
|
* Zips the two streams so that when a value is emitted by either of the two
|
|
4334
4394
|
* streams, it is combined with the latest value from the other stream to
|
package/src/Tuple.ts
CHANGED
|
@@ -202,3 +202,56 @@ export const appendElement: {
|
|
|
202
202
|
- swap
|
|
203
203
|
|
|
204
204
|
*/
|
|
205
|
+
|
|
206
|
+
export {
|
|
207
|
+
/**
|
|
208
|
+
* Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.
|
|
209
|
+
*
|
|
210
|
+
* An `Array` is considered to be a `TupleOf` if its length is exactly `N`.
|
|
211
|
+
*
|
|
212
|
+
* @param self - The `Array` to check.
|
|
213
|
+
* @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* import { isTupleOf } from "effect/Tuple"
|
|
217
|
+
*
|
|
218
|
+
* assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);
|
|
219
|
+
* assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);
|
|
220
|
+
* assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);
|
|
221
|
+
*
|
|
222
|
+
* const arr: number[] = [1, 2, 3];
|
|
223
|
+
* if (isTupleOf(arr, 3)) {
|
|
224
|
+
* console.log(arr);
|
|
225
|
+
* // ^? [number, number, number]
|
|
226
|
+
* }
|
|
227
|
+
*
|
|
228
|
+
* @category guards
|
|
229
|
+
* @since 3.3.0
|
|
230
|
+
*/
|
|
231
|
+
isTupleOf,
|
|
232
|
+
/**
|
|
233
|
+
* Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.
|
|
234
|
+
*
|
|
235
|
+
* An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.
|
|
236
|
+
*
|
|
237
|
+
* @param self - The `Array` to check.
|
|
238
|
+
* @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* import { isTupleOfAtLeast } from "effect/Tuple"
|
|
242
|
+
*
|
|
243
|
+
* assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);
|
|
244
|
+
* assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);
|
|
245
|
+
* assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);
|
|
246
|
+
*
|
|
247
|
+
* const arr: number[] = [1, 2, 3, 4];
|
|
248
|
+
* if (isTupleOfAtLeast(arr, 3)) {
|
|
249
|
+
* console.log(arr);
|
|
250
|
+
* // ^? [number, number, number, ...number[]]
|
|
251
|
+
* }
|
|
252
|
+
*
|
|
253
|
+
* @category guards
|
|
254
|
+
* @since 3.3.0
|
|
255
|
+
*/
|
|
256
|
+
isTupleOfAtLeast
|
|
257
|
+
} from "./Predicate.js"
|