Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make the file tree provider the fallback in PlatformConfigProvider.layerFileTreeAdd #2479

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-chicken-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

Make the file tree provider the fallback in PlatformConfigProvider.layerFileTreeAdd
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ describe("PlatformConfigProvider", () => {

it.effect("layerFileTreeAdd", () =>
Effect.gen(function*(_) {
assert.strictEqual(Secret.value(yield* _(Config.secret("secret"))), "keepitsafe")
assert.strictEqual(Secret.value(yield* _(Config.secret("secret"))), "shh")
assert.strictEqual(yield* _(Config.integer("integer")), 123)
assert.strictEqual(yield* _(Config.string("fallback")), "value")
}).pipe(
Effect.provide(AddLive),
Effect.withConfigProvider(ConfigProvider.fromJson({
secret: "fail",
secret: "shh",
fallback: "value"
}))
))
Expand Down
6 changes: 3 additions & 3 deletions packages/platform/src/PlatformConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const fromFileTree = (options?: {
)

/**
* Add the file tree ConfigProvider to the environment, falling back to the default ConfigProvider.
* Add the file tree ConfigProvider to the environment, as a fallback to the current ConfigProvider.
*
* @since 1.0.0
* @category layers
Expand All @@ -92,14 +92,14 @@ export const layerFileTreeAdd = (options?: {
Effect.map((provider) =>
Layer.fiberRefLocallyScopedWith(DefaultServices.currentServices, (services) => {
const current = Context.get(services, ConfigProvider.ConfigProvider)
return Context.add(services, ConfigProvider.ConfigProvider, ConfigProvider.orElse(provider, () => current))
return Context.add(services, ConfigProvider.ConfigProvider, ConfigProvider.orElse(current, () => provider))
})
),
Layer.unwrapEffect
)

/**
* Add the file tree ConfigProvider to the environment, replacing the default ConfigProvider.
* Add the file tree ConfigProvider to the environment, replacing the current ConfigProvider.
*
* @since 1.0.0
* @category layers
Expand Down