@effected/config-file 0.2.0 → 0.2.1
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/README.md +20 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -98,6 +98,25 @@ export const SettingsLive = ConfigFile.layer(SettingsConfig, {
|
|
|
98
98
|
});
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
## Reading one known path
|
|
102
|
+
|
|
103
|
+
Not every caller has a config file — some just have one path a caller already vouched for, such as a CLI's `--config` flag. `ConfigFile.read` is the one-shot escape from the service, the layer and the resolver chain: read, decode and validate a single path, with the schema and codec named per call rather than bound to a service class:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { ConfigFile, JsonCodec } from "@effected/config-file";
|
|
107
|
+
import { NodeFileSystem } from "@effect/platform-node";
|
|
108
|
+
import { Effect, Schema } from "effect";
|
|
109
|
+
|
|
110
|
+
class MyConfig extends Schema.Class<MyConfig>("MyConfig")({ port: Schema.Number }) {}
|
|
111
|
+
|
|
112
|
+
const program = ConfigFile.read("./app.config.json", { schema: MyConfig, codec: JsonCodec });
|
|
113
|
+
|
|
114
|
+
Effect.runPromise(program.pipe(Effect.provide(NodeFileSystem.layer))).then(console.log);
|
|
115
|
+
// MyConfig { port: 3000 }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
It is deliberately read-only and discovery-free — no resolver chain, no `save`/`update`. Reach for `ConfigFile.layer` the moment either is wanted.
|
|
119
|
+
|
|
101
120
|
## Errors
|
|
102
121
|
|
|
103
122
|
Every failure is a tagged error you route on with `Effect.catchTag`. The tags exist so that recovery can differ:
|
|
@@ -166,6 +185,7 @@ export const secret = EncryptedCodec(migrating, EncryptedCodecKey.fromPassphrase
|
|
|
166
185
|
## Features
|
|
167
186
|
|
|
168
187
|
- `ConfigFile.Service` / `ConfigFile.layer` / `ConfigFile.testLayer` — a per-schema service class and its layers. `testLayer` seeds files into a temp directory and wires the *real* implementation over them, so tests exercise the actual pipeline rather than a stub that can drift from it.
|
|
188
|
+
- `ConfigFile.read` — the one-shot escape from the service: read, decode and validate one explicit path, schema and codec named per call, with no resolver chain and no write path.
|
|
169
189
|
- `ConfigResolver` — `explicitPath`, `staticDir`, `upwardWalk`, `workspaceRoot`, `gitRoot` and `systemEtc`. A resolver's error channel is `never` by contract: every filesystem failure becomes `Option.none()`, so one unreadable tier never aborts the chain.
|
|
170
190
|
- `MergeStrategy` — `firstMatch` and `layeredMerge`, combining discovered sources in priority order.
|
|
171
191
|
- `JsonCodec`, `JsoncCodec`, `YamlCodec`, `TomlCodec` — JSON, JSONC, YAML and TOML in the box, exported free-standing so an unused format's engine is tree-shaken away.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/config-file",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Composable config file loading for Effect: JSON, JSONC, YAML and TOML codecs, resolution strategies, and merge behaviors.",
|
|
6
6
|
"keywords": [
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"./package.json": "./package.json"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@effected/jsonc": "
|
|
47
|
-
"@effected/toml": "
|
|
48
|
-
"@effected/walker": "
|
|
49
|
-
"@effected/yaml": "
|
|
46
|
+
"@effected/jsonc": "^0.5.2",
|
|
47
|
+
"@effected/toml": "^0.3.2",
|
|
48
|
+
"@effected/walker": "^0.3.4",
|
|
49
|
+
"@effected/yaml": "^0.6.1",
|
|
50
50
|
"effect": "4.0.0-beta.101"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|