effect 4.0.0-beta.82 → 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/httpapi/HttpApiSchema.d.ts +39 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- 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/httpapi/HttpApiSchema.ts +18 -6
- 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/ConfigProvider.ts
CHANGED
|
@@ -176,7 +176,7 @@ export function makeArray(length: number, value?: string): Node {
|
|
|
176
176
|
* **Gotchas**
|
|
177
177
|
*
|
|
178
178
|
* Do not use `SourceError` for "key not found". That case is represented by
|
|
179
|
-
* returning `undefined` from `load
|
|
179
|
+
* returning `undefined` from `load`.
|
|
180
180
|
*
|
|
181
181
|
* **Example** (Failing with a SourceError)
|
|
182
182
|
*
|
|
@@ -190,8 +190,8 @@ export function makeArray(length: number, value?: string): Node {
|
|
|
190
190
|
* )
|
|
191
191
|
* ```
|
|
192
192
|
*
|
|
193
|
-
* @see {@link ConfigProvider} – the interface whose `load
|
|
194
|
-
*
|
|
193
|
+
* @see {@link ConfigProvider} – the interface whose `load` may fail with this
|
|
194
|
+
* error
|
|
195
195
|
*
|
|
196
196
|
* @category models
|
|
197
197
|
* @since 4.0.0
|
|
@@ -234,13 +234,10 @@ export type Path = ReadonlyArray<string | number>
|
|
|
234
234
|
*
|
|
235
235
|
* **Details**
|
|
236
236
|
*
|
|
237
|
-
* `load(path)`
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* {@link mapInput} and {@link nested}. All methods return
|
|
242
|
-
* `Effect<Node | undefined, SourceError>`: `undefined` means "not found" and
|
|
243
|
-
* `SourceError` means the source itself failed.
|
|
237
|
+
* `load(path)` is the semantic lookup operation used by the `Config` module.
|
|
238
|
+
* It applies provider transformations and composition before consulting the
|
|
239
|
+
* underlying source. `undefined` means "not found" and `SourceError` means the
|
|
240
|
+
* source itself failed.
|
|
244
241
|
*
|
|
245
242
|
* @see {@link make} – construct a provider from a lookup function
|
|
246
243
|
* @see {@link orElse} – compose providers with fallback
|
|
@@ -260,33 +257,8 @@ export interface ConfigProvider extends Pipeable {
|
|
|
260
257
|
*/
|
|
261
258
|
readonly load: (path: Path) => Effect.Effect<Node | undefined, SourceError>
|
|
262
259
|
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
*
|
|
266
|
-
* **When to use**
|
|
267
|
-
*
|
|
268
|
-
* Use to read from the backing source without applying this provider's path
|
|
269
|
-
* transformations.
|
|
270
|
-
*/
|
|
271
|
-
readonly get: (path: Path) => Effect.Effect<Node | undefined, SourceError>
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Function to map the input path.
|
|
275
|
-
*
|
|
276
|
-
* **When to use**
|
|
277
|
-
*
|
|
278
|
-
* Use to store the path transformation applied before raw provider lookup.
|
|
279
|
-
*/
|
|
280
|
-
readonly mapInput: ((path: Path) => Path) | undefined
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Prefix to add to the input path.
|
|
284
|
-
*
|
|
285
|
-
* **When to use**
|
|
286
|
-
*
|
|
287
|
-
* Use to store the path prefix applied before raw provider lookup.
|
|
288
|
-
*/
|
|
289
|
-
readonly prefix: Path | undefined
|
|
260
|
+
/** @internal */
|
|
261
|
+
readonly state: ProviderState
|
|
290
262
|
}
|
|
291
263
|
|
|
292
264
|
/**
|
|
@@ -335,6 +307,57 @@ const Proto = {
|
|
|
335
307
|
}
|
|
336
308
|
}
|
|
337
309
|
|
|
310
|
+
type SourceState = {
|
|
311
|
+
readonly _tag: "Source"
|
|
312
|
+
readonly get: (path: Path) => Effect.Effect<Node | undefined, SourceError>
|
|
313
|
+
readonly transform: (path: Path) => Path
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
type OrElseState = {
|
|
317
|
+
readonly _tag: "OrElse"
|
|
318
|
+
readonly first: ConfigProvider
|
|
319
|
+
readonly second: ConfigProvider
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
type ProviderState = SourceState | OrElseState
|
|
323
|
+
|
|
324
|
+
const identityPath = (path: Path): Path => path
|
|
325
|
+
|
|
326
|
+
function makeProvider(
|
|
327
|
+
state: ProviderState,
|
|
328
|
+
load: (path: Path) => Effect.Effect<Node | undefined, SourceError>
|
|
329
|
+
): ConfigProvider {
|
|
330
|
+
const self = Object.create(Proto)
|
|
331
|
+
self.state = state
|
|
332
|
+
self.load = load
|
|
333
|
+
return self
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function makeSource(
|
|
337
|
+
get: (path: Path) => Effect.Effect<Node | undefined, SourceError>,
|
|
338
|
+
transform: (path: Path) => Path
|
|
339
|
+
): ConfigProvider {
|
|
340
|
+
const state: SourceState = {
|
|
341
|
+
_tag: "Source",
|
|
342
|
+
get,
|
|
343
|
+
transform
|
|
344
|
+
}
|
|
345
|
+
return makeProvider(state, (path) => state.get(state.transform(path)))
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function makeOrElse(first: ConfigProvider, second: ConfigProvider): ConfigProvider {
|
|
349
|
+
const state: OrElseState = {
|
|
350
|
+
_tag: "OrElse",
|
|
351
|
+
first,
|
|
352
|
+
second
|
|
353
|
+
}
|
|
354
|
+
return makeProvider(state, (path) =>
|
|
355
|
+
Effect.flatMap(
|
|
356
|
+
state.first.load(path),
|
|
357
|
+
(node) => node ? Effect.succeed(node) : state.second.load(path)
|
|
358
|
+
))
|
|
359
|
+
}
|
|
360
|
+
|
|
338
361
|
/**
|
|
339
362
|
* Creates a `ConfigProvider` from a raw lookup function.
|
|
340
363
|
*
|
|
@@ -349,11 +372,7 @@ const Proto = {
|
|
|
349
372
|
* `Effect<Node | undefined, SourceError>`. Return `undefined` when the path
|
|
350
373
|
* does not exist; fail with `SourceError` only for actual I/O errors.
|
|
351
374
|
*
|
|
352
|
-
*
|
|
353
|
-
* resulting `load` method so that combinators like {@link mapInput} and
|
|
354
|
-
* {@link nested} can compose without wrapping `get`.
|
|
355
|
-
*
|
|
356
|
-
* **Example** (A simple in-memory provider)
|
|
375
|
+
* **Example** (Creating a simple in-memory provider)
|
|
357
376
|
*
|
|
358
377
|
* ```ts
|
|
359
378
|
* import { ConfigProvider, Effect } from "effect"
|
|
@@ -378,21 +397,8 @@ const Proto = {
|
|
|
378
397
|
* @category constructors
|
|
379
398
|
* @since 2.0.0
|
|
380
399
|
*/
|
|
381
|
-
export function make(
|
|
382
|
-
|
|
383
|
-
mapInput?: (path: Path) => Path,
|
|
384
|
-
prefix?: Path
|
|
385
|
-
): ConfigProvider {
|
|
386
|
-
const self = Object.create(Proto)
|
|
387
|
-
self.get = get
|
|
388
|
-
self.mapInput = mapInput
|
|
389
|
-
self.prefix = prefix
|
|
390
|
-
self.load = (path: Path) => {
|
|
391
|
-
if (mapInput) path = mapInput(path)
|
|
392
|
-
if (prefix) path = [...prefix, ...path]
|
|
393
|
-
return get(path)
|
|
394
|
-
}
|
|
395
|
-
return self
|
|
400
|
+
export function make(get: (path: Path) => Effect.Effect<Node | undefined, SourceError>): ConfigProvider {
|
|
401
|
+
return makeSource(get, identityPath)
|
|
396
402
|
}
|
|
397
403
|
|
|
398
404
|
/**
|
|
@@ -406,7 +412,9 @@ export function make(
|
|
|
406
412
|
*
|
|
407
413
|
* **Details**
|
|
408
414
|
*
|
|
409
|
-
*
|
|
415
|
+
* Each provider keeps its own path transformations. If the combined provider
|
|
416
|
+
* is later transformed with {@link mapInput} or {@link nested}, the
|
|
417
|
+
* transformation is applied to both sides.
|
|
410
418
|
*
|
|
411
419
|
* **Gotchas**
|
|
412
420
|
*
|
|
@@ -443,7 +451,9 @@ export const orElse: {
|
|
|
443
451
|
*
|
|
444
452
|
* **Details**
|
|
445
453
|
*
|
|
446
|
-
*
|
|
454
|
+
* Each provider keeps its own path transformations. If the combined provider
|
|
455
|
+
* is later transformed with {@link mapInput} or {@link nested}, the
|
|
456
|
+
* transformation is applied to both sides.
|
|
447
457
|
*
|
|
448
458
|
* **Gotchas**
|
|
449
459
|
*
|
|
@@ -480,7 +490,9 @@ export const orElse: {
|
|
|
480
490
|
*
|
|
481
491
|
* **Details**
|
|
482
492
|
*
|
|
483
|
-
*
|
|
493
|
+
* Each provider keeps its own path transformations. If the combined provider
|
|
494
|
+
* is later transformed with {@link mapInput} or {@link nested}, the
|
|
495
|
+
* transformation is applied to both sides.
|
|
484
496
|
*
|
|
485
497
|
* **Gotchas**
|
|
486
498
|
*
|
|
@@ -508,8 +520,7 @@ export const orElse: {
|
|
|
508
520
|
(self: ConfigProvider, that: ConfigProvider): ConfigProvider
|
|
509
521
|
} = dual(
|
|
510
522
|
2,
|
|
511
|
-
(self: ConfigProvider, that: ConfigProvider): ConfigProvider =>
|
|
512
|
-
make((path) => Effect.flatMap(self.get(path), (node) => node ? Effect.succeed(node) : that.get(path)))
|
|
523
|
+
(self: ConfigProvider, that: ConfigProvider): ConfigProvider => makeOrElse(self, that)
|
|
513
524
|
)
|
|
514
525
|
|
|
515
526
|
/**
|
|
@@ -522,10 +533,11 @@ export const orElse: {
|
|
|
522
533
|
*
|
|
523
534
|
* **Details**
|
|
524
535
|
*
|
|
525
|
-
* The function `f` receives the
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
536
|
+
* The function `f` receives the whole path produced by earlier provider
|
|
537
|
+
* transformations and must return a new path. Lookup path transformations
|
|
538
|
+
* compose in application order: the existing transformation runs first, then
|
|
539
|
+
* `f` runs. For providers composed with {@link orElse}, the transformation is
|
|
540
|
+
* applied to each operand.
|
|
529
541
|
*
|
|
530
542
|
* **Example** (Uppercasing path segments)
|
|
531
543
|
*
|
|
@@ -560,10 +572,11 @@ export const mapInput: {
|
|
|
560
572
|
*
|
|
561
573
|
* **Details**
|
|
562
574
|
*
|
|
563
|
-
* The function `f` receives the
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
575
|
+
* The function `f` receives the whole path produced by earlier provider
|
|
576
|
+
* transformations and must return a new path. Lookup path transformations
|
|
577
|
+
* compose in application order: the existing transformation runs first, then
|
|
578
|
+
* `f` runs. For providers composed with {@link orElse}, the transformation is
|
|
579
|
+
* applied to each operand.
|
|
567
580
|
*
|
|
568
581
|
* **Example** (Uppercasing path segments)
|
|
569
582
|
*
|
|
@@ -598,10 +611,11 @@ export const mapInput: {
|
|
|
598
611
|
*
|
|
599
612
|
* **Details**
|
|
600
613
|
*
|
|
601
|
-
* The function `f` receives the
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
614
|
+
* The function `f` receives the whole path produced by earlier provider
|
|
615
|
+
* transformations and must return a new path. Lookup path transformations
|
|
616
|
+
* compose in application order: the existing transformation runs first, then
|
|
617
|
+
* `f` runs. For providers composed with {@link orElse}, the transformation is
|
|
618
|
+
* applied to each operand.
|
|
605
619
|
*
|
|
606
620
|
* **Example** (Uppercasing path segments)
|
|
607
621
|
*
|
|
@@ -629,7 +643,13 @@ export const mapInput: {
|
|
|
629
643
|
} = dual(
|
|
630
644
|
2,
|
|
631
645
|
(self: ConfigProvider, f: (path: Path) => Path): ConfigProvider => {
|
|
632
|
-
|
|
646
|
+
const state = self.state
|
|
647
|
+
switch (state._tag) {
|
|
648
|
+
case "Source":
|
|
649
|
+
return makeSource(state.get, flow(state.transform, f))
|
|
650
|
+
case "OrElse":
|
|
651
|
+
return makeOrElse(mapInput(state.first, f), mapInput(state.second, f))
|
|
652
|
+
}
|
|
633
653
|
}
|
|
634
654
|
)
|
|
635
655
|
|
|
@@ -678,14 +698,16 @@ export const constantCase: (self: ConfigProvider) => ConfigProvider = mapInput((
|
|
|
678
698
|
*
|
|
679
699
|
* **Details**
|
|
680
700
|
*
|
|
681
|
-
* Accepts a single string or a full `Path` array.
|
|
682
|
-
*
|
|
701
|
+
* Accepts a single string or a full `Path` array. For providers composed with
|
|
702
|
+
* {@link orElse}, the prefix is applied to each operand. Supports both
|
|
703
|
+
* data-last and data-first calling conventions.
|
|
683
704
|
*
|
|
684
705
|
* **Gotchas**
|
|
685
706
|
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
707
|
+
* Ordering matters when composing with {@link mapInput} or
|
|
708
|
+
* {@link constantCase}. Later provider transformations run after earlier ones:
|
|
709
|
+
* a later `nested` becomes the outer prefix, and a later `mapInput` sees the
|
|
710
|
+
* whole path produced by previous transformations.
|
|
689
711
|
*
|
|
690
712
|
* **Example** (Nesting under a prefix)
|
|
691
713
|
*
|
|
@@ -717,14 +739,16 @@ export const nested: {
|
|
|
717
739
|
*
|
|
718
740
|
* **Details**
|
|
719
741
|
*
|
|
720
|
-
* Accepts a single string or a full `Path` array.
|
|
721
|
-
*
|
|
742
|
+
* Accepts a single string or a full `Path` array. For providers composed with
|
|
743
|
+
* {@link orElse}, the prefix is applied to each operand. Supports both
|
|
744
|
+
* data-last and data-first calling conventions.
|
|
722
745
|
*
|
|
723
746
|
* **Gotchas**
|
|
724
747
|
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
748
|
+
* Ordering matters when composing with {@link mapInput} or
|
|
749
|
+
* {@link constantCase}. Later provider transformations run after earlier ones:
|
|
750
|
+
* a later `nested` becomes the outer prefix, and a later `mapInput` sees the
|
|
751
|
+
* whole path produced by previous transformations.
|
|
728
752
|
*
|
|
729
753
|
* **Example** (Nesting under a prefix)
|
|
730
754
|
*
|
|
@@ -756,14 +780,16 @@ export const nested: {
|
|
|
756
780
|
*
|
|
757
781
|
* **Details**
|
|
758
782
|
*
|
|
759
|
-
* Accepts a single string or a full `Path` array.
|
|
760
|
-
*
|
|
783
|
+
* Accepts a single string or a full `Path` array. For providers composed with
|
|
784
|
+
* {@link orElse}, the prefix is applied to each operand. Supports both
|
|
785
|
+
* data-last and data-first calling conventions.
|
|
761
786
|
*
|
|
762
787
|
* **Gotchas**
|
|
763
788
|
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
789
|
+
* Ordering matters when composing with {@link mapInput} or
|
|
790
|
+
* {@link constantCase}. Later provider transformations run after earlier ones:
|
|
791
|
+
* a later `nested` becomes the outer prefix, and a later `mapInput` sees the
|
|
792
|
+
* whole path produced by previous transformations.
|
|
767
793
|
*
|
|
768
794
|
* **Example** (Nesting under a prefix)
|
|
769
795
|
*
|
|
@@ -788,7 +814,13 @@ export const nested: {
|
|
|
788
814
|
2,
|
|
789
815
|
(self: ConfigProvider, prefix: string | Path): ConfigProvider => {
|
|
790
816
|
const path = typeof prefix === "string" ? [prefix] : prefix
|
|
791
|
-
|
|
817
|
+
const state = self.state
|
|
818
|
+
switch (state._tag) {
|
|
819
|
+
case "Source":
|
|
820
|
+
return makeSource(state.get, flow(state.transform, (input) => [...path, ...input]))
|
|
821
|
+
case "OrElse":
|
|
822
|
+
return makeOrElse(nested(state.first, path), nested(state.second, path))
|
|
823
|
+
}
|
|
792
824
|
}
|
|
793
825
|
)
|
|
794
826
|
|
|
@@ -805,7 +837,7 @@ export const nested: {
|
|
|
805
837
|
* Accepts either a plain `ConfigProvider` or an `Effect` that produces one.
|
|
806
838
|
* When given an Effect, it is evaluated once when the layer is built.
|
|
807
839
|
*
|
|
808
|
-
* **Example** (
|
|
840
|
+
* **Example** (Reading config from a JSON object)
|
|
809
841
|
*
|
|
810
842
|
* ```ts
|
|
811
843
|
* import { Config, ConfigProvider, Effect, Layer } from "effect"
|
|
@@ -1286,8 +1318,9 @@ export const fromDotEnv: (options?: {
|
|
|
1286
1318
|
*
|
|
1287
1319
|
* Resolution tries a regular file first and returns a `Value` node with
|
|
1288
1320
|
* trimmed file contents. If the file read fails, it tries a directory and
|
|
1289
|
-
* returns a `Record` node with immediate child names as keys. If both fail
|
|
1290
|
-
* returns `
|
|
1321
|
+
* returns a `Record` node with immediate child names as keys. If both fail with
|
|
1322
|
+
* `NotFound`, it returns `undefined`. Other platform failures return
|
|
1323
|
+
* `SourceError`.
|
|
1291
1324
|
*
|
|
1292
1325
|
* Requires `Path` and `FileSystem` in the Effect context. Defaults to root
|
|
1293
1326
|
* path `/`; override with `{ rootPath: "/etc/config" }`.
|
|
@@ -1332,15 +1365,19 @@ export const fromDir: (options?: {
|
|
|
1332
1365
|
|
|
1333
1366
|
// If not a file, try reading as a *directory*
|
|
1334
1367
|
const asDirectory = fs.readDirectory(fullPath).pipe(
|
|
1335
|
-
Effect.map((entries
|
|
1336
|
-
// Support both string paths and DirEntry-like objects
|
|
1337
|
-
const keys = entries.map((e) => typeof e === "string" ? platformPath.basename(e) : format(e?.name ?? ""))
|
|
1338
|
-
return makeRecord(new Set(keys))
|
|
1339
|
-
})
|
|
1368
|
+
Effect.map((entries) => makeRecord(new Set(entries.map((entry) => platformPath.basename(entry)))))
|
|
1340
1369
|
)
|
|
1341
1370
|
|
|
1342
1371
|
return asFile.pipe(
|
|
1343
|
-
Effect.catch(() =>
|
|
1372
|
+
Effect.catch((fileCause) =>
|
|
1373
|
+
asDirectory.pipe(
|
|
1374
|
+
Effect.catch((dirCause) =>
|
|
1375
|
+
isNotFound(fileCause) && isNotFound(dirCause)
|
|
1376
|
+
? Effect.succeed(undefined)
|
|
1377
|
+
: Effect.fail(isNotFound(fileCause) ? dirCause : fileCause)
|
|
1378
|
+
)
|
|
1379
|
+
)
|
|
1380
|
+
),
|
|
1344
1381
|
Effect.mapError((cause: PlatformError) =>
|
|
1345
1382
|
new SourceError({
|
|
1346
1383
|
message: `Failed to read file at ${platformPath.join(rootPath, ...path.map(String))}`,
|
|
@@ -1350,3 +1387,5 @@ export const fromDir: (options?: {
|
|
|
1350
1387
|
)
|
|
1351
1388
|
})
|
|
1352
1389
|
})
|
|
1390
|
+
|
|
1391
|
+
const isNotFound = (cause: PlatformError) => cause.reason._tag === "NotFound"
|
package/src/Console.ts
CHANGED
|
@@ -78,7 +78,7 @@ export const Console: Context.Reference<Console> = effect.ConsoleRef
|
|
|
78
78
|
/**
|
|
79
79
|
* Creates an Effect that provides access to the current console service and lets you perform operations with it within an Effect context.
|
|
80
80
|
*
|
|
81
|
-
* **Example** (
|
|
81
|
+
* **Example** (Accessing the current console service)
|
|
82
82
|
*
|
|
83
83
|
* ```ts
|
|
84
84
|
* import { Console, Effect } from "effect"
|
package/src/Data.ts
CHANGED
|
@@ -195,7 +195,7 @@ export declare namespace TaggedEnum {
|
|
|
195
195
|
* `this["A"]`, `this["B"]`, etc. as placeholders for the generics. The
|
|
196
196
|
* `Count` parameter declares how many generics are used (up to 4).
|
|
197
197
|
*
|
|
198
|
-
* **Example** (
|
|
198
|
+
* **Example** (Defining a generic tagged enum)
|
|
199
199
|
*
|
|
200
200
|
* ```ts
|
|
201
201
|
* import { Data } from "effect"
|
|
@@ -325,7 +325,7 @@ export declare namespace TaggedEnum {
|
|
|
325
325
|
*
|
|
326
326
|
* Use to select one full tagged-union variant by its `_tag` value.
|
|
327
327
|
*
|
|
328
|
-
* **Example** (
|
|
328
|
+
* **Example** (Extracting a variant type)
|
|
329
329
|
*
|
|
330
330
|
* ```ts
|
|
331
331
|
* import type { Data } from "effect"
|
|
@@ -537,7 +537,7 @@ export declare namespace TaggedEnum {
|
|
|
537
537
|
* on the tag being globally unique and the value being produced by your
|
|
538
538
|
* constructors. For untrusted input, validate with the `Schema` module first.
|
|
539
539
|
*
|
|
540
|
-
* **Example** (
|
|
540
|
+
* **Example** (Creating and matching tagged enum values)
|
|
541
541
|
*
|
|
542
542
|
* ```ts
|
|
543
543
|
* import { Data } from "effect"
|
|
@@ -562,7 +562,7 @@ export declare namespace TaggedEnum {
|
|
|
562
562
|
* console.log(msg) // "/missing not found"
|
|
563
563
|
* ```
|
|
564
564
|
*
|
|
565
|
-
* **Example** (
|
|
565
|
+
* **Example** (Defining a generic tagged enum)
|
|
566
566
|
*
|
|
567
567
|
* ```ts
|
|
568
568
|
* import { Data } from "effect"
|
|
@@ -610,7 +610,7 @@ export const taggedEnum: {
|
|
|
610
610
|
* on the tag being globally unique and the value being produced by your
|
|
611
611
|
* constructors. For untrusted input, validate with the `Schema` module first.
|
|
612
612
|
*
|
|
613
|
-
* **Example** (
|
|
613
|
+
* **Example** (Creating and matching tagged enum values)
|
|
614
614
|
*
|
|
615
615
|
* ```ts
|
|
616
616
|
* import { Data } from "effect"
|
|
@@ -635,7 +635,7 @@ export const taggedEnum: {
|
|
|
635
635
|
* console.log(msg) // "/missing not found"
|
|
636
636
|
* ```
|
|
637
637
|
*
|
|
638
|
-
* **Example** (
|
|
638
|
+
* **Example** (Defining a generic tagged enum)
|
|
639
639
|
*
|
|
640
640
|
* ```ts
|
|
641
641
|
* import { Data } from "effect"
|
|
@@ -694,7 +694,7 @@ export const taggedEnum: {
|
|
|
694
694
|
* on the tag being globally unique and the value being produced by your
|
|
695
695
|
* constructors. For untrusted input, validate with the `Schema` module first.
|
|
696
696
|
*
|
|
697
|
-
* **Example** (
|
|
697
|
+
* **Example** (Creating and matching tagged enum values)
|
|
698
698
|
*
|
|
699
699
|
* ```ts
|
|
700
700
|
* import { Data } from "effect"
|
|
@@ -719,7 +719,7 @@ export const taggedEnum: {
|
|
|
719
719
|
* console.log(msg) // "/missing not found"
|
|
720
720
|
* ```
|
|
721
721
|
*
|
|
722
|
-
* **Example** (
|
|
722
|
+
* **Example** (Defining a generic tagged enum)
|
|
723
723
|
*
|
|
724
724
|
* ```ts
|
|
725
725
|
* import { Data } from "effect"
|
|
@@ -778,7 +778,7 @@ export const taggedEnum: {
|
|
|
778
778
|
* on the tag being globally unique and the value being produced by your
|
|
779
779
|
* constructors. For untrusted input, validate with the `Schema` module first.
|
|
780
780
|
*
|
|
781
|
-
* **Example** (
|
|
781
|
+
* **Example** (Creating and matching tagged enum values)
|
|
782
782
|
*
|
|
783
783
|
* ```ts
|
|
784
784
|
* import { Data } from "effect"
|
|
@@ -803,7 +803,7 @@ export const taggedEnum: {
|
|
|
803
803
|
* console.log(msg) // "/missing not found"
|
|
804
804
|
* ```
|
|
805
805
|
*
|
|
806
|
-
* **Example** (
|
|
806
|
+
* **Example** (Defining a generic tagged enum)
|
|
807
807
|
*
|
|
808
808
|
* ```ts
|
|
809
809
|
* import { Data } from "effect"
|
|
@@ -862,7 +862,7 @@ export const taggedEnum: {
|
|
|
862
862
|
* on the tag being globally unique and the value being produced by your
|
|
863
863
|
* constructors. For untrusted input, validate with the `Schema` module first.
|
|
864
864
|
*
|
|
865
|
-
* **Example** (
|
|
865
|
+
* **Example** (Creating and matching tagged enum values)
|
|
866
866
|
*
|
|
867
867
|
* ```ts
|
|
868
868
|
* import { Data } from "effect"
|
|
@@ -887,7 +887,7 @@ export const taggedEnum: {
|
|
|
887
887
|
* console.log(msg) // "/missing not found"
|
|
888
888
|
* ```
|
|
889
889
|
*
|
|
890
|
-
* **Example** (
|
|
890
|
+
* **Example** (Defining a generic tagged enum)
|
|
891
891
|
*
|
|
892
892
|
* ```ts
|
|
893
893
|
* import { Data } from "effect"
|
|
@@ -946,7 +946,7 @@ export const taggedEnum: {
|
|
|
946
946
|
* on the tag being globally unique and the value being produced by your
|
|
947
947
|
* constructors. For untrusted input, validate with the `Schema` module first.
|
|
948
948
|
*
|
|
949
|
-
* **Example** (
|
|
949
|
+
* **Example** (Creating and matching tagged enum values)
|
|
950
950
|
*
|
|
951
951
|
* ```ts
|
|
952
952
|
* import { Data } from "effect"
|
|
@@ -971,7 +971,7 @@ export const taggedEnum: {
|
|
|
971
971
|
* console.log(msg) // "/missing not found"
|
|
972
972
|
* ```
|
|
973
973
|
*
|
|
974
|
-
* **Example** (
|
|
974
|
+
* **Example** (Defining a generic tagged enum)
|
|
975
975
|
*
|
|
976
976
|
* ```ts
|
|
977
977
|
* import { Data } from "effect"
|
|
@@ -1098,7 +1098,7 @@ export const Error: new<A extends Record<string, any> = {}>(
|
|
|
1098
1098
|
* The `_tag` is excluded from the constructor argument. Yielding an instance
|
|
1099
1099
|
* inside `Effect.gen` fails the effect with this error.
|
|
1100
1100
|
*
|
|
1101
|
-
* **Example** (
|
|
1101
|
+
* **Example** (Recovering by tag)
|
|
1102
1102
|
*
|
|
1103
1103
|
* ```ts
|
|
1104
1104
|
* import { Data, Effect } from "effect"
|
package/src/DateTime.ts
CHANGED
|
@@ -3177,7 +3177,7 @@ export const mapEpochMillis: {
|
|
|
3177
3177
|
* `DateTime.Zoned` values. Use `DateTime.withDateUtc` when the callback should
|
|
3178
3178
|
* receive the UTC instant.
|
|
3179
3179
|
*
|
|
3180
|
-
* **Example** (
|
|
3180
|
+
* **Example** (Applying time zone adjusted Dates)
|
|
3181
3181
|
*
|
|
3182
3182
|
* ```ts
|
|
3183
3183
|
* import { DateTime } from "effect"
|
|
@@ -3202,7 +3202,7 @@ export const withDate: {
|
|
|
3202
3202
|
* `DateTime.Zoned` values. Use `DateTime.withDateUtc` when the callback should
|
|
3203
3203
|
* receive the UTC instant.
|
|
3204
3204
|
*
|
|
3205
|
-
* **Example** (
|
|
3205
|
+
* **Example** (Applying time zone adjusted Dates)
|
|
3206
3206
|
*
|
|
3207
3207
|
* ```ts
|
|
3208
3208
|
* import { DateTime } from "effect"
|
|
@@ -3227,7 +3227,7 @@ export const withDate: {
|
|
|
3227
3227
|
* `DateTime.Zoned` values. Use `DateTime.withDateUtc` when the callback should
|
|
3228
3228
|
* receive the UTC instant.
|
|
3229
3229
|
*
|
|
3230
|
-
* **Example** (
|
|
3230
|
+
* **Example** (Applying time zone adjusted Dates)
|
|
3231
3231
|
*
|
|
3232
3232
|
* ```ts
|
|
3233
3233
|
* import { DateTime } from "effect"
|
|
@@ -3253,7 +3253,7 @@ export const withDate: {
|
|
|
3253
3253
|
* This ignores any associated time zone. Use `DateTime.withDate` when the
|
|
3254
3254
|
* callback should receive the time-zone-adjusted wall-clock date.
|
|
3255
3255
|
*
|
|
3256
|
-
* **Example** (
|
|
3256
|
+
* **Example** (Applying UTC Dates)
|
|
3257
3257
|
*
|
|
3258
3258
|
* ```ts
|
|
3259
3259
|
* import { DateTime } from "effect"
|
|
@@ -3277,7 +3277,7 @@ export const withDateUtc: {
|
|
|
3277
3277
|
* This ignores any associated time zone. Use `DateTime.withDate` when the
|
|
3278
3278
|
* callback should receive the time-zone-adjusted wall-clock date.
|
|
3279
3279
|
*
|
|
3280
|
-
* **Example** (
|
|
3280
|
+
* **Example** (Applying UTC Dates)
|
|
3281
3281
|
*
|
|
3282
3282
|
* ```ts
|
|
3283
3283
|
* import { DateTime } from "effect"
|
|
@@ -3301,7 +3301,7 @@ export const withDateUtc: {
|
|
|
3301
3301
|
* This ignores any associated time zone. Use `DateTime.withDate` when the
|
|
3302
3302
|
* callback should receive the time-zone-adjusted wall-clock date.
|
|
3303
3303
|
*
|
|
3304
|
-
* **Example** (
|
|
3304
|
+
* **Example** (Applying UTC Dates)
|
|
3305
3305
|
*
|
|
3306
3306
|
* ```ts
|
|
3307
3307
|
* import { DateTime } from "effect"
|
package/src/Duration.ts
CHANGED
|
@@ -573,7 +573,7 @@ export const negate = (self: Duration): Duration => {
|
|
|
573
573
|
/**
|
|
574
574
|
* A Duration representing zero time.
|
|
575
575
|
*
|
|
576
|
-
* **Example** (
|
|
576
|
+
* **Example** (Referencing the zero duration)
|
|
577
577
|
*
|
|
578
578
|
* ```ts
|
|
579
579
|
* import { Duration } from "effect"
|
|
@@ -589,7 +589,7 @@ export const zero: Duration = make(0)
|
|
|
589
589
|
/**
|
|
590
590
|
* A Duration representing infinite time.
|
|
591
591
|
*
|
|
592
|
-
* **Example** (
|
|
592
|
+
* **Example** (Referencing infinite duration)
|
|
593
593
|
*
|
|
594
594
|
* ```ts
|
|
595
595
|
* import { Duration } from "effect"
|
|
@@ -605,7 +605,7 @@ export const infinity: Duration = make(Infinity)
|
|
|
605
605
|
/**
|
|
606
606
|
* A Duration representing negative infinite time.
|
|
607
607
|
*
|
|
608
|
-
* **Example** (
|
|
608
|
+
* **Example** (Referencing negative infinite duration)
|
|
609
609
|
*
|
|
610
610
|
* ```ts
|
|
611
611
|
* import { Duration } from "effect"
|