-
Notifications
You must be signed in to change notification settings - Fork 106
MVP array config item vals #843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@env-spec/parser": minor | ||
| varlock: minor | ||
| env-spec-language: minor | ||
| --- | ||
|
|
||
| Add `@type=array(...)` for list-valued config items with per-element validation, array literal values, JSON and comma-separated input, and `T[]` type generation. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,4 +254,34 @@ POLL_INTERVAL=15m | |
|
|
||
| Same parser is used by `cache(..., ttl=...)` and the plugin `cacheTtl` option, so any string that works there also works here. For cache mode behavior and troubleshooting, see the [Caching guide](/guides/caching/). | ||
| </div> | ||
|
|
||
| <div> | ||
| ### `array` | ||
|
|
||
| Validates a list of values, coercing and checking each element with an inner type. | ||
|
|
||
| **Element type** — first positional argument: a type name (`string`, `email`, …) or a nested call for types with positional args (`enum(dev, staging, prod)`). | ||
|
|
||
| **Array options:** | ||
| - `minLength` / `maxLength` — element count bounds | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probable want an |
||
| - `unique` (boolean) — reject duplicate elements | ||
| - `separator` (string) — split string input (e.g. `","` for comma-separated `.env` values) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both in terms of input and output, we may need some options around quotes and brackets. For example, all these seem like reasonable inputs - Id assume default is that splitting by comma is fine, and no quotes needed, since if youre using an env var today to pass in a list, its probably just |
||
| - `allowEmpty` (boolean) — allow `[]` (default: false) | ||
|
|
||
| Named options not listed above are forwarded to the element type (e.g. `normalize=true` on `array(email, …)`). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is weird |
||
|
|
||
| ```env-spec | ||
| # @type=array(email, normalize=true) | ||
| ALLOWED_EMAILS=[admin@example.com, support@example.com] | ||
|
|
||
| # @type=array(enum(dev, staging, prod)) | ||
| APP_MODES=[dev, staging] | ||
|
|
||
| # Comma-separated in .env | ||
| # @type=array(email, separator=",") | ||
| ALLOWED_EMAILS=one@example.com, two@example.com | ||
| ``` | ||
|
|
||
| Array values are available as typed arrays via `ENV` (e.g. `string[]`). In `process.env` they are JSON-serialized. | ||
| </div> | ||
| </div> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My debate internally had been whether to do wrap the type in
array()or to split it into a new decorator --@type=string(startsWith=abc) @arrayType(minLength=2)Obviously wrapping is a bit more correct, but since our type stuff doesnt actually use normal function calls like the rest of the system I thought it might be cleaner. Also do we want to support nested arrays?
Im not set on it, but curious what you think.
Also - we may as well support object (record/dictionary) too with this work? I dont think arbitrary shaped objects like we had in dmno, but just setting the value type, and optionally the key type.
dictionary(uuid, keyType=string(isLength=2), minKeyCount=2)