@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
Proposed1. Summary / Abstract
This RFC proposes
@env-spec, a Domain-Specific Language (DSL) that extends the traditional.envfile syntax. It introduces structured metadata via@decoratorstyle comments and a syntax for setting values through function calls. The goal of@env-specis 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.envfiles. This specification defines the parsing rules for@env-speccompliant files.2. Motivation / Problem Statement
Traditional
.envfiles, while widely adopted for their simplicity, lack a standardized way to convey metadata or complex value semantics. This leads to:.envstructure. This increases the risk of accidental exposure..env.examplefiles provide a starting point, they are static and don't offer ongoing schema enforcement or rich metadata for tools and team members..envspecification has led to various parsers with slightly different behaviors regarding comments, quoting, and variable expansion.@env-specaims to address these issues by providing a standardized, backwards-compatible (as much as feasible) extension to.envfiles, 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..envfiles using@decorators..envfile practices..env.schemafile) across teams and environments.4. Non-Goals
@requiredor@sensitiveactually 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-specfiles into a structured representation..envformat.5. Proposed Solution / Detailed Design
@env-specextends the.envsyntax. An@env-specenabled parser will process files according to the following rules:5.1. File Structure and Merging Philosophy
.env.schemafile, 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 commentDecoratorComment:@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:RegularCommentand/orDecoratorCommentlines.Divideror an empty line from any config item).Divider, a config item, or the end of the file.DocumentHeader:CommentBlockat the very beginning of the document that ends with aDivider.5.3. Decorators
Decorators attach structured metadata. They appear within
DecoratorComments.@nameor@name=value.@nameis equivalent to@name=true.5.4. Config Items
Config items define individual environment variables.
Structure:
KEY=valueKey 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:
\nwithin double quotes:"line1\nline2""""with actual newlines``` with actual newlinesFor triple quotes/backticks:
Examples:
Attached Comments:
DecoratorComments andRegularComments immediately preceding a config item (without an intervening empty line orDivider) are attached to that item.RegularCommentorDecoratorCommentcan appear on the same line after the config item's value. These are also attached.@description,@required, and@sensitiveare 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.
\nshould be used. In quote-wrapped values (single, double, backtick),\nwill be interpreted as a literal newline character.[ #].[ #].[ ,)].truebecomes booleantrue.falsebecomes booleanfalse.undefinedbecomesundefined.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".\nwithin 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
@decoratorsor function call syntax should parse correctly by most existing.envparsers, assuming they follow common comment and K/V syntax.@env-specstandardizes certain behaviors (e.g., comment attachment, value parsing) where existing parsers might differ.@env-specmay offer compatibility flags to mimic behaviors of other specific.envparsers if desired by users, but this is outside the core spec.@env-specenabled parser will successfully parse files that non-@env-specparsers might fail on (due to decorators or function calls).6. Alternatives Considered
.envfiles.@env-specaims for progressive enhancement.@decoratorstyle is familiar from JSDoc, Python decorators, etc., and offers clear parsing rules..envBaseline: Attempting to enforce a very strict subset of.envcompatibility could alienate users of tools with more lenient parsing.@env-spectries to be reasonably accommodating while standardizing its extensions.7. Pros and Cons
Pros:
.envfile..envfiles can gradually adopt@env-specfeatures..env.schemafiles can be version-controlled and shared.Cons:
@env-specparser is more complex than a basic.envparser..envfiles complex.8. Impact
.env.schemafiles.9. Open Questions / Unresolved Issues
"""or```) be strictly defined, or left to implementers?.envparser behaviors that need explicit "compatibility consideration" notes (even if not part of the core spec)?.env.schemaand.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.schemaand.envfiles for various use cases.@env-spec.Beta Was this translation helpful? Give feedback.
All reactions