@env-spec initial specification #17
Pinned
philmillman
started this conversation in
@env-spec RFCs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
RFC-0001: @env-spec - A Specification for Enhanced .env Files
Proposed
1. Summary / Abstract
This RFC proposes
@env-spec
, a Domain-Specific Language (DSL) that extends the traditional.env
file syntax. It introduces structured metadata via@decorator
style comments and a syntax for setting values through function calls. The goal of@env-spec
is to enable richer interactions with environment configuration, including enhanced validation, type coercion, improved security for sensitive data, and more flexible value loading mechanisms (e.g., decryption, fetching from external sources) directly within.env
files. This specification defines the parsing rules for@env-spec
compliant files.2. Motivation / Problem Statement
Traditional
.env
files, while widely adopted for their simplicity, lack a standardized way to convey metadata or complex value semantics. This leads to:.env
structure. This increases the risk of accidental exposure..env.example
files provide a starting point, they are static and don't offer ongoing schema enforcement or rich metadata for tools and team members..env
specification has led to various parsers with slightly different behaviors regarding comments, quoting, and variable expansion.@env-spec
aims to address these issues by providing a standardized, backwards-compatible (as much as feasible) extension to.env
files, enabling a schema-driven approach to environment configuration. This will empower a new generation of tools to offer better security, developer experience, and robustness.3. Goals
@env-spec
..env
files using@decorators
..env
file practices..env.schema
file) across teams and environments.4. Non-Goals
@required
or@sensitive
actually do). It only defines their syntax and how they are parsed and attached to config items or the document. The interpretation and action based on these decorators are left to implementing tools.decrypt()
,fetchFromVault()
). It only defines the syntax for function calls. The implementation and availability of specific functions are left to implementing tools.@env-spec
files into a structured representation..env
format.5. Proposed Solution / Detailed Design
@env-spec
extends the.env
syntax. An@env-spec
enabled parser will process files according to the following rules:5.1. File Structure and Merging Philosophy
.env.schema
file, intended to be committed to version control..env.schema
(as defaults), or in subsequent files (e.g.,.env
,.env.local
,.env.production
).@env-spec
, but the syntax should support this.5.2. Comments
Comments begin with
#
. They can be on their own line or at the end of a line.Regular Comment
:@
immediately after#
.#
is optional:# this
,# is valid
.# this @decorator is ignored
.KEY=val # this is a regular comment
DecoratorComment
:@
immediately after#
.# @type=string @required
.# @sensitive # key is published in final build
.# @type=string(startsWith="sk_")
Divider
:#---
or#===
(optional single leading space after#
is allowed:# ---
).---
or===
on the line is considered part of the divider but ignored for parsing purposes:# --- Section Break ---
.# ---
CommentBlock
:RegularComment
and/orDecoratorComment
lines.Divider
or an empty line from any config item).Divider
, a config item, or the end of the file.DocumentHeader
:CommentBlock
at the very beginning of the document that ends with aDivider
.5.3. Decorators
Decorators attach structured metadata. They appear within
DecoratorComment
s.@name
or@name=value
.@name
is equivalent to@name=true
.5.4. Config Items
Config items define individual environment variables.
Structure:
KEY=value
Key Syntax:
[a-zA-Z_]
.[a-zA-Z0-9_]
.API_KEY
,_DB_USER
,FeatureFlag1
.2_FACTOR_AUTH
,api-key
.Value Assignment:
KEY=
(no value after=
) is parsed asundefined
.KEY=""
(empty quoted string) is parsed as an empty string""
.Multi-line Values:
Can be specified in several ways:
\n
within double quotes:"line1\nline2"
"""
with actual newlinesFor triple quotes/backticks:
Examples:
Attached Comments:
DecoratorComment
s andRegularComment
s immediately preceding a config item (without an intervening empty line orDivider
) are attached to that item.RegularComment
orDecoratorComment
can appear on the same line after the config item's value. These are also attached.@description
,@required
, and@sensitive
are all attached toDB_USER
.5.5. Common Value-Handling Rules
These rules apply to config item values (single-line), decorator values, and function call arguments.
\n
should be used. In quote-wrapped values (single, double, backtick),\n
will be interpreted as a literal newline character.[ #]
.[ #]
.[ ,)]
.true
becomes booleantrue
.false
becomes booleanfalse
.undefined
becomesundefined
.123
,45.67
,-10
) are coerced to numbers.TIMEOUT=3000
,@retry=true
,LOG_LEVEL=info
.true
,false
, numbers)."
(double),'
(single),`
(backtick)."This is an \"escaped\" quote"
.\n
within quoted strings is interpreted as a newline character.MESSAGE="Hello World"
,@pattern="^[a-z]+$"
,DB_NAME='my-database'
.5.6. Function Calls
Values (for config items or decorators) can be specified as function calls.
functionName(arg1, arg2, ...)
orfunctionName(key1=val1, key2=val2, ...)
orfunctionName()
.name(...)
.[a-zA-Z]
and can subsequently contain[a-zA-Z0-9_]
.5.7. Backwards Compatibility
@decorators
or function call syntax should parse correctly by most existing.env
parsers, assuming they follow common comment and K/V syntax.@env-spec
standardizes certain behaviors (e.g., comment attachment, value parsing) where existing parsers might differ.@env-spec
may offer compatibility flags to mimic behaviors of other specific.env
parsers if desired by users, but this is outside the core spec.@env-spec
enabled parser will successfully parse files that non-@env-spec
parsers might fail on (due to decorators or function calls).6. Alternatives Considered
.env
files.@env-spec
aims for progressive enhancement.@decorator
style is familiar from JSDoc, Python decorators, etc., and offers clear parsing rules..env
Baseline: Attempting to enforce a very strict subset of.env
compatibility could alienate users of tools with more lenient parsing.@env-spec
tries to be reasonably accommodating while standardizing its extensions.7. Pros and Cons
Pros:
.env
file..env
files can gradually adopt@env-spec
features..env.schema
files can be version-controlled and shared.Cons:
@env-spec
parser is more complex than a basic.env
parser..env
files complex.8. Impact
.env.schema
files.9. Open Questions / Unresolved Issues
"""
or```
) be strictly defined, or left to implementers?.env
parser behaviors that need explicit "compatibility consideration" notes (even if not part of the core spec)?.env.schema
and.env.local
)? (Likely an implementation detail for merging tools, but worth discussing).@description
,@example
,@default
) to encourage interoperability?10. Future Possibilities / Phasing
@env-spec
.env(VAR_NAME, defaultValue)
,file(path)
).11. How to Teach This
.env.schema
, using decorators, and employing function calls..env.schema
and.env
files for various use cases.@env-spec
.Beta Was this translation helpful? Give feedback.
All reactions