-
Notifications
You must be signed in to change notification settings - Fork 5
Coercion #569
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
Merged
Coercion #569
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
da4be5e
`type` Coercion Implementation (#565)
yamcodes c0e0a14
Global schema transformer (#570)
yamcodes 1728e55
Improve coercion types (#572)
yamcodes 07fd3dd
Schema-Directed Coercion JSON Schema (100% Public API Coercion implem…
yamcodes ed36e78
Merge branch 'main' into coercion
yamcodes 513f9f0
Merge branch 'main' into coercion
yamcodes a03eee6
Merge branch 'main' into coercion
yamcodes 32522e3
fix(coerce): support schemas with morphs (#593)
yamcodes 78936c3
feat(arkenv): Fix coercion crashes for predicates (#595)
yamcodes 167ba08
Coercion playgrounds/examples (#596)
yamcodes 84c1145
Coercion Documentation (#597)
yamcodes 1483d57
NaN Coercion (#603)
yamcodes 68956d5
Option to disable coercion (#602)
yamcodes 2f85b3f
docs: Archive coercion public API design documents and move final spe…
yamcodes 20f31d4
docs: Archive `update-hero-videos` change documents and promote the h…
yamcodes 59e162c
chore: Update `VITE_MY_VAR` type from `string` to `unknown`.
yamcodes f1dd521
feat: update literal coercion spec to expect successful string-to-num…
yamcodes bb12b6f
docs: Detail path mapping rules and execution flow for the coercion p…
yamcodes 8d8bb6c
feat: Update spec to require coercion of strings to numbers for numer…
yamcodes 5924c6f
fix: correct typo in coercion spec
yamcodes 1ecde2e
fix: Reference `toJsonSchema` instead of `json` for ArkType API in co…
yamcodes 788fc01
test: Add cases for array element coercion and validation failures
yamcodes dd2d649
chore: Adjust bundle size goal to 2KB across documentation and update…
yamcodes 6e39da2
chore: Increase bun-plugin bundle size limit to 2.2 kB.
yamcodes 864e285
refactor: consolidate stable introspection and pipeline-based coercio…
yamcodes e14bc5f
refactor: Update `VITE_MY_VAR` type from `string` to `unknown` in Vit…
yamcodes e656a71
docs: Define stable coercion mechanism using public ArkType APIs, doc…
yamcodes 9631c67
test: add test for case-sensitive boolean coercion expecting an error…
yamcodes ea59bc0
docs: add user-facing behavior documentation and elaborate on coercio…
yamcodes 973473a
docs: Refine coercion public API design by detailing null/undefined k…
yamcodes 55e27bb
docs: Add details on performance, mutation, limitations, and alternat…
yamcodes a9a7e72
Merge branch 'main' into coercion
yamcodes 3a7623f
Update openspec/specs/coercion/spec.md
yamcodes d7a7d1d
docs: Improve clarity of coercion specification and simplify test com…
yamcodes 934493c
style: Standardize scenario formatting in the coercion specification.
yamcodes fec2e63
docs: Fix punctuation in coercion spec.
yamcodes 0680c1a
docs: fix punctuation in coercion spec
yamcodes 78a1cd0
feat: add 404 Not Found page and update pnpm lockfile
yamcodes 9cef3a9
test: adjust `arkenv` `loadEnv` assertion to use object property syntax
yamcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| "@arkenv/vite-plugin": minor | ||
| --- | ||
|
|
||
| ### Breaking Change: `createEnv` API Update | ||
|
|
||
| The underlying `arkenv` package has updated its `createEnv` API. This affects users who manually call `arkenv` (or `createEnv`) within their `vite.config.ts` to Type-Safe environment variables during config loading. | ||
|
|
||
| If you are using this pattern: | ||
|
|
||
| ```ts | ||
| const env = arkenv(Env, loadEnv(mode, process.cwd(), "")); | ||
| ``` | ||
|
|
||
| You must update it to: | ||
|
|
||
| ```ts | ||
| const env = arkenv(Env, { env: loadEnv(mode, process.cwd(), "") }); | ||
| ``` | ||
|
|
||
| The plugin usage itself (`plugins: [arkenv(Env)]`) remains unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| "arkenv": minor | ||
| --- | ||
|
|
||
| ### Coercion | ||
|
|
||
| Introduced **Schema-Directed Coercion**: now, environment variables defined as `number` or `boolean` in your schema are automatically parsed to their correct types. | ||
|
|
||
| If you want to opt-out of this feature, pass `config.coerce: false` to `createEnv()` (`arkenv()`). Example: | ||
|
|
||
| ```ts | ||
| arkenv(schema, { coerce: false }); | ||
| ``` | ||
|
|
||
| To learn more about the new coercion system, read [the docs](https://arkenv.js.org/docs/arkenv/coercion). | ||
|
|
||
| ### ⚠️ Breaking Changes | ||
|
|
||
| * **`createEnv` API**: The `createEnv` function signature has changed to support a configuration object. | ||
| Instead of `createEnv(schema, env)`, use `createEnv(schema, config)` where `config` includes `env` and the newly added `coerce` option (`true` by default). | ||
| * **`boolean` keyword**: The custom `boolean` morph has been removed. Use `arktype`'s standard `boolean` instead, which will be coerced when used within `createEnv` / `arkenv`. | ||
| * **`port` keyword**: Now a strict numeric refinement (0-65535). It no longer parses strings automatically outside of `createEnv` / `arkenv`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@repo/keywords": minor | ||
| --- | ||
|
|
||
| #### Simplify keywords for central coercion | ||
|
|
||
| * **BREAKING**: The `boolean` keyword has been removed. Universal boolean coercion is now handled by the `arkenv` package. | ||
| * **BREAKING**: The `port` keyword has been changed from a `string -> number` morph to a pure `number` refinement. Numeric coercion is now handled centrally. | ||
| * Added `maybeParsedNumber` and `maybeParsedBoolean` internal morphs to support central coercion (including specific "NaN" support). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@repo/scope": minor | ||
| --- | ||
|
|
||
| #### Align scope with central coercion | ||
|
|
||
| * **BREAKING**: Removed the custom `boolean` keyword from the root scope. ArkEnv now uses the standard ArkType `boolean` primitive combined with global coercion. | ||
| * Updated `number.port` to use the new strict numeric refinement, as string parsing is now handled by global coercion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { type } from "arkenv"; | ||
|
|
||
| export default type({ | ||
| BUN_PUBLIC_API_URL: "string", | ||
| BUN_PUBLIC_API_URL: "string.url", | ||
| BUN_PUBLIC_DEBUG: "boolean", | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,2 @@ | ||
| HOST=localhost | ||
| PORT=3000 | ||
| NODE_ENV=development | ||
| DEBUG=true | ||
| ZED_ENV=development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,19 @@ | ||
| import arkenv, { type } from "arkenv"; | ||
| import * as z from "zod"; | ||
| import arkenv from "arkenv"; | ||
|
|
||
| const env = arkenv({ | ||
| HOST: "string.host", | ||
| PORT: "number.port", | ||
| HOST: "string.ip | 'localhost'", | ||
| PORT: "0 <= number.integer <= 65535", | ||
| NODE_ENV: "'development' | 'production' | 'test' = 'development'", | ||
| ALLOWED_ORIGINS: type("string[]").default(() => []), | ||
| DEBUG: "boolean = true", | ||
| ZED_ENV: z.string(), | ||
| DEBUGGING: "boolean = false", | ||
| }); | ||
|
|
||
| // Automatically validate and parse process.env | ||
| // TypeScript knows the ✨exact✨ types! | ||
| const host = env.HOST; | ||
| const port = env.PORT; | ||
| const nodeEnv = env.NODE_ENV; | ||
| const allowedOrigins = env.ALLOWED_ORIGINS; | ||
| const debug = env.DEBUG; | ||
| const zedEnv = env.ZED_ENV; | ||
| console.log({ | ||
| host, | ||
| port, | ||
| nodeEnv, | ||
| allowedOrigins, | ||
| debug, | ||
| zedEnv, | ||
| host: env.HOST, | ||
| port: env.PORT, | ||
| nodeEnv: env.NODE_ENV, | ||
| debugging: env.DEBUGGING, | ||
| }); | ||
|
|
||
| export default env; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.