@effected/config-file 0.1.0

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/YamlCodec.js ADDED
@@ -0,0 +1,34 @@
1
+ import { ConfigCodecError } from "./ConfigCodec.js";
2
+ import { Effect } from "effect";
3
+ import { Yaml } from "@effected/yaml";
4
+
5
+ //#region src/YamlCodec.ts
6
+ /**
7
+ * A `ConfigCodec` backed by `@effected/yaml`.
8
+ *
9
+ * @remarks
10
+ * `@effected/yaml`'s input hardening — an alias-expansion budget guarding
11
+ * against "billion laughs" alias bombs, and a collection-nesting depth cap —
12
+ * fails through the typed error channel, so a hostile config file surfaces
13
+ * as a `ConfigCodecError` rather than crashing the process. Both directions
14
+ * preserve the underlying failure structurally in `cause` — never
15
+ * stringified.
16
+ *
17
+ * @public
18
+ */
19
+ const YamlCodec = {
20
+ name: "yaml",
21
+ parse: (raw) => Yaml.parse(raw).pipe(Effect.mapError((cause) => new ConfigCodecError({
22
+ codec: "yaml",
23
+ operation: "parse",
24
+ cause
25
+ }))),
26
+ stringify: (value) => Yaml.stringify(value).pipe(Effect.mapError((cause) => new ConfigCodecError({
27
+ codec: "yaml",
28
+ operation: "stringify",
29
+ cause
30
+ })))
31
+ };
32
+
33
+ //#endregion
34
+ export { YamlCodec };