tyfigo 0.1.0-next.d1e2fdf.0 → 0.1.0-next.d3c2bea.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/dist/bun.d.mts ADDED
@@ -0,0 +1,7 @@
1
+ import { BunPlugin } from "bun";
2
+ /**
3
+ * The tyfigo Bun plugin. Importing `tyfigo/bun` (a `bunfig.toml` `preload`) registers it for the runtime and `bun test`; pass
4
+ * `tyfigo()` in `plugins` to use it with `Bun.build`, where a `browser` target inlines the config.
5
+ */
6
+ export declare const tyfigo: () => BunPlugin;
7
+ //# sourceMappingURL=bun.d.mts.map
package/dist/bun.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import { i as configSuffixes, u as formatProblems } from "./placeholders-MqW2KO9Z.mjs";
2
+ import { t as load } from "./runtime-BuQk1xsn.mjs";
3
+ import { extname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { plugin } from "bun";
6
+ // src/bun.ts
7
+ const runtime = fileURLToPath(new URL(`runtime/index${extname(import.meta.url)}`, import.meta.url));
8
+ const filter = new RegExp(`[^/\\\\](?:${configSuffixes.map((suffix) => suffix.replaceAll(".", "\\.")).join("|")})$`);
9
+ /**
10
+ * The tyfigo Bun plugin. Importing `tyfigo/bun` (a `bunfig.toml` `preload`) registers it for the runtime and `bun test`; pass
11
+ * `tyfigo()` in `plugins` to use it with `Bun.build`, where a `browser` target inlines the config.
12
+ */
13
+ const tyfigo = () => ({
14
+ name: "tyfigo",
15
+ setup(build) {
16
+ const target = build.config?.target === "browser" ? "browser" : "server";
17
+ build.onLoad({ filter }, ({ path }) => {
18
+ const result = load(path, {
19
+ target,
20
+ runtime
21
+ });
22
+ if (result.problems.length > 0) throw new Error(`Invalid config ${path}\n${formatProblems(result.problems)}`);
23
+ return {
24
+ contents: result.code,
25
+ loader: "js"
26
+ };
27
+ });
28
+ }
29
+ });
30
+ plugin(tyfigo());
31
+ export { tyfigo };
32
+
33
+ //# sourceMappingURL=bun.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.mjs","names":[],"sources":["../src/bun.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { plugin } from 'bun';\n\nimport { configSuffixes, formatProblems } from './core/index.ts';\nimport { load } from './runtime/index.ts';\n\nimport type { BunPlugin } from 'bun';\n\n// The runtime next to this module, so it resolves from config files outside the dependency tree: `.ts` in this repo, `.mjs` once built.\nconst runtime = fileURLToPath(new URL(`runtime/index${extname(import.meta.url)}`, import.meta.url));\n\nconst filter = new RegExp(`[^/\\\\\\\\](?:${configSuffixes.map((suffix) => suffix.replaceAll('.', '\\\\.')).join('|')})$`);\n\n/**\n * The tyfigo Bun plugin. Importing `tyfigo/bun` (a `bunfig.toml` `preload`) registers it for the runtime and `bun test`; pass\n * `tyfigo()` in `plugins` to use it with `Bun.build`, where a `browser` target inlines the config.\n */\nexport const tyfigo = (): BunPlugin => ({\n\tname: 'tyfigo',\n\tsetup(build) {\n\t\tconst target = (build.config as typeof build.config | undefined)?.target === 'browser' ? 'browser' : 'server';\n\t\tbuild.onLoad({ filter }, ({ path }) => {\n\t\t\tconst result = load(path, { target, runtime });\n\t\t\tif (result.problems.length > 0) {\n\t\t\t\tthrow new Error(`Invalid config ${path}\\n${formatProblems(result.problems)}`);\n\t\t\t}\n\t\t\treturn { contents: result.code, loader: 'js' };\n\t\t});\n\t},\n});\n\nvoid plugin(tyfigo());\n"],"mappings":";;;;;;AAWA,MAAM,UAAU,cAAc,IAAI,IAAI,gBAAgB,QAAQ,YAAY,GAAG,KAAK,YAAY,GAAG,CAAC;AAElG,MAAM,SAAS,IAAI,OAAO,cAAc,eAAe,KAAK,WAAW,OAAO,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;;;;;AAMnH,MAAa,gBAA2B;CACvC,MAAM;CACN,MAAM,OAAO;EACZ,MAAM,SAAU,MAAM,QAA4C,WAAW,YAAY,YAAY;EACrG,MAAM,OAAO,EAAE,OAAO,IAAI,EAAE,WAAW;GACtC,MAAM,SAAS,KAAK,MAAM;IAAE;IAAQ;GAAQ,CAAC;GAC7C,IAAI,OAAO,SAAS,SAAS,GAC5B,MAAM,IAAI,MAAM,kBAAkB,KAAK,IAAI,eAAe,OAAO,QAAQ,GAAG;GAE7E,OAAO;IAAE,UAAU,OAAO;IAAM,QAAQ;GAAK;EAC9C,CAAC;CACF;AACD;AAEK,OAAO,OAAO,CAAC"}
package/dist/effect.d.mts CHANGED
@@ -1,2 +1,79 @@
1
- import { a as Problem, c as Span, i as LocatedSpan, n as ResolvedConfig, o as ProblemCode, r as ResolvedLayer, s as Path, t as ResolveOptions } from "./index-_5Tr2XH2.mjs";
2
- export type { LocatedSpan, Path, Problem, ProblemCode, ResolveOptions, ResolvedConfig, ResolvedLayer, Span };
1
+ import { d as ResolvedLayer, f as LocatedSpan, g as Span, h as Path, l as ResolveOptions, m as ProblemCode, p as Problem, r as ConfigSource, u as ResolvedConfig } from "./resolve-BeFHJeZb.mjs";
2
+ import { a as LooseInput, i as LoadEnvOptions, n as ConfigSchema, o as SchemaInput, r as ConfigValidationError, s as SchemaOutput, t as ConfigIssue } from "./schema-CNquZBC8.mjs";
3
+ import { ConfigProvider, Context, Effect, Layer, Schema } from "effect";
4
+ import { StandardSchemaV1 } from "@standard-schema/spec";
5
+ /**
6
+ * A Standard Schema or any Effect Schema, including one that needs services to decode.
7
+ */
8
+ export type EffectConfigSchema = StandardSchemaV1 | Schema.Top;
9
+ /**
10
+ * The services an Effect Schema needs to decode, or `never` for a Standard Schema.
11
+ */
12
+ export type SchemaServices<S> = S extends StandardSchemaV1 ? never : S extends Schema.Top ? S['DecodingServices'] : never;
13
+ /**
14
+ * The error of every tyfigo Effect: a config or the environment does not match its schema, or a config file could not
15
+ * be resolved. It is the same class the Promise API throws, tagged `ConfigValidationError`.
16
+ */
17
+ export declare const ConfigError: typeof ConfigValidationError;
18
+ export type ConfigError = ConfigValidationError;
19
+ /**
20
+ * Validates a config import (or any value) with a Standard Schema or an Effect Schema. Effect Schemas are decoded by
21
+ * Effect itself, so schemas that need services or decode asynchronously work, and so do async Standard Schemas.
22
+ */
23
+ export declare const loadConfig: <S extends EffectConfigSchema>(config: LooseInput<SchemaInput<S>>, schema: S) => Effect.Effect<SchemaOutput<S>, ConfigError, SchemaServices<S>>;
24
+ /**
25
+ * Validates `.env`, `.env.local`, `.env.<environment>` and `.env.<environment>.local` with the real environment on top.
26
+ * Never writes `process.env`.
27
+ */
28
+ export declare const loadEnv: <S extends EffectConfigSchema>(schema: S, options?: LoadEnvOptions) => Effect.Effect<SchemaOutput<S>, ConfigError, SchemaServices<S>>;
29
+ /**
30
+ * A layer that provides `service` with the validated config.
31
+ */
32
+ export declare const layerConfig: <I, S extends EffectConfigSchema>(service: Context.Key<I, SchemaOutput<S>>, config: LooseInput<SchemaInput<S>>, schema: S) => Layer.Layer<I, ConfigError, SchemaServices<S>>;
33
+ /**
34
+ * A layer that provides `service` with the validated environment variables.
35
+ */
36
+ export declare const layerEnv: <I, S extends EffectConfigSchema>(service: Context.Key<I, SchemaOutput<S>>, schema: S, options?: LoadEnvOptions) => Layer.Layer<I, ConfigError, SchemaServices<S>>;
37
+ /**
38
+ * Defines a service class for a validated config, with a `layer` that provides it.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * class AppConfig extends ConfigService<AppConfig>()('app/AppConfig', config, schema) {}
43
+ *
44
+ * const program = Effect.gen(function* () {
45
+ * const { port } = yield* AppConfig;
46
+ * }).pipe(Effect.provide(AppConfig.layer));
47
+ * ```
48
+ */
49
+ export declare const ConfigService: <Self>() => <const Identifier extends string, S extends EffectConfigSchema>(id: Identifier, config: LooseInput<SchemaInput<S>>, schema: S) => Context.ServiceClass<Self, Identifier, SchemaOutput<S>> & {
50
+ layer: Layer.Layer<Self, ConfigValidationError, Exclude<SchemaServices<S>, import("effect/Scope").Scope>>;
51
+ };
52
+ export interface ConfigProviderLayerOptions {
53
+ /**
54
+ * Whether the config files win over the provider already installed (by default the environment variables). Defaults to
55
+ * `true`; with `false` the config files only fill in paths the current provider does not have.
56
+ */
57
+ readonly asPrimary?: boolean | undefined;
58
+ }
59
+ /**
60
+ * A `ConfigProvider` that reads a config import (or any object): nested keys are path segments and array items are
61
+ * numeric segments, so `Config.Number('port').pipe(Config.nested('server'))` reads `server.port`. Empty strings are kept.
62
+ */
63
+ export declare const configProvider: (config: unknown) => ConfigProvider.ConfigProvider;
64
+ /**
65
+ * Resolves a config file with its layers, `.env` files and placeholders, like a config import does, and returns a
66
+ * `ConfigProvider` over the merged value.
67
+ */
68
+ export declare const configProviderFromFile: (file: string, options?: ResolveOptions | undefined) => Effect.Effect<ConfigProvider.ConfigProvider, ConfigValidationError, never>;
69
+ /**
70
+ * Installs {@link configProvider} for a config import on top of the current `ConfigProvider`, which falls back to the
71
+ * environment variables for paths the config does not have.
72
+ */
73
+ export declare const layerConfigProvider: (config: unknown, options?: ConfigProviderLayerOptions) => Layer.Layer<never>;
74
+ /**
75
+ * Installs {@link configProviderFromFile} on top of the current `ConfigProvider`.
76
+ */
77
+ export declare const layerConfigProviderFromFile: (file: string, options?: ResolveOptions & ConfigProviderLayerOptions) => Layer.Layer<never, ConfigError>;
78
+ export { type ConfigIssue, type ConfigSchema, type ConfigSource, ConfigValidationError, type LoadEnvOptions, type LocatedSpan, type LooseInput, type Path, type Problem, type ProblemCode, type ResolveOptions, type ResolvedConfig, type ResolvedLayer, type SchemaInput, type SchemaOutput, type Span };
79
+ //# sourceMappingURL=effect.d.mts.map
package/dist/effect.mjs CHANGED
@@ -1 +1,84 @@
1
- export {};
1
+ import { o as resolveConfig } from "./resolve-CDWA58rz.mjs";
2
+ import { n as decodeConfig, r as decodeEnv, t as ConfigValidationError } from "./schema-C31aywfc.mjs";
3
+ import { ConfigProvider, Context, Effect, Layer } from "effect";
4
+ // src/effect/load.ts
5
+ /**
6
+ * The error of every tyfigo Effect: a config or the environment does not match its schema, or a config file could not
7
+ * be resolved. It is the same class the Promise API throws, tagged `ConfigValidationError`.
8
+ */
9
+ const ConfigError = ConfigValidationError;
10
+ /**
11
+ * Validates a config import (or any value) with a Standard Schema or an Effect Schema. Effect Schemas are decoded by
12
+ * Effect itself, so schemas that need services or decode asynchronously work, and so do async Standard Schemas.
13
+ */
14
+ const loadConfig = (config, schema) => decodeConfig(config, schema, {
15
+ async: true,
16
+ native: true
17
+ });
18
+ /**
19
+ * Validates `.env`, `.env.local`, `.env.<environment>` and `.env.<environment>.local` with the real environment on top.
20
+ * Never writes `process.env`.
21
+ */
22
+ const loadEnv = (schema, options = {}) => decodeEnv(schema, {
23
+ ...options,
24
+ async: true,
25
+ native: true
26
+ });
27
+ /**
28
+ * A layer that provides `service` with the validated config.
29
+ */
30
+ const layerConfig = (service, config, schema) => Layer.effect(service, loadConfig(config, schema));
31
+ /**
32
+ * A layer that provides `service` with the validated environment variables.
33
+ */
34
+ const layerEnv = (service, schema, options = {}) => Layer.effect(service, loadEnv(schema, options));
35
+ /**
36
+ * Defines a service class for a validated config, with a `layer` that provides it.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * class AppConfig extends ConfigService<AppConfig>()('app/AppConfig', config, schema) {}
41
+ *
42
+ * const program = Effect.gen(function* () {
43
+ * const { port } = yield* AppConfig;
44
+ * }).pipe(Effect.provide(AppConfig.layer));
45
+ * ```
46
+ */
47
+ const ConfigService = () => (id, config, schema) => {
48
+ const service = Context.Service()(id);
49
+ return Object.assign(service, { layer: Layer.effect(service, loadConfig(config, schema)) });
50
+ };
51
+ // src/effect/provider.ts
52
+ /**
53
+ * A `ConfigProvider` that reads a config import (or any object): nested keys are path segments and array items are
54
+ * numeric segments, so `Config.Number('port').pipe(Config.nested('server'))` reads `server.port`. Empty strings are kept.
55
+ */
56
+ const configProvider = (config) => ConfigProvider.fromUnknown(config, { preserveEmptyStrings: true });
57
+ /**
58
+ * Resolves a config file with its layers, `.env` files and placeholders, like a config import does, and returns a
59
+ * `ConfigProvider` over the merged value.
60
+ */
61
+ const configProviderFromFile = Effect.fn("configProviderFromFile")(function* (file, options = {}) {
62
+ const result = yield* resolveConfig(file, options);
63
+ if (result.problems.length > 0) return yield* new ConfigValidationError({
64
+ subject: `config ${result.file}`,
65
+ issues: result.problems.map((problem) => ({
66
+ path: [],
67
+ message: `${problem.message} (${problem.code})`,
68
+ location: `${problem.file}:${problem.line}:${problem.column}`
69
+ }))
70
+ });
71
+ return configProvider(result.value);
72
+ });
73
+ /**
74
+ * Installs {@link configProvider} for a config import on top of the current `ConfigProvider`, which falls back to the
75
+ * environment variables for paths the config does not have.
76
+ */
77
+ const layerConfigProvider = (config, options = {}) => ConfigProvider.layerAdd(configProvider(config), { asPrimary: options.asPrimary ?? true });
78
+ /**
79
+ * Installs {@link configProviderFromFile} on top of the current `ConfigProvider`.
80
+ */
81
+ const layerConfigProviderFromFile = (file, options = {}) => ConfigProvider.layerAdd(configProviderFromFile(file, options), { asPrimary: options.asPrimary ?? true });
82
+ export { ConfigError, ConfigService, ConfigValidationError, configProvider, configProviderFromFile, layerConfig, layerConfigProvider, layerConfigProviderFromFile, layerEnv, loadConfig, loadEnv };
83
+
84
+ //# sourceMappingURL=effect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.mjs","names":[],"sources":["../src/effect/load.ts","../src/effect/provider.ts"],"sourcesContent":["import { Context, Layer } from 'effect';\n\nimport { ConfigValidationError, decodeConfig, decodeEnv } from '../schema.ts';\n\nimport type { ConfigSchema, LoadEnvOptions, LooseInput, SchemaInput, SchemaOutput } from '../schema.ts';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Effect, Schema } from 'effect';\n\n/**\n * A Standard Schema or any Effect Schema, including one that needs services to decode.\n */\nexport type EffectConfigSchema = StandardSchemaV1 | Schema.Top;\n\n/**\n * The services an Effect Schema needs to decode, or `never` for a Standard Schema.\n */\nexport type SchemaServices<S> = S extends StandardSchemaV1\n\t? never\n\t: S extends Schema.Top\n\t\t? S['DecodingServices']\n\t\t: never;\n\n/**\n * The error of every tyfigo Effect: a config or the environment does not match its schema, or a config file could not\n * be resolved. It is the same class the Promise API throws, tagged `ConfigValidationError`.\n */\nexport const ConfigError = ConfigValidationError;\nexport type ConfigError = ConfigValidationError;\n\n/**\n * Validates a config import (or any value) with a Standard Schema or an Effect Schema. Effect Schemas are decoded by\n * Effect itself, so schemas that need services or decode asynchronously work, and so do async Standard Schemas.\n */\nexport const loadConfig = <S extends EffectConfigSchema>(\n\tconfig: LooseInput<SchemaInput<S>>,\n\tschema: S,\n): Effect.Effect<SchemaOutput<S>, ConfigError, SchemaServices<S>> =>\n\tdecodeConfig(config, schema as ConfigSchema, { async: true, native: true }) as Effect.Effect<\n\t\tSchemaOutput<S>,\n\t\tConfigError,\n\t\tSchemaServices<S>\n\t>;\n\n/**\n * Validates `.env`, `.env.local`, `.env.<environment>` and `.env.<environment>.local` with the real environment on top.\n * Never writes `process.env`.\n */\nexport const loadEnv = <S extends EffectConfigSchema>(\n\tschema: S,\n\toptions: LoadEnvOptions = {},\n): Effect.Effect<SchemaOutput<S>, ConfigError, SchemaServices<S>> =>\n\tdecodeEnv(schema as ConfigSchema, { ...options, async: true, native: true }) as Effect.Effect<\n\t\tSchemaOutput<S>,\n\t\tConfigError,\n\t\tSchemaServices<S>\n\t>;\n\n/**\n * A layer that provides `service` with the validated config.\n */\nexport const layerConfig = <I, S extends EffectConfigSchema>(\n\tservice: Context.Key<I, SchemaOutput<S>>,\n\tconfig: LooseInput<SchemaInput<S>>,\n\tschema: S,\n): Layer.Layer<I, ConfigError, SchemaServices<S>> => Layer.effect(service, loadConfig(config, schema));\n\n/**\n * A layer that provides `service` with the validated environment variables.\n */\nexport const layerEnv = <I, S extends EffectConfigSchema>(\n\tservice: Context.Key<I, SchemaOutput<S>>,\n\tschema: S,\n\toptions: LoadEnvOptions = {},\n): Layer.Layer<I, ConfigError, SchemaServices<S>> => Layer.effect(service, loadEnv(schema, options));\n\n/**\n * Defines a service class for a validated config, with a `layer` that provides it.\n *\n * @example\n * ```ts\n * class AppConfig extends ConfigService<AppConfig>()('app/AppConfig', config, schema) {}\n *\n * const program = Effect.gen(function* () {\n * \tconst { port } = yield* AppConfig;\n * }).pipe(Effect.provide(AppConfig.layer));\n * ```\n */\nexport const ConfigService =\n\t<Self>() =>\n\t<const Identifier extends string, S extends EffectConfigSchema>(\n\t\tid: Identifier,\n\t\tconfig: LooseInput<SchemaInput<S>>,\n\t\tschema: S,\n\t) => {\n\t\tconst service = Context.Service<Self, SchemaOutput<S>>()(id);\n\t\treturn Object.assign(service, {\n\t\t\tlayer: Layer.effect(service, loadConfig(config, schema)),\n\t\t});\n\t};\n","import { ConfigProvider, Effect } from 'effect';\n\nimport { resolveConfig } from '../core/resolve.ts';\nimport { ConfigValidationError } from '../schema.ts';\n\nimport type { ResolveOptions } from '../core/resolve.ts';\nimport type { ConfigError } from './load.ts';\nimport type { Layer } from 'effect';\n\nexport interface ConfigProviderLayerOptions {\n\t/**\n\t * Whether the config files win over the provider already installed (by default the environment variables). Defaults to\n\t * `true`; with `false` the config files only fill in paths the current provider does not have.\n\t */\n\treadonly asPrimary?: boolean | undefined;\n}\n\n/**\n * A `ConfigProvider` that reads a config import (or any object): nested keys are path segments and array items are\n * numeric segments, so `Config.Number('port').pipe(Config.nested('server'))` reads `server.port`. Empty strings are kept.\n */\nexport const configProvider = (config: unknown): ConfigProvider.ConfigProvider =>\n\tConfigProvider.fromUnknown(config, { preserveEmptyStrings: true });\n\n/**\n * Resolves a config file with its layers, `.env` files and placeholders, like a config import does, and returns a\n * `ConfigProvider` over the merged value.\n */\nexport const configProviderFromFile = Effect.fn('configProviderFromFile')(function* (\n\tfile: string,\n\toptions: ResolveOptions = {},\n): Effect.fn.Return<ConfigProvider.ConfigProvider, ConfigError> {\n\tconst result = yield* resolveConfig(file, options);\n\tif (result.problems.length > 0) {\n\t\treturn yield* new ConfigValidationError({\n\t\t\tsubject: `config ${result.file}`,\n\t\t\tissues: result.problems.map((problem) => ({\n\t\t\t\tpath: [],\n\t\t\t\tmessage: `${problem.message} (${problem.code})`,\n\t\t\t\tlocation: `${problem.file}:${problem.line}:${problem.column}`,\n\t\t\t})),\n\t\t});\n\t}\n\treturn configProvider(result.value);\n});\n\n/**\n * Installs {@link configProvider} for a config import on top of the current `ConfigProvider`, which falls back to the\n * environment variables for paths the config does not have.\n */\nexport const layerConfigProvider = (config: unknown, options: ConfigProviderLayerOptions = {}): Layer.Layer<never> =>\n\tConfigProvider.layerAdd(configProvider(config), { asPrimary: options.asPrimary ?? true });\n\n/**\n * Installs {@link configProviderFromFile} on top of the current `ConfigProvider`.\n */\nexport const layerConfigProviderFromFile = (\n\tfile: string,\n\toptions: ResolveOptions & ConfigProviderLayerOptions = {},\n): Layer.Layer<never, ConfigError> =>\n\tConfigProvider.layerAdd(configProviderFromFile(file, options), { asPrimary: options.asPrimary ?? true });\n"],"mappings":";;;;;;;;AA0BA,MAAa,cAAc;;;;;AAO3B,MAAa,cACZ,QACA,WAEA,aAAa,QAAQ,QAAwB;CAAE,OAAO;CAAM,QAAQ;AAAK,CAAC;;;;;AAU3E,MAAa,WACZ,QACA,UAA0B,CAAC,MAE3B,UAAU,QAAwB;CAAE,GAAG;CAAS,OAAO;CAAM,QAAQ;AAAK,CAAC;;;;AAS5E,MAAa,eACZ,SACA,QACA,WACoD,MAAM,OAAO,SAAS,WAAW,QAAQ,MAAM,CAAC;;;;AAKrG,MAAa,YACZ,SACA,QACA,UAA0B,CAAC,MACyB,MAAM,OAAO,SAAS,QAAQ,QAAQ,OAAO,CAAC;;;;;;;;;;;;;AAcnG,MAAa,uBAGX,IACA,QACA,WACI;CACJ,MAAM,UAAU,QAAQ,QAA+B,CAAC,CAAC,EAAE;CAC3D,OAAO,OAAO,OAAO,SAAS,EAC7B,OAAO,MAAM,OAAO,SAAS,WAAW,QAAQ,MAAM,CAAC,EACxD,CAAC;AACF;;;;;;AC7ED,MAAa,kBAAkB,WAC9B,eAAe,YAAY,QAAQ,EAAE,sBAAsB,KAAK,CAAC;;;;;AAMlE,MAAa,yBAAyB,OAAO,GAAG,wBAAwB,CAAC,CAAC,WACzE,MACA,UAA0B,CAAC,GACoC;CAC/D,MAAM,SAAS,OAAO,cAAc,MAAM,OAAO;CACjD,IAAI,OAAO,SAAS,SAAS,GAC5B,OAAO,OAAO,IAAI,sBAAsB;EACvC,SAAS,UAAU,OAAO;EAC1B,QAAQ,OAAO,SAAS,KAAK,aAAa;GACzC,MAAM,CAAC;GACP,SAAS,GAAG,QAAQ,QAAQ,IAAI,QAAQ,KAAK;GAC7C,UAAU,GAAG,QAAQ,KAAK,GAAG,QAAQ,KAAK,GAAG,QAAQ;EACtD,EAAE;CACH,CAAC;CAEF,OAAO,eAAe,OAAO,KAAK;AACnC,CAAC;;;;;AAMD,MAAa,uBAAuB,QAAiB,UAAsC,CAAC,MAC3F,eAAe,SAAS,eAAe,MAAM,GAAG,EAAE,WAAW,QAAQ,aAAa,KAAK,CAAC;;;;AAKzF,MAAa,+BACZ,MACA,UAAuD,CAAC,MAExD,eAAe,SAAS,uBAAuB,MAAM,OAAO,GAAG,EAAE,WAAW,QAAQ,aAAa,KAAK,CAAC"}
package/dist/index.d.mts CHANGED
@@ -1,44 +1,5 @@
1
- import { a as Problem, c as Span, i as LocatedSpan, n as ResolvedConfig, o as ProblemCode, r as ResolvedLayer, s as Path, t as ResolveOptions } from "./index-_5Tr2XH2.mjs";
2
- import { r as ConfigSource } from "./resolve-Oj4qvq9_.mjs";
3
- import { Effect, Schema } from "effect";
4
- import { StandardSchemaV1 } from "@standard-schema/spec";
5
- /**
6
- * A Standard Schema (Zod, Valibot, ArkType, …) or an Effect Schema without decoding services.
7
- */
8
- type ConfigSchema = StandardSchemaV1 | Schema.ConstraintDecoder<unknown>;
9
- type SchemaInput<S> = S extends StandardSchemaV1 ? StandardSchemaV1.InferInput<S> : S extends Schema.Top ? S['Encoded'] : never;
10
- type SchemaOutput<S> = S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : S extends Schema.Top ? S['Type'] : never;
11
- /**
12
- * A schema input with literals widened and everything readonly, so a schema-less config import is assignable to it.
13
- */
14
- type LooseInput<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends readonly (infer U)[] ? readonly LooseInput<U>[] : T extends object ? { readonly [K in keyof T]: LooseInput<T[K]>; } : T;
15
- interface ConfigIssue {
16
- readonly path: readonly PropertyKey[];
17
- readonly message: string;
18
- /**
19
- * `file:line:column` when the value came from a config import, or the file alone when the key has no position.
20
- */
21
- readonly location?: string | undefined;
22
- }
23
- declare const ConfigValidationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
24
- readonly _tag: "ConfigValidationError";
25
- } & Readonly<A>;
26
- /**
27
- * Thrown with every issue at once when a config or the environment does not match its schema.
28
- */
29
- export declare class ConfigValidationError extends ConfigValidationError_base<{
30
- readonly subject: string;
31
- readonly issues: readonly ConfigIssue[];
32
- }> {
33
- get message(): string;
34
- }
35
- interface LoadEnvOptions extends ResolveOptions {
36
- /**
37
- * Where to start looking for `.env` files, which are searched there and then in the nearest directory with a
38
- * `package.json`. Defaults to `process.cwd()`.
39
- */
40
- readonly cwd?: string | undefined;
41
- }
1
+ import { d as ResolvedLayer, f as LocatedSpan, g as Span, h as Path, l as ResolveOptions, m as ProblemCode, p as Problem, r as ConfigSource, u as ResolvedConfig } from "./resolve-BeFHJeZb.mjs";
2
+ import { a as LooseInput, i as LoadEnvOptions, n as ConfigSchema, o as SchemaInput, r as ConfigValidationError, s as SchemaOutput, t as ConfigIssue } from "./schema-CNquZBC8.mjs";
42
3
  /**
43
4
  * Validates a config import (or any value) with a Standard Schema or an Effect Schema and returns the schema's output.
44
5
  *
@@ -62,5 +23,5 @@ export declare const loadEnv: <S extends ConfigSchema>(schema: S, options?: Load
62
23
  * {@link loadEnv} for schemas that may validate asynchronously.
63
24
  */
64
25
  export declare const loadEnvAsync: <S extends ConfigSchema>(schema: S, options?: LoadEnvOptions) => Promise<SchemaOutput<S>>;
65
- export type { ConfigIssue, ConfigSchema, ConfigSource, LoadEnvOptions, LocatedSpan, LooseInput, Path, Problem, ProblemCode, ResolveOptions, ResolvedConfig, ResolvedLayer, SchemaInput, SchemaOutput, Span };
26
+ export { type ConfigIssue, type ConfigSchema, type ConfigSource, ConfigValidationError, type LoadEnvOptions, type LocatedSpan, type LooseInput, type Path, type Problem, type ProblemCode, type ResolveOptions, type ResolvedConfig, type ResolvedLayer, type SchemaInput, type SchemaOutput, type Span };
66
27
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,81 +1,5 @@
1
- import { f as formatPath, g as readEnv, h as processEnv, i as getConfigSource } from "./resolve-wE3GPIQp.mjs";
2
- import { Data, Effect, Schema } from "effect";
3
- import { join } from "node:path";
4
- import process from "node:process";
5
- // src/schema.ts
6
- const formatIssue = (issue) => {
7
- const path = formatPath(issue.path.map((segment) => typeof segment === "symbol" ? String(segment) : segment));
8
- const text = path ? `${path}: ${issue.message}` : issue.message;
9
- return issue.location ? `${issue.location} - ${text}` : text;
10
- };
11
- /**
12
- * Thrown with every issue at once when a config or the environment does not match its schema.
13
- */
14
- var ConfigValidationError = class extends Data.TaggedError("ConfigValidationError") {
15
- get message() {
16
- return [`Invalid ${this.subject}:`, ...this.issues.map((issue) => ` ${formatIssue(issue)}`)].join("\n");
17
- }
18
- };
19
- const configSource = (config) => {
20
- const source = getConfigSource(config);
21
- return typeof source?.file === "string" && typeof source.position === "function" ? source : void 0;
22
- };
23
- const locateIssue = (source, path) => {
24
- const end = path.findIndex((segment) => typeof segment === "symbol");
25
- const keys = end === -1 ? path : path.slice(0, end);
26
- const position = source.position(keys);
27
- return position ? `${position.file}:${position.line}:${position.column}` : source.file;
28
- };
29
- const toStandardSchema = (schema) => Schema.isSchema(schema) ? Schema.toStandardSchemaV1(schema, { parseOptions: { errors: "all" } }) : schema;
30
- const validate = Effect.fn("validate")(function* (schema, value, options) {
31
- const pending = toStandardSchema(schema)["~standard"].validate(value);
32
- let result;
33
- if ("then" in pending) {
34
- if (!options.async) {
35
- pending.catch(() => void 0);
36
- return yield* Effect.die(/* @__PURE__ */ new TypeError(`The schema for the ${options.subject} validates asynchronously; use loadConfigAsync or loadEnvAsync`));
37
- }
38
- result = yield* Effect.promise(async () => pending);
39
- } else result = pending;
40
- const issues = [...options.issues ?? [], ...(result.issues ?? []).map((issue) => {
41
- const path = Array.from(issue.path ?? [], (segment) => typeof segment === "object" ? segment.key : segment);
42
- return {
43
- path,
44
- message: issue.message,
45
- location: options.source && locateIssue(options.source, path)
46
- };
47
- })];
48
- if (issues.length > 0) return yield* new ConfigValidationError({
49
- subject: options.subject,
50
- issues
51
- });
52
- return result.value;
53
- });
54
- const decodeConfig = (config, schema, options) => {
55
- const source = configSource(config);
56
- return validate(schema, config, {
57
- subject: source ? `config ${source.file}` : "config",
58
- source,
59
- async: options.async
60
- });
61
- };
62
- const decodeEnv = Effect.fn("decodeEnv")(function* (schema, options) {
63
- const env = options.env ?? processEnv();
64
- const environment = options.environment ?? (env.NODE_ENV || void 0);
65
- const result = yield* readEnv(join(options.cwd ?? process.cwd(), ".env"), {
66
- environment,
67
- env
68
- });
69
- return yield* validate(schema, result.variables, {
70
- subject: "environment variables",
71
- async: options.async,
72
- issues: result.problems.map((problem) => ({
73
- path: [],
74
- message: problem.message,
75
- location: `${problem.file}:${problem.line}:${problem.column}`
76
- }))
77
- });
78
- });
1
+ import { n as decodeConfig, r as decodeEnv, t as ConfigValidationError } from "./schema-C31aywfc.mjs";
2
+ import { Effect } from "effect";
79
3
  // src/index.ts
80
4
  /**
81
5
  * Validates a config import (or any value) with a Standard Schema or an Effect Schema and returns the schema's output.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/schema.ts","../src/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport process from 'node:process';\n\nimport { Data, Effect, Schema } from 'effect';\n\nimport { processEnv, readEnv } from './core/env.ts';\nimport { formatPath } from './core/positions.ts';\nimport { getConfigSource } from './runtime/resolve.ts';\n\nimport type { ResolveOptions } from './core/resolve.ts';\nimport type { ConfigSource } from './runtime/resolve.ts';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * A Standard Schema (Zod, Valibot, ArkType, …) or an Effect Schema without decoding services.\n */\nexport type ConfigSchema = StandardSchemaV1 | Schema.ConstraintDecoder<unknown>;\n\nexport type SchemaInput<S> = S extends StandardSchemaV1\n\t? StandardSchemaV1.InferInput<S>\n\t: S extends Schema.Top\n\t\t? S['Encoded']\n\t\t: never;\n\nexport type SchemaOutput<S> = S extends StandardSchemaV1\n\t? StandardSchemaV1.InferOutput<S>\n\t: S extends Schema.Top\n\t\t? S['Type']\n\t\t: never;\n\n/**\n * A schema input with literals widened and everything readonly, so a schema-less config import is assignable to it.\n */\nexport type LooseInput<T> = T extends string\n\t? string\n\t: T extends number\n\t\t? number\n\t\t: T extends boolean\n\t\t\t? boolean\n\t\t\t: T extends readonly (infer U)[]\n\t\t\t\t? readonly LooseInput<U>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { readonly [K in keyof T]: LooseInput<T[K]> }\n\t\t\t\t\t: T;\n\nexport interface ConfigIssue {\n\treadonly path: readonly PropertyKey[];\n\treadonly message: string;\n\t/**\n\t * `file:line:column` when the value came from a config import, or the file alone when the key has no position.\n\t */\n\treadonly location?: string | undefined;\n}\n\nconst formatIssue = (issue: ConfigIssue): string => {\n\tconst path = formatPath(issue.path.map((segment) => (typeof segment === 'symbol' ? String(segment) : segment)));\n\tconst text = path ? `${path}: ${issue.message}` : issue.message;\n\treturn issue.location ? `${issue.location} - ${text}` : text;\n};\n\n/**\n * Thrown with every issue at once when a config or the environment does not match its schema.\n */\nexport class ConfigValidationError extends Data.TaggedError('ConfigValidationError')<{\n\treadonly subject: string;\n\treadonly issues: readonly ConfigIssue[];\n}> {\n\toverride get message(): string {\n\t\treturn [`Invalid ${this.subject}:`, ...this.issues.map((issue) => ` ${formatIssue(issue)}`)].join('\\n');\n\t}\n}\n\nexport type { ConfigSource } from './runtime/resolve.ts';\n\nexport const configSource = (config: unknown): ConfigSource | undefined => {\n\tconst source = getConfigSource(config);\n\treturn typeof source?.file === 'string' && typeof source.position === 'function' ? source : undefined;\n};\n\nconst locateIssue = (source: ConfigSource, path: readonly PropertyKey[]): string => {\n\tconst end = path.findIndex((segment) => typeof segment === 'symbol');\n\tconst keys = (end === -1 ? path : path.slice(0, end)) as readonly (string | number)[];\n\tconst position = source.position(keys);\n\treturn position ? `${position.file}:${position.line}:${position.column}` : source.file;\n};\n\nexport const toStandardSchema = (schema: ConfigSchema): StandardSchemaV1 =>\n\tSchema.isSchema(schema)\n\t\t? Schema.toStandardSchemaV1(schema as Schema.ConstraintDecoder<unknown>, { parseOptions: { errors: 'all' } })\n\t\t: (schema as StandardSchemaV1);\n\nexport interface ValidateOptions {\n\treadonly subject: string;\n\treadonly source?: ConfigSource | undefined;\n\t/**\n\t * Allow a schema that validates asynchronously. Without it, an async schema is a defect.\n\t */\n\treadonly async: boolean;\n\t/**\n\t * Issues found before validation, such as unreadable `.env` files. They fail validation even when the schema passes.\n\t */\n\treadonly issues?: readonly ConfigIssue[] | undefined;\n}\n\nexport const validate = Effect.fn('validate')(function* <S extends ConfigSchema>(\n\tschema: S,\n\tvalue: unknown,\n\toptions: ValidateOptions,\n) {\n\tconst pending = toStandardSchema(schema)['~standard'].validate(value);\n\tlet result: StandardSchemaV1.Result<unknown>;\n\tif ('then' in pending) {\n\t\tif (!options.async) {\n\t\t\tvoid pending.catch(() => undefined);\n\t\t\treturn yield* Effect.die(\n\t\t\t\tnew TypeError(\n\t\t\t\t\t`The schema for the ${options.subject} validates asynchronously; use loadConfigAsync or loadEnvAsync`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tresult = yield* Effect.promise(async () => pending);\n\t} else {\n\t\tresult = pending;\n\t}\n\n\tconst issues = [\n\t\t...(options.issues ?? []),\n\t\t...(result.issues ?? []).map((issue): ConfigIssue => {\n\t\t\tconst path = Array.from(issue.path ?? [], (segment) =>\n\t\t\t\ttypeof segment === 'object' ? segment.key : segment,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tpath,\n\t\t\t\tmessage: issue.message,\n\t\t\t\tlocation: options.source && locateIssue(options.source, path),\n\t\t\t};\n\t\t}),\n\t];\n\tif (issues.length > 0) return yield* new ConfigValidationError({ subject: options.subject, issues });\n\treturn (result as StandardSchemaV1.SuccessResult<SchemaOutput<S>>).value;\n});\n\nexport const decodeConfig = <S extends ConfigSchema>(\n\tconfig: unknown,\n\tschema: S,\n\toptions: { readonly async: boolean },\n) => {\n\tconst source = configSource(config);\n\treturn validate(schema, config, {\n\t\tsubject: source ? `config ${source.file}` : 'config',\n\t\tsource,\n\t\tasync: options.async,\n\t});\n};\n\nexport interface LoadEnvOptions extends ResolveOptions {\n\t/**\n\t * Where to start looking for `.env` files, which are searched there and then in the nearest directory with a\n\t * `package.json`. Defaults to `process.cwd()`.\n\t */\n\treadonly cwd?: string | undefined;\n}\n\nexport const decodeEnv = Effect.fn('decodeEnv')(function* <S extends ConfigSchema>(\n\tschema: S,\n\toptions: LoadEnvOptions & { readonly async: boolean },\n) {\n\tconst env = options.env ?? processEnv();\n\tconst environment = options.environment ?? (env.NODE_ENV || undefined);\n\tconst result = yield* readEnv(join(options.cwd ?? process.cwd(), '.env'), { environment, env });\n\treturn yield* validate(schema, result.variables, {\n\t\tsubject: 'environment variables',\n\t\tasync: options.async,\n\t\tissues: result.problems.map((problem) => ({\n\t\t\tpath: [],\n\t\t\tmessage: problem.message,\n\t\t\tlocation: `${problem.file}:${problem.line}:${problem.column}`,\n\t\t})),\n\t});\n});\n","import { Effect } from 'effect';\n\nimport { decodeConfig, decodeEnv } from './schema.ts';\n\nimport type { ConfigSchema, LoadEnvOptions, LooseInput, SchemaInput, SchemaOutput } from './schema.ts';\n\nexport type {\n\tLocatedSpan,\n\tPath,\n\tProblem,\n\tProblemCode,\n\tResolvedConfig,\n\tResolvedLayer,\n\tResolveOptions,\n\tSpan,\n} from './core/index.ts';\nexport { ConfigValidationError } from './schema.ts';\nexport type {\n\tConfigIssue,\n\tConfigSchema,\n\tConfigSource,\n\tLoadEnvOptions,\n\tLooseInput,\n\tSchemaInput,\n\tSchemaOutput,\n} from './schema.ts';\n\n/**\n * Validates a config import (or any value) with a Standard Schema or an Effect Schema and returns the schema's output.\n *\n * @throws {@link ConfigValidationError} listing every issue, with `file:line:column` when `config` is a config import.\n * @throws TypeError when the schema validates asynchronously; use {@link loadConfigAsync} for those.\n */\nexport const loadConfig = <S extends ConfigSchema>(config: LooseInput<SchemaInput<S>>, schema: S): SchemaOutput<S> =>\n\tEffect.runSync(decodeConfig(config, schema, { async: false }));\n\n/**\n * {@link loadConfig} for schemas that may validate asynchronously.\n */\nexport const loadConfigAsync = async <S extends ConfigSchema>(\n\tconfig: LooseInput<SchemaInput<S>>,\n\tschema: S,\n): Promise<SchemaOutput<S>> => Effect.runPromise(decodeConfig(config, schema, { async: true }));\n\n/**\n * Validates `.env`, `.env.local`, `.env.<environment>` and `.env.<environment>.local` with the real environment on top.\n * Never writes `process.env`.\n *\n * @throws {@link ConfigValidationError} listing every issue and every `.env` file that could not be read.\n * @throws TypeError when the schema validates asynchronously; use {@link loadEnvAsync} for those.\n */\nexport const loadEnv = <S extends ConfigSchema>(schema: S, options: LoadEnvOptions = {}): SchemaOutput<S> =>\n\tEffect.runSync(decodeEnv(schema, { ...options, async: false }));\n\n/**\n * {@link loadEnv} for schemas that may validate asynchronously.\n */\nexport const loadEnvAsync = async <S extends ConfigSchema>(\n\tschema: S,\n\toptions: LoadEnvOptions = {},\n): Promise<SchemaOutput<S>> => Effect.runPromise(decodeEnv(schema, { ...options, async: true }));\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { decodeConfig, decodeEnv } from './schema.ts';\n\nimport type { ConfigSchema, LoadEnvOptions, LooseInput, SchemaInput, SchemaOutput } from './schema.ts';\n\nexport type {\n\tLocatedSpan,\n\tPath,\n\tProblem,\n\tProblemCode,\n\tResolvedConfig,\n\tResolvedLayer,\n\tResolveOptions,\n\tSpan,\n} from './core/index.ts';\nexport { ConfigValidationError } from './schema.ts';\nexport type {\n\tConfigIssue,\n\tConfigSchema,\n\tConfigSource,\n\tLoadEnvOptions,\n\tLooseInput,\n\tSchemaInput,\n\tSchemaOutput,\n} from './schema.ts';\n\n/**\n * Validates a config import (or any value) with a Standard Schema or an Effect Schema and returns the schema's output.\n *\n * @throws {@link ConfigValidationError} listing every issue, with `file:line:column` when `config` is a config import.\n * @throws TypeError when the schema validates asynchronously; use {@link loadConfigAsync} for those.\n */\nexport const loadConfig = <S extends ConfigSchema>(config: LooseInput<SchemaInput<S>>, schema: S): SchemaOutput<S> =>\n\tEffect.runSync(decodeConfig(config, schema, { async: false }));\n\n/**\n * {@link loadConfig} for schemas that may validate asynchronously.\n */\nexport const loadConfigAsync = async <S extends ConfigSchema>(\n\tconfig: LooseInput<SchemaInput<S>>,\n\tschema: S,\n): Promise<SchemaOutput<S>> => Effect.runPromise(decodeConfig(config, schema, { async: true }));\n\n/**\n * Validates `.env`, `.env.local`, `.env.<environment>` and `.env.<environment>.local` with the real environment on top.\n * Never writes `process.env`.\n *\n * @throws {@link ConfigValidationError} listing every issue and every `.env` file that could not be read.\n * @throws TypeError when the schema validates asynchronously; use {@link loadEnvAsync} for those.\n */\nexport const loadEnv = <S extends ConfigSchema>(schema: S, options: LoadEnvOptions = {}): SchemaOutput<S> =>\n\tEffect.runSync(decodeEnv(schema, { ...options, async: false }));\n\n/**\n * {@link loadEnv} for schemas that may validate asynchronously.\n */\nexport const loadEnvAsync = async <S extends ConfigSchema>(\n\tschema: S,\n\toptions: LoadEnvOptions = {},\n): Promise<SchemaOutput<S>> => Effect.runPromise(decodeEnv(schema, { ...options, async: true }));\n"],"mappings":";;;;;;;;;AAiCA,MAAa,cAAsC,QAAoC,WACtF,OAAO,QAAQ,aAAa,QAAQ,QAAQ,EAAE,OAAO,MAAM,CAAC,CAAC;;;;AAK9D,MAAa,kBAAkB,OAC9B,QACA,WAC8B,OAAO,WAAW,aAAa,QAAQ,QAAQ,EAAE,OAAO,KAAK,CAAC,CAAC;;;;;;;;AAS9F,MAAa,WAAmC,QAAW,UAA0B,CAAC,MACrF,OAAO,QAAQ,UAAU,QAAQ;CAAE,GAAG;CAAS,OAAO;AAAM,CAAC,CAAC;;;;AAK/D,MAAa,eAAe,OAC3B,QACA,UAA0B,CAAC,MACG,OAAO,WAAW,UAAU,QAAQ;CAAE,GAAG;CAAS,OAAO;AAAK,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {}