effect 4.0.0-beta.83 → 4.0.0-beta.84
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/Array.d.ts +64 -64
- package/dist/Array.js +26 -26
- package/dist/Cache.d.ts +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cause.d.ts +68 -68
- package/dist/Cause.js +47 -47
- package/dist/Channel.d.ts +5 -5
- package/dist/Channel.js +3 -3
- package/dist/Clock.d.ts +1 -1
- package/dist/Clock.js +1 -1
- package/dist/Combiner.d.ts +9 -9
- package/dist/Combiner.js +8 -8
- package/dist/Config.d.ts +15 -94
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +22 -70
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +58 -74
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +66 -41
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Console.d.ts +1 -1
- package/dist/Console.js +1 -1
- package/dist/Data.d.ts +15 -15
- package/dist/Data.js +3 -3
- package/dist/DateTime.d.ts +6 -6
- package/dist/DateTime.js +2 -2
- package/dist/Duration.d.ts +3 -3
- package/dist/Duration.js +3 -3
- package/dist/Effect.d.ts +84 -45
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +72 -33
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +7 -7
- package/dist/Equal.js +5 -5
- package/dist/Equivalence.d.ts +17 -17
- package/dist/Equivalence.js +13 -13
- package/dist/Exit.d.ts +3 -3
- package/dist/Exit.js +3 -3
- package/dist/Formatter.d.ts +5 -5
- package/dist/Formatter.js +4 -4
- package/dist/Function.d.ts +10 -10
- package/dist/Function.js +3 -3
- package/dist/HashMap.d.ts +3 -3
- package/dist/HashMap.js +1 -1
- package/dist/Iterable.d.ts +6 -6
- package/dist/Iterable.js +2 -2
- package/dist/JsonPatch.d.ts +2 -2
- package/dist/Layer.d.ts +1 -1
- package/dist/Layer.js +1 -1
- package/dist/Logger.d.ts +1 -1
- package/dist/Logger.js +1 -1
- package/dist/Match.d.ts +8 -8
- package/dist/Match.js +8 -8
- package/dist/Metric.d.ts +3 -3
- package/dist/Metric.js +3 -3
- package/dist/Optic.d.ts +30 -30
- package/dist/Optic.js +12 -12
- package/dist/Option.d.ts +7 -7
- package/dist/Option.js +7 -7
- package/dist/Order.d.ts +23 -23
- package/dist/Order.js +20 -20
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.js +1 -1
- package/dist/Predicate.d.ts +88 -88
- package/dist/Predicate.js +47 -47
- package/dist/PubSub.d.ts +3 -3
- package/dist/PubSub.js +3 -3
- package/dist/Reducer.d.ts +1 -1
- package/dist/Reducer.js +1 -1
- package/dist/Result.d.ts +18 -18
- package/dist/Result.js +8 -8
- package/dist/Runtime.d.ts +1 -1
- package/dist/Runtime.js +1 -1
- package/dist/Schema.d.ts +265 -120
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +285 -116
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +13 -9
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +48 -48
- package/dist/SchemaGetter.js +44 -44
- package/dist/SchemaIssue.d.ts +3 -3
- package/dist/SchemaIssue.js +3 -3
- package/dist/SchemaParser.d.ts +122 -22
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +186 -50
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +96 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +20 -20
- package/dist/SchemaTransformation.js +18 -18
- package/dist/Stream.d.ts +3 -3
- package/dist/Stream.js +2 -2
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +1 -1
- package/dist/String.js +1 -1
- package/dist/Struct.d.ts +1 -1
- package/dist/Struct.js +1 -1
- package/dist/Types.d.ts +13 -13
- package/dist/internal/effect.js +23 -10
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/cause.d.ts +2 -0
- package/dist/internal/schema/cause.d.ts.map +1 -0
- package/dist/internal/schema/cause.js +24 -0
- package/dist/internal/schema/cause.js.map +1 -0
- package/dist/internal/schema/schema.d.ts +8 -4
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +21 -8
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +3 -3
- package/dist/testing/TestSchema.js +1 -1
- package/dist/unstable/ai/AiError.d.ts +1 -1
- package/dist/unstable/ai/AiError.js +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.js +1 -1
- package/dist/unstable/cli/Prompt.js +2 -2
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js +3 -4
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +15 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +1 -0
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +1 -0
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +65 -65
- package/src/Cache.ts +1 -1
- package/src/Cause.ts +68 -68
- package/src/Channel.ts +5 -5
- package/src/Clock.ts +1 -1
- package/src/Combiner.ts +9 -9
- package/src/Config.ts +40 -108
- package/src/ConfigProvider.ts +139 -100
- package/src/Console.ts +1 -1
- package/src/Data.ts +15 -15
- package/src/DateTime.ts +6 -6
- package/src/Duration.ts +3 -3
- package/src/Effect.ts +89 -45
- package/src/Equal.ts +7 -7
- package/src/Equivalence.ts +17 -17
- package/src/Exit.ts +3 -3
- package/src/Formatter.ts +5 -5
- package/src/Function.ts +10 -10
- package/src/HashMap.ts +3 -3
- package/src/Iterable.ts +6 -6
- package/src/JsonPatch.ts +2 -2
- package/src/Layer.ts +1 -1
- package/src/Logger.ts +1 -1
- package/src/Match.ts +8 -8
- package/src/Metric.ts +3 -3
- package/src/Optic.ts +30 -30
- package/src/Option.ts +7 -7
- package/src/Order.ts +23 -23
- package/src/Pool.ts +1 -1
- package/src/Predicate.ts +88 -88
- package/src/PubSub.ts +3 -3
- package/src/Reducer.ts +1 -1
- package/src/Result.ts +20 -20
- package/src/Runtime.ts +1 -1
- package/src/Schema.ts +314 -131
- package/src/SchemaAST.ts +20 -11
- package/src/SchemaGetter.ts +48 -48
- package/src/SchemaIssue.ts +3 -3
- package/src/SchemaParser.ts +197 -58
- package/src/SchemaRepresentation.ts +73 -3
- package/src/SchemaTransformation.ts +20 -20
- package/src/Stream.ts +4 -4
- package/src/String.ts +1 -1
- package/src/Struct.ts +1 -1
- package/src/Types.ts +13 -13
- package/src/internal/effect.ts +29 -10
- package/src/internal/schema/cause.ts +26 -0
- package/src/internal/schema/schema.ts +36 -10
- package/src/testing/TestSchema.ts +3 -3
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/cli/Prompt.ts +1 -1
- package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
- package/src/unstable/rpc/Rpc.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -4
- package/src/unstable/sql/SqlResolver.ts +15 -2
- package/src/unstable/workflow/Activity.ts +2 -0
- package/src/unstable/workflow/WorkflowEngine.ts +1 -1
package/src/Combiner.ts
CHANGED
|
@@ -24,7 +24,7 @@ import type * as Order from "./Order.ts"
|
|
|
24
24
|
* `Struct.makeCombiner` or `Option.makeCombinerFailFast`, or define the
|
|
25
25
|
* combining step for a `Reducer`.
|
|
26
26
|
*
|
|
27
|
-
* **Example** (
|
|
27
|
+
* **Example** (Combining numbers with addition)
|
|
28
28
|
*
|
|
29
29
|
* ```ts
|
|
30
30
|
* import { Combiner } from "effect"
|
|
@@ -63,7 +63,7 @@ export interface Combiner<A> {
|
|
|
63
63
|
* The returned combiner's `combine` method delegates to the provided function.
|
|
64
64
|
* Any purity, associativity, or mutation behavior comes from that function.
|
|
65
65
|
*
|
|
66
|
-
* **Example** (
|
|
66
|
+
* **Example** (Multiplying numbers)
|
|
67
67
|
*
|
|
68
68
|
* ```ts
|
|
69
69
|
* import { Combiner } from "effect"
|
|
@@ -95,7 +95,7 @@ export function make<A>(combine: (self: A, that: A) => A): Combiner<A> {
|
|
|
95
95
|
* Returns a new `Combiner` where `combine(self, that)` calls the original
|
|
96
96
|
* combiner as `combine(that, self)`.
|
|
97
97
|
*
|
|
98
|
-
* **Example** (
|
|
98
|
+
* **Example** (Reversing string concatenation)
|
|
99
99
|
*
|
|
100
100
|
* ```ts
|
|
101
101
|
* import { Combiner, String } from "effect"
|
|
@@ -128,7 +128,7 @@ export function flip<A>(combiner: Combiner<A>): Combiner<A> {
|
|
|
128
128
|
* The combiner compares values using the given `Order`. When values are equal,
|
|
129
129
|
* it returns `that` (the second argument).
|
|
130
130
|
*
|
|
131
|
-
* **Example** (minimum of two numbers)
|
|
131
|
+
* **Example** (Selecting the minimum of two numbers)
|
|
132
132
|
*
|
|
133
133
|
* ```ts
|
|
134
134
|
* import { Combiner, Number } from "effect"
|
|
@@ -164,7 +164,7 @@ export function min<A>(order: Order.Order<A>): Combiner<A> {
|
|
|
164
164
|
* The combiner compares values using the given `Order`. When values are equal,
|
|
165
165
|
* it returns `that` (the second argument).
|
|
166
166
|
*
|
|
167
|
-
* **Example** (maximum of two numbers)
|
|
167
|
+
* **Example** (Selecting the maximum of two numbers)
|
|
168
168
|
*
|
|
169
169
|
* ```ts
|
|
170
170
|
* import { Combiner, Number } from "effect"
|
|
@@ -197,7 +197,7 @@ export function max<A>(order: Order.Order<A>): Combiner<A> {
|
|
|
197
197
|
*
|
|
198
198
|
* `combine(self, that)` returns `self` and ignores `that`.
|
|
199
199
|
*
|
|
200
|
-
* **Example** (
|
|
200
|
+
* **Example** (Keeping the first value)
|
|
201
201
|
*
|
|
202
202
|
* ```ts
|
|
203
203
|
* import { Combiner } from "effect"
|
|
@@ -227,7 +227,7 @@ export function first<A>(): Combiner<A> {
|
|
|
227
227
|
*
|
|
228
228
|
* `combine(self, that)` returns `that` and ignores `self`.
|
|
229
229
|
*
|
|
230
|
-
* **Example** (
|
|
230
|
+
* **Example** (Keeping the last value)
|
|
231
231
|
*
|
|
232
232
|
* ```ts
|
|
233
233
|
* import { Combiner } from "effect"
|
|
@@ -259,7 +259,7 @@ export function last<A>(): Combiner<A> {
|
|
|
259
259
|
*
|
|
260
260
|
* `combine(self, that)` returns the constant `a` and ignores both arguments.
|
|
261
261
|
*
|
|
262
|
-
* **Example** (
|
|
262
|
+
* **Example** (Always returning zero)
|
|
263
263
|
*
|
|
264
264
|
* ```ts
|
|
265
265
|
* import { Combiner } from "effect"
|
|
@@ -295,7 +295,7 @@ export function constant<A>(a: A): Combiner<A> {
|
|
|
295
295
|
* `combiner.combine(self, combiner.combine(middle, that))`. This function is
|
|
296
296
|
* curried: first provide the separator, then the base combiner.
|
|
297
297
|
*
|
|
298
|
-
* **Example** (
|
|
298
|
+
* **Example** (Joining strings with a separator)
|
|
299
299
|
*
|
|
300
300
|
* ```ts
|
|
301
301
|
* import { Combiner, String } from "effect"
|
package/src/Config.ts
CHANGED
|
@@ -33,7 +33,7 @@ const TypeId = "~effect/Config"
|
|
|
33
33
|
* Use when you need to distinguish a `Config` from an unknown value before
|
|
34
34
|
* calling `.parse` or {@link unwrap}.
|
|
35
35
|
*
|
|
36
|
-
* **Example** (
|
|
36
|
+
* **Example** (Checking Config values)
|
|
37
37
|
*
|
|
38
38
|
* ```ts
|
|
39
39
|
* import { Config } from "effect"
|
|
@@ -93,21 +93,24 @@ export class ConfigError {
|
|
|
93
93
|
* **Details**
|
|
94
94
|
*
|
|
95
95
|
* Key members:
|
|
96
|
-
* - `parse(provider)` – runs the config against a specific provider
|
|
97
|
-
*
|
|
96
|
+
* - `parse(provider, pathPrefix?)` – runs the config against a specific provider.
|
|
97
|
+
* The optional path prefix is the logical scope accumulated from outer
|
|
98
|
+
* `Config.nested` calls.
|
|
98
99
|
* - Yieldable – can be yielded inside `Effect.gen`, which automatically
|
|
99
100
|
* resolves the current `ConfigProvider` from the context.
|
|
100
101
|
* - Pipeable – supports `.pipe(Config.map(...))` etc.
|
|
101
102
|
*
|
|
102
103
|
* @see {@link schema} – the main way to create a Config
|
|
103
|
-
* @see {@link make} – low-level constructor
|
|
104
104
|
*
|
|
105
105
|
* @category models
|
|
106
106
|
* @since 2.0.0
|
|
107
107
|
*/
|
|
108
108
|
export interface Config<out T> extends Effect.Effect<T, ConfigError> {
|
|
109
109
|
readonly [TypeId]: typeof TypeId
|
|
110
|
-
readonly parse: (
|
|
110
|
+
readonly parse: (
|
|
111
|
+
provider: ConfigProvider.ConfigProvider,
|
|
112
|
+
pathPrefix?: Path
|
|
113
|
+
) => Effect.Effect<T, ConfigError>
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
const Proto = {
|
|
@@ -125,46 +128,11 @@ const Proto = {
|
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
* **When to use**
|
|
132
|
-
*
|
|
133
|
-
* Use to build a custom config that cannot be expressed with {@link schema} or
|
|
134
|
-
* convenience constructors, or compose configs programmatically.
|
|
135
|
-
*
|
|
136
|
-
* **Details**
|
|
137
|
-
*
|
|
138
|
-
* The `parse` callback receives a `ConfigProvider` and must return
|
|
139
|
-
* `Effect<T, ConfigError>`.
|
|
140
|
-
*
|
|
141
|
-
* **Example** (Custom config that reads two keys)
|
|
142
|
-
*
|
|
143
|
-
* ```ts
|
|
144
|
-
* import { Config, ConfigProvider, Effect } from "effect"
|
|
145
|
-
*
|
|
146
|
-
* const hostPort = Config.make((provider) =>
|
|
147
|
-
* Effect.all({
|
|
148
|
-
* host: Config.string("host").parse(provider),
|
|
149
|
-
* port: Config.number("port").parse(provider)
|
|
150
|
-
* })
|
|
151
|
-
* )
|
|
152
|
-
*
|
|
153
|
-
* const provider = ConfigProvider.fromUnknown({ host: "localhost", port: 3000 })
|
|
154
|
-
* // Effect.runSync(hostPort.parse(provider))
|
|
155
|
-
* // { host: "localhost", port: 3000 }
|
|
156
|
-
* ```
|
|
157
|
-
*
|
|
158
|
-
* @see {@link schema} – higher-level constructor using Schema codecs
|
|
159
|
-
*
|
|
160
|
-
* @category constructors
|
|
161
|
-
* @since 4.0.0
|
|
162
|
-
*/
|
|
163
|
-
export function make<T>(
|
|
164
|
-
parse: (provider: ConfigProvider.ConfigProvider) => Effect.Effect<T, ConfigError>
|
|
131
|
+
function make<T>(
|
|
132
|
+
parse: (provider: ConfigProvider.ConfigProvider, pathPrefix: Path) => Effect.Effect<T, ConfigError>
|
|
165
133
|
): Config<T> {
|
|
166
134
|
const self = Object.create(Proto)
|
|
167
|
-
self.parse = parse
|
|
135
|
+
self.parse = (provider: ConfigProvider.ConfigProvider, pathPrefix: Path = []) => parse(provider, pathPrefix)
|
|
168
136
|
return self
|
|
169
137
|
}
|
|
170
138
|
|
|
@@ -176,10 +144,6 @@ export function make<T>(
|
|
|
176
144
|
* Use when you need to transform a parsed config value with a function that
|
|
177
145
|
* cannot fail.
|
|
178
146
|
*
|
|
179
|
-
* **Details**
|
|
180
|
-
*
|
|
181
|
-
* Supports both data-last and data-first calling conventions.
|
|
182
|
-
*
|
|
183
147
|
* **Example** (Uppercasing a string config)
|
|
184
148
|
*
|
|
185
149
|
* ```ts
|
|
@@ -207,10 +171,6 @@ export const map: {
|
|
|
207
171
|
* Use when you need to transform a parsed config value with a function that
|
|
208
172
|
* cannot fail.
|
|
209
173
|
*
|
|
210
|
-
* **Details**
|
|
211
|
-
*
|
|
212
|
-
* Supports both data-last and data-first calling conventions.
|
|
213
|
-
*
|
|
214
174
|
* **Example** (Uppercasing a string config)
|
|
215
175
|
*
|
|
216
176
|
* ```ts
|
|
@@ -238,10 +198,6 @@ export const map: {
|
|
|
238
198
|
* Use when you need to transform a parsed config value with a function that
|
|
239
199
|
* cannot fail.
|
|
240
200
|
*
|
|
241
|
-
* **Details**
|
|
242
|
-
*
|
|
243
|
-
* Supports both data-last and data-first calling conventions.
|
|
244
|
-
*
|
|
245
201
|
* **Example** (Uppercasing a string config)
|
|
246
202
|
*
|
|
247
203
|
* ```ts
|
|
@@ -262,7 +218,7 @@ export const map: {
|
|
|
262
218
|
*/
|
|
263
219
|
<A, B>(self: Config<A>, f: (a: A) => B): Config<B>
|
|
264
220
|
} = dual(2, <A, B>(self: Config<A>, f: (a: A) => B): Config<B> => {
|
|
265
|
-
return make((provider) => Effect.map(self.parse(provider), f))
|
|
221
|
+
return make((provider, pathPrefix) => Effect.map(self.parse(provider, pathPrefix), f))
|
|
266
222
|
})
|
|
267
223
|
|
|
268
224
|
/**
|
|
@@ -273,10 +229,6 @@ export const map: {
|
|
|
273
229
|
* Use when you need to transform a parsed config value with a function that can
|
|
274
230
|
* produce a `ConfigError` (e.g. parsing a URL, checking a range).
|
|
275
231
|
*
|
|
276
|
-
* **Details**
|
|
277
|
-
*
|
|
278
|
-
* Supports both data-last and data-first calling conventions.
|
|
279
|
-
*
|
|
280
232
|
* **Example** (Wrapping a value in an effectful transformation)
|
|
281
233
|
*
|
|
282
234
|
* ```ts
|
|
@@ -301,10 +253,6 @@ export const mapOrFail: {
|
|
|
301
253
|
* Use when you need to transform a parsed config value with a function that can
|
|
302
254
|
* produce a `ConfigError` (e.g. parsing a URL, checking a range).
|
|
303
255
|
*
|
|
304
|
-
* **Details**
|
|
305
|
-
*
|
|
306
|
-
* Supports both data-last and data-first calling conventions.
|
|
307
|
-
*
|
|
308
256
|
* **Example** (Wrapping a value in an effectful transformation)
|
|
309
257
|
*
|
|
310
258
|
* ```ts
|
|
@@ -329,10 +277,6 @@ export const mapOrFail: {
|
|
|
329
277
|
* Use when you need to transform a parsed config value with a function that can
|
|
330
278
|
* produce a `ConfigError` (e.g. parsing a URL, checking a range).
|
|
331
279
|
*
|
|
332
|
-
* **Details**
|
|
333
|
-
*
|
|
334
|
-
* Supports both data-last and data-first calling conventions.
|
|
335
|
-
*
|
|
336
280
|
* **Example** (Wrapping a value in an effectful transformation)
|
|
337
281
|
*
|
|
338
282
|
* ```ts
|
|
@@ -350,7 +294,7 @@ export const mapOrFail: {
|
|
|
350
294
|
*/
|
|
351
295
|
<A, B>(self: Config<A>, f: (a: A) => Effect.Effect<B, ConfigError>): Config<B>
|
|
352
296
|
} = dual(2, <A, B>(self: Config<A>, f: (a: A) => Effect.Effect<B, ConfigError>): Config<B> => {
|
|
353
|
-
return make((provider) => Effect.flatMap(self.parse(provider), f))
|
|
297
|
+
return make((provider, pathPrefix) => Effect.flatMap(self.parse(provider, pathPrefix), f))
|
|
354
298
|
})
|
|
355
299
|
|
|
356
300
|
/**
|
|
@@ -367,8 +311,6 @@ export const mapOrFail: {
|
|
|
367
311
|
* missing data). The fallback function receives the error and returns a new
|
|
368
312
|
* `Config`.
|
|
369
313
|
*
|
|
370
|
-
* Supports both data-last and data-first calling conventions.
|
|
371
|
-
*
|
|
372
314
|
* **Example** (Falling back to a literal)
|
|
373
315
|
*
|
|
374
316
|
* ```ts
|
|
@@ -399,8 +341,6 @@ export const orElse: {
|
|
|
399
341
|
* missing data). The fallback function receives the error and returns a new
|
|
400
342
|
* `Config`.
|
|
401
343
|
*
|
|
402
|
-
* Supports both data-last and data-first calling conventions.
|
|
403
|
-
*
|
|
404
344
|
* **Example** (Falling back to a literal)
|
|
405
345
|
*
|
|
406
346
|
* ```ts
|
|
@@ -431,8 +371,6 @@ export const orElse: {
|
|
|
431
371
|
* missing data). The fallback function receives the error and returns a new
|
|
432
372
|
* `Config`.
|
|
433
373
|
*
|
|
434
|
-
* Supports both data-last and data-first calling conventions.
|
|
435
|
-
*
|
|
436
374
|
* **Example** (Falling back to a literal)
|
|
437
375
|
*
|
|
438
376
|
* ```ts
|
|
@@ -450,7 +388,9 @@ export const orElse: {
|
|
|
450
388
|
*/
|
|
451
389
|
<A, A2>(self: Config<A>, that: (error: ConfigError) => Config<A2>): Config<A | A2>
|
|
452
390
|
} = dual(2, <A, A2>(self: Config<A>, that: (error: ConfigError) => Config<A2>): Config<A | A2> => {
|
|
453
|
-
return make((provider
|
|
391
|
+
return make((provider, pathPrefix) =>
|
|
392
|
+
Effect.catch(self.parse(provider, pathPrefix), (error) => that(error).parse(provider, pathPrefix))
|
|
393
|
+
)
|
|
454
394
|
})
|
|
455
395
|
|
|
456
396
|
/**
|
|
@@ -501,9 +441,13 @@ export function all<const Arg extends Iterable<Config<any>> | Record<string, Con
|
|
|
501
441
|
? [...arg as any]
|
|
502
442
|
: arg
|
|
503
443
|
if (Array.isArray(configs)) {
|
|
504
|
-
return make((provider
|
|
444
|
+
return make((provider, pathPrefix) =>
|
|
445
|
+
Effect.all(configs.map((config) => config.parse(provider, pathPrefix)))
|
|
446
|
+
) as any
|
|
505
447
|
} else {
|
|
506
|
-
return make((provider
|
|
448
|
+
return make((provider, pathPrefix) =>
|
|
449
|
+
Effect.all(Rec.map(configs, (config) => config.parse(provider, pathPrefix)))
|
|
450
|
+
) as any
|
|
507
451
|
}
|
|
508
452
|
}
|
|
509
453
|
|
|
@@ -543,11 +487,6 @@ function isMissingDataOnly(issue: SchemaIssue.Issue): boolean {
|
|
|
543
487
|
*
|
|
544
488
|
* Use when you need to make a config key optional with a sensible default.
|
|
545
489
|
*
|
|
546
|
-
* **Details**
|
|
547
|
-
*
|
|
548
|
-
* The default is lazily evaluated. Supports both data-last and data-first
|
|
549
|
-
* calling conventions.
|
|
550
|
-
*
|
|
551
490
|
* **Gotchas**
|
|
552
491
|
*
|
|
553
492
|
* Only applies when the error is a `SchemaError` caused exclusively by
|
|
@@ -579,11 +518,6 @@ export const withDefault: {
|
|
|
579
518
|
*
|
|
580
519
|
* Use when you need to make a config key optional with a sensible default.
|
|
581
520
|
*
|
|
582
|
-
* **Details**
|
|
583
|
-
*
|
|
584
|
-
* The default is lazily evaluated. Supports both data-last and data-first
|
|
585
|
-
* calling conventions.
|
|
586
|
-
*
|
|
587
521
|
* **Gotchas**
|
|
588
522
|
*
|
|
589
523
|
* Only applies when the error is a `SchemaError` caused exclusively by
|
|
@@ -615,11 +549,6 @@ export const withDefault: {
|
|
|
615
549
|
*
|
|
616
550
|
* Use when you need to make a config key optional with a sensible default.
|
|
617
551
|
*
|
|
618
|
-
* **Details**
|
|
619
|
-
*
|
|
620
|
-
* The default is lazily evaluated. Supports both data-last and data-first
|
|
621
|
-
* calling conventions.
|
|
622
|
-
*
|
|
623
552
|
* **Gotchas**
|
|
624
553
|
*
|
|
625
554
|
* Only applies when the error is a `SchemaError` caused exclusively by
|
|
@@ -669,7 +598,7 @@ export const withDefault: {
|
|
|
669
598
|
* Like {@link withDefault}, only missing-data errors produce `None`.
|
|
670
599
|
* Validation errors still propagate.
|
|
671
600
|
*
|
|
672
|
-
* **Example** (
|
|
601
|
+
* **Example** (Reading optional config)
|
|
673
602
|
*
|
|
674
603
|
* ```ts
|
|
675
604
|
* import { Config, ConfigProvider, Effect } from "effect"
|
|
@@ -765,10 +694,10 @@ type IsPlainObject<A> = [A] extends [Record<string, any>]
|
|
|
765
694
|
*/
|
|
766
695
|
export const unwrap = <T>(wrapped: Wrap<T>): Config<T> => {
|
|
767
696
|
if (isConfig(wrapped)) return wrapped
|
|
768
|
-
return make((provider) => {
|
|
697
|
+
return make((provider, pathPrefix) => {
|
|
769
698
|
const entries = Object.entries(wrapped)
|
|
770
699
|
const configs = entries.map(([key, config]) =>
|
|
771
|
-
unwrap(config as any).parse(provider).pipe(Effect.map((value) => [key, value] as const))
|
|
700
|
+
unwrap(config as any).parse(provider, pathPrefix).pipe(Effect.map((value) => [key, value] as const))
|
|
772
701
|
)
|
|
773
702
|
return Effect.all(configs).pipe(Effect.map(Object.fromEntries))
|
|
774
703
|
})
|
|
@@ -879,8 +808,10 @@ const recur: (
|
|
|
879
808
|
*
|
|
880
809
|
* **Details**
|
|
881
810
|
*
|
|
882
|
-
* The optional `path` sets the
|
|
883
|
-
*
|
|
811
|
+
* The optional `path` sets the local path segment(s) for the config lookup.
|
|
812
|
+
* It is appended to the logical path prefix accumulated from outer
|
|
813
|
+
* {@link nested} calls. Pass a single string for a flat key or an array for
|
|
814
|
+
* nested paths.
|
|
884
815
|
*
|
|
885
816
|
* Convenience constructors such as `string`, `number`, and `boolean` delegate
|
|
886
817
|
* to this API.
|
|
@@ -919,14 +850,14 @@ export function schema<T, E>(codec: Schema.Codec<T, E>, path?: string | ConfigPr
|
|
|
919
850
|
const codecStringTree = Schema.toCodecStringTree(codec)
|
|
920
851
|
const decodeUnknownEffect = SchemaParser.decodeUnknownEffect(codecStringTree)
|
|
921
852
|
const codecStringTreeEncoded = SchemaAST.toEncoded(codecStringTree.ast)
|
|
922
|
-
const
|
|
923
|
-
return make((provider) => {
|
|
924
|
-
const
|
|
925
|
-
return recur(codecStringTreeEncoded, provider,
|
|
853
|
+
const localPath = typeof path === "string" ? [path] : path ?? []
|
|
854
|
+
return make((provider, pathPrefix) => {
|
|
855
|
+
const fullPath = [...pathPrefix, ...localPath]
|
|
856
|
+
return recur(codecStringTreeEncoded, provider, fullPath).pipe(
|
|
926
857
|
Effect.flatMapEager((tree) =>
|
|
927
858
|
decodeUnknownEffect(tree).pipe(
|
|
928
859
|
Effect.mapErrorEager((issue) =>
|
|
929
|
-
new Schema.SchemaError(
|
|
860
|
+
new Schema.SchemaError(fullPath.length > 0 ? new SchemaIssue.Pointer(fullPath, issue) : issue)
|
|
930
861
|
)
|
|
931
862
|
)
|
|
932
863
|
),
|
|
@@ -1132,7 +1063,7 @@ export function fail(err: SourceError | Schema.SchemaError) {
|
|
|
1132
1063
|
* Use when you need a hardcoded config value, such as inside {@link orElse} or
|
|
1133
1064
|
* tests.
|
|
1134
1065
|
*
|
|
1135
|
-
* **Example** (
|
|
1066
|
+
* **Example** (Returning a constant fallback)
|
|
1136
1067
|
*
|
|
1137
1068
|
* ```ts
|
|
1138
1069
|
* import { Config } from "effect"
|
|
@@ -1672,7 +1603,7 @@ export function date(name?: string) {
|
|
|
1672
1603
|
* // { host: "localhost", port: 5432 }
|
|
1673
1604
|
* ```
|
|
1674
1605
|
*
|
|
1675
|
-
* **Example** (
|
|
1606
|
+
* **Example** (Reading env vars with a nested prefix)
|
|
1676
1607
|
*
|
|
1677
1608
|
* ```ts
|
|
1678
1609
|
* import { Config, ConfigProvider, Effect } from "effect"
|
|
@@ -1725,7 +1656,7 @@ export const nested: {
|
|
|
1725
1656
|
* // { host: "localhost", port: 5432 }
|
|
1726
1657
|
* ```
|
|
1727
1658
|
*
|
|
1728
|
-
* **Example** (
|
|
1659
|
+
* **Example** (Reading env vars with a nested prefix)
|
|
1729
1660
|
*
|
|
1730
1661
|
* ```ts
|
|
1731
1662
|
* import { Config, ConfigProvider, Effect } from "effect"
|
|
@@ -1778,7 +1709,7 @@ export const nested: {
|
|
|
1778
1709
|
* // { host: "localhost", port: 5432 }
|
|
1779
1710
|
* ```
|
|
1780
1711
|
*
|
|
1781
|
-
* **Example** (
|
|
1712
|
+
* **Example** (Reading env vars with a nested prefix)
|
|
1782
1713
|
*
|
|
1783
1714
|
* ```ts
|
|
1784
1715
|
* import { Config, ConfigProvider, Effect } from "effect"
|
|
@@ -1800,5 +1731,6 @@ export const nested: {
|
|
|
1800
1731
|
<A>(self: Config<A>, name: string): Config<A>
|
|
1801
1732
|
} = dual(
|
|
1802
1733
|
2,
|
|
1803
|
-
<A>(self: Config<A>, name: string): Config<A> =>
|
|
1734
|
+
<A>(self: Config<A>, name: string): Config<A> =>
|
|
1735
|
+
make((provider, pathPrefix) => self.parse(provider, [...pathPrefix, name]))
|
|
1804
1736
|
)
|