Skip to content

Commit

Permalink
update effect (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Dec 11, 2023
1 parent 1f7bc62 commit 222c18a
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 36 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"@effect/language-service": "^0.0.21",
"@effect/opentelemetry": "^0.26.0",
"@effect/opentelemetry": "^0.27.0",
"@mdx-js/mdx": "^2.3.0",
"@opentelemetry/exporter-trace-otlp-http": "0.43.0",
"@opentelemetry/sdk-trace-base": "^1.17.1",
Expand All @@ -34,7 +34,7 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"autoprefixer": "^10.4.14",
"effect": "2.0.0-next.59",
"effect": "2.0.0-next.60",
"eslint": "^8.38.0",
"eslint-config-next": "^13.3.0",
"eslint-config-prettier": "^8.8.0",
Expand Down
10 changes: 5 additions & 5 deletions pages/docs/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Effect comes bundled with a straightforward default `ConfigProvider` that retrie

To make our application configurable, we need to understand three essential elements:

- **Config Description**: We describe the configuration data using an instance of `Config<A>`. If the configuration data is simple, such as a `string`, `number`, or `boolean`, we can use the built-in functions provided by the `Config` module. For more complex data types like `HostPort`, we can combine primitive configs to create a custom configuration description.
- **Config Description**: We describe the configuration data using an instance of `Config<A>`. If the configuration data is simple, such as a `string`, `number`, or `boolean`, we can use the built-in functions provided by the `Config` module. For more complex data types like [`HostPort`](#custom-configurations), we can combine primitive configs to create a custom configuration description.

- **Config Frontend**: We use `Effect.config` to load the configuration data described by a `Config<A>` instance. This function leverages the current `ConfigProvider` to retrieve the configuration.
- **Config Frontend**: We utilize the instance of `Config<A>` to load the configuration data described by the instance (a `Config` is, in itself, an effect). This process leverages the current `ConfigProvider` to retrieve the configuration.

- **Config Backend**: The `ConfigProvider` is the underlying engine that powers `Effect.config` and handles the loading of configurations. Effect comes with a default config provider as part of its default services. This default provider reads the configuration data from environment variables. If we want to use a custom config provider, we can utilize the `Effect.setConfigProvider` layer to configure the Effect runtime accordingly.
- **Config Backend**: The `ConfigProvider` serves as the underlying engine that manages the configuration loading process. Effect comes with a default config provider as part of its default services. This default provider reads the configuration data from environment variables. If we want to use a custom config provider, we can utilize the `Effect.setConfigProvider` layer to configure the Effect runtime accordingly.

## Primitives

Expand Down Expand Up @@ -117,14 +117,14 @@ If we use this customized configuration in our application:
<Tabs>
<Tab>

```ts filename="App.ts" /Effect.config(HostPort.config)/ file=<rootDir>/src/configuration/App-gen.ts
```ts filename="App.ts" /HostPort.config/ file=<rootDir>/src/configuration/App-gen.ts

```

</Tab>
<Tab>

```ts filename="App.ts" /Effect.config(HostPort.config)/ file=<rootDir>/src/configuration/App.ts
```ts filename="App.ts" /HostPort.config/ file=<rootDir>/src/configuration/App.ts

```

Expand Down
6 changes: 3 additions & 3 deletions pages/docs/observability/logging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The log message contains the following information:

- `timestamp`: The timestamp when the log message was generated.
- `level`: The log level at which the message is logged.
- `fiber`: The identifier of the [fiber](../concurrency/fibers#what-is-a-fiber) executing the program.
- `fiber`: The identifier of the [fiber](../concurrency/fibers.mdx#what-is-a-fiber) executing the program.
- `message`: The content of the log message.
- `span`: (Optional) The duration of the span in milliseconds.

Expand Down Expand Up @@ -210,13 +210,13 @@ In this approach, you create a custom runtime that incorporates the configuratio

## Loading the Log Level from Configuration

To retrieve the log level from a [configuration](../configuration) and incorporate it into your program, utilize the layer produced by `Logger.minimumLogLevel`:
To retrieve the log level from a [configuration](../configuration.mdx) and incorporate it into your program, utilize the layer produced by `Logger.minimumLogLevel`:

```ts file=<rootDir>/src/logging/load-log-level-from-configuration.ts

```

To evaluate the configured program, you can utilize `ConfigProvider.fromMap` for testing (refer to [Testing Services](../configuration#testing-services) for more details).
To evaluate the configured program, you can utilize `ConfigProvider.fromMap` for testing (refer to [Testing Services](../configuration.mdx#testing-services) for more details).

## Custom loggers

Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/configuration/App-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import * as HostPort from "./HostPort"

// $ExpectType Effect<never, ConfigError, void>
export const program = Effect.gen(function* (_) {
const hostPort = yield* _(Effect.config(HostPort.config))
const hostPort = yield* _(HostPort.config)
console.log(`Application started: ${hostPort.url}`)
})
2 changes: 1 addition & 1 deletion src/configuration/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Effect, Console } from "effect"
import * as HostPort from "./HostPort"

// $ExpectType Effect<never, ConfigError, void>
export const program = Effect.config(HostPort.config).pipe(
export const program = HostPort.config.pipe(
Effect.flatMap((hostPort) =>
Console.log(`Application started: ${hostPort.url}`)
)
Expand Down
4 changes: 2 additions & 2 deletions src/configuration/primitives-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Effect, Config } from "effect"

// $ExpectType Effect<never, ConfigError, void>
const program = Effect.gen(function* (_) {
const host = yield* _(Effect.config(Config.string("HOST")))
const port = yield* _(Effect.config(Config.string("PORT")))
const host = yield* _(Config.string("HOST"))
const port = yield* _(Config.string("PORT"))
console.log(`Application started: ${host}:${port}`)
})

Expand Down
5 changes: 1 addition & 4 deletions src/configuration/primitives-pipe.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Effect, Config, Console } from "effect"

// $ExpectType Effect<never, ConfigError, void>
const program = Effect.all([
Effect.config(Config.string("HOST")),
Effect.config(Config.number("PORT"))
]).pipe(
const program = Effect.all([Config.string("HOST"), Config.number("PORT")]).pipe(
Effect.flatMap(([host, port]) =>
Console.log(`Application started: ${host}:${port}`)
)
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/secret.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect, Config, ConfigProvider, Layer, Console, Secret } from "effect"

const program = Effect.config(Config.secret("API_KEY")).pipe(
const program = Config.secret("API_KEY").pipe(
Effect.tap((secret) => Console.log(`console.log: ${secret}`)),
Effect.tap((secret) => Console.log(`Secret.value: ${Secret.value(secret)}`))
)
Expand Down
6 changes: 2 additions & 4 deletions src/configuration/withDefault-gen.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Effect, Config } from "effect"

const program = Effect.gen(function* (_) {
const host = yield* _(Effect.config(Config.string("HOST")))
const port = yield* _(
Effect.config(Config.withDefault(Config.number("PORT"), 8080))
)
const host = yield* _(Config.string("HOST"))
const port = yield* _(Config.withDefault(Config.number("PORT"), 8080))
console.log(`Application started: ${host}:${port}`)
})

Expand Down
4 changes: 2 additions & 2 deletions src/configuration/withDefault-pipe.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Effect, Config, Console } from "effect"

const program = Effect.all([
Effect.config(Config.string("HOST")),
Effect.config(Config.withDefault(Config.number("PORT"), 8080))
Config.string("HOST"),
Config.withDefault(Config.number("PORT"), 8080)
]).pipe(
Effect.flatMap(([host, port]) =>
Console.log(`Application started: ${host}:${port}`)
Expand Down
2 changes: 1 addition & 1 deletion src/logging/load-log-level-from-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const program = Effect.gen(function* (_) {
})

// Load the log level from the configuration as a layer
const LogLevelLive = Effect.config(Config.logLevel("LOG_LEVEL")).pipe(
const LogLevelLive = Config.logLevel("LOG_LEVEL").pipe(
Effect.map((level) => Logger.minimumLogLevel(level)),
Layer.unwrapEffect
)
Expand Down

0 comments on commit 222c18a

Please sign in to comment.