Skip to content

Expose type function#139

Merged
yamcodes merged 3 commits intomainfrom
export-type
Sep 10, 2025
Merged

Expose type function#139
yamcodes merged 3 commits intomainfrom
export-type

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Sep 10, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a public type() API for defining environment schemas with ArkEnv-specific types (e.g., string.host, number.port) and validating with env.assert.
  • Documentation

    • Added a comprehensive Type Function guide with examples, advanced usage, Vite integration, updated key features, navigation entry, and Quickstart cards.
  • Tests

    • Added extensive tests covering scalar, optional, nested, array, and ArkEnv-specific validations.
  • Chores

    • Added a changeset announcing the new public API surface.

@changeset-bot
Copy link

changeset-bot bot commented Sep 10, 2025

🦋 Changeset detected

Latest commit: 62e5936

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
arkenv Minor
@arkenv/vite-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
arkenv Ready Ready Preview Comment Sep 10, 2025 8:57pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 10, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a new public export type to ArkEnv (re-exported from scope), plus a dedicated type.ts module, Vitest coverage for the type API, documentation (guide, nav entry, quickstart cards, index feature note), and a changeset announcing the new API surface.

Changes

Cohort / File(s) Summary
Public API export
packages/arkenv/src/index.ts, packages/arkenv/src/type.ts
Add packages/arkenv/src/type.ts exporting export const type = $.type; and re-export it from the package index (export * from "./type").
Tests for type function
packages/arkenv/src/type.test.ts
Add Vitest suite exercising scalar, optional, ArkEnv-specific (host/port) validations, nested objects, arrays, coercion, and assert behavior.
Documentation
apps/www/content/docs/guides/type-function.mdx, apps/www/content/docs/meta.json, apps/www/content/docs/quickstart.mdx, apps/www/content/docs/index.mdx
Add a new Type Function guide, insert it into docs navigation, add Quickstart cards linking the guide, and add a key-features note describing type().
Vite plugin fixture update
packages/vite-plugin/src/__fixtures__/basic/config.ts
Switch import of type helper from arktype to arkenv (use new public export).
Changeset
.changeset/large-taxis-check.md
Add a changeset entry announcing the new public API exposure and usage example.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant ArkEnv as "arkenv (package)"
  participant Scope as "scope (internal)"
  participant EnvType as "envType (schema)"
  participant Runtime as "runtime (process.env)"

  Dev->>ArkEnv: import { type } from "arkenv"
  ArkEnv->>Scope: forward export ($.type)
  Dev->>EnvType: const envType = type(schema)
  Dev->>Runtime: provide env object (e.g., process.env)
  Dev->>EnvType: envType.assert(runtime)
  EnvType-->>Dev: validated & coerced config OR throws error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Expose type function #139 — Adds the same public type export, plus tests and docs referencing the new export (strong code-level overlap).

Suggested labels

@arkenv/vite-plugin

I nibbled the specs with nimble paws,
Pulled a type from ArkEnv’s laws. 🥕
Hosts and ports parsed, tidy and bright,
Tests hop in, docs shine in the light.
Schema sealed neat — validation takes flight.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98b9cfe and 62e5936.

📒 Files selected for processing (1)
  • packages/vite-plugin/src/__fixtures__/basic/config.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch export-type

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added docs Improvements or additions to documentation arkenv Changes to the `arkenv` npm package. www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests labels Sep 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/www/content/docs/index.mdx (1)

38-39: Fix port range comment (0 is invalid per our validator and tests).

-  PORT: "number.port",           // Ensures valid port number (0-65535)
+  PORT: "number.port",           // Ensures valid port number (1-65535)
🧹 Nitpick comments (6)
.changeset/large-taxis-check.md (1)

25-25: Link the new guide from the changeset for discoverability.

-This extends ArkType's `type` function with ArkEnv-specific validations for common environment variable patterns.
+This extends ArkType's `type` function with ArkEnv-specific validations for common environment variable patterns. See the docs: [Type Function guide](/docs/guides/type-function).
apps/www/content/docs/index.mdx (1)

15-15: Nice addition. Consider linking to the guide inline.

-- 🛠️ **Type function**: Use `type()` to separate schema definition from validation
+- 🛠️ **Type function**: Use `type()` to separate schema definition from validation ([learn more](/docs/guides/type-function))
packages/arkenv/src/index.ts (1)

4-4: Re-export looks good; add a smoke test to ensure type is exposed from the top-level.

Add this small test to packages/arkenv/src/index.test.ts to guard the public API:

it("should export `type` from the package entrypoint", () => {
  // Import from the index (package entry)
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const { type: arkenvType } = require(".");
  const schema = arkenvType({ PORT: "number.port" });
  const result = schema.assert({ PORT: "3000" });
  expect(result.PORT).toBe(3000);
});
packages/arkenv/src/type.ts (1)

1-3: Add TSDoc to clarify that this is ArkEnv-scoped ArkType.

 import { $ } from "./scope";

+/**
+ * ArkEnv-scoped ArkType `type` function.
+ * Provides `string.host`, `number.port`, and other ArkEnv-specific validators.
+ */
 export const type = $.type;
apps/www/content/docs/guides/type-function.mdx (1)

125-146: Add a small “Defaults” subsection to mirror Quickstart and show = 'default' usage.

 ## Advanced Usage
 ### Optional Fields
@@
 const env = type({
   REQUIRED: "string",
   OPTIONAL: "string?",
   PORT: "number.port?",
 });
@@
 });
+
+### Defaults
+
+You can provide defaults for optional fields:
+
+```ts
+const env = type({
+  LOG_LEVEL: "'debug' | 'info' | 'warn' | 'error' = 'info'",
+});
+
+const result = env.assert({});
+// result.LOG_LEVEL === "info"
+```
packages/arkenv/src/type.test.ts (1)

1-3: Include expectTypeOf and add a couple of lightweight type and failure tests.

-import { describe, expect, it } from "vitest";
+import { describe, expect, it, expectTypeOf } from "vitest";

Additional tests (append near the end):

it("should infer precise types from schema", () => {
  const envType = type({
    HOST: "string.host",
    PORT: "number.port",
    OPTIONAL: "string?",
  });
  const res = envType.assert({ HOST: "localhost", PORT: "3000" });
  expectTypeOf(res.HOST).toEqualTypeOf<string>();
  expectTypeOf(res.PORT).toEqualTypeOf<number>();
  expectTypeOf(res.OPTIONAL).toEqualTypeOf<string | undefined>();
});

it("should fail invalid array members", () => {
  const envType = type({ ALLOWED_ORIGINS: "string[]" });
  expect(() =>
    envType.assert({ ALLOWED_ORIGINS: ["ok.com", 123 as unknown as string] })
  ).toThrow();
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9737f8 and 98b9cfe.

📒 Files selected for processing (8)
  • .changeset/large-taxis-check.md (1 hunks)
  • apps/www/content/docs/guides/type-function.mdx (1 hunks)
  • apps/www/content/docs/index.mdx (1 hunks)
  • apps/www/content/docs/meta.json (1 hunks)
  • apps/www/content/docs/quickstart.mdx (1 hunks)
  • packages/arkenv/src/index.ts (1 hunks)
  • packages/arkenv/src/type.test.ts (1 hunks)
  • packages/arkenv/src/type.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use built-in validators (host, port, url, email, etc.) when available in environment schemas
Provide default values for optional environment variables in schemas

Files:

  • packages/arkenv/src/type.ts
  • packages/arkenv/src/type.test.ts
  • packages/arkenv/src/index.ts
**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.test.ts: Place tests alongside source files using the .test.ts suffix
Use Vitest's describe/it structure in tests
Test both success and failure cases for each feature
Mock process.env in tests and restore it after each test to isolate scenarios
Verify both runtime behavior and TypeScript types in tests

Files:

  • packages/arkenv/src/type.test.ts
🧠 Learnings (4)
📚 Learning: 2025-09-10T19:39:49.841Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-10T19:39:49.841Z
Learning: Applies to **/*.{ts,tsx} : Use built-in validators (host, port, url, email, etc.) when available in environment schemas

Applied to files:

  • apps/www/content/docs/index.mdx
  • packages/arkenv/src/type.test.ts
📚 Learning: 2025-09-10T19:39:49.841Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-10T19:39:49.841Z
Learning: Applies to **/*.test.ts : Verify both runtime behavior and TypeScript types in tests

Applied to files:

  • packages/arkenv/src/type.test.ts
📚 Learning: 2025-09-10T19:39:49.841Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-10T19:39:49.841Z
Learning: Applies to **/*.test.ts : Use Vitest's describe/it structure in tests

Applied to files:

  • packages/arkenv/src/type.test.ts
📚 Learning: 2025-09-10T19:39:49.841Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-10T19:39:49.841Z
Learning: Applies to **/*.{ts,tsx} : Provide default values for optional environment variables in schemas

Applied to files:

  • packages/arkenv/src/index.ts
🧬 Code graph analysis (6)
.changeset/large-taxis-check.md (3)
packages/arkenv/src/scope.test.ts (6)
  • envType (33-44)
  • stringType (46-50)
  • hostType (5-9)
  • hostType (11-15)
  • it (4-51)
  • hostType (17-20)
packages/arkenv/src/create-env.ts (1)
  • createEnv (24-34)
packages/arkenv/src/index.test.ts (2)
  • expectTypeOf (32-39)
  • process (53-63)
packages/arkenv/src/type.ts (2)
packages/arkenv/src/scope.ts (1)
  • $ (9-18)
packages/arkenv/src/scope.test.ts (6)
  • stringType (46-50)
  • hostType (11-15)
  • hostType (5-9)
  • envType (33-44)
  • it (4-51)
  • portType (22-26)
apps/www/content/docs/quickstart.mdx (1)
apps/www/components/ui/card.tsx (1)
  • Card (6-8)
packages/arkenv/src/type.test.ts (3)
packages/arkenv/src/type.ts (1)
  • type (3-3)
packages/arkenv/src/scope.test.ts (4)
  • envType (33-44)
  • stringType (46-50)
  • it (4-51)
  • hostType (5-9)
packages/arkenv/src/types.test.ts (2)
  • it (23-37)
  • it (4-21)
apps/www/content/docs/guides/type-function.mdx (3)
packages/arkenv/src/scope.test.ts (5)
  • stringType (46-50)
  • envType (33-44)
  • hostType (5-9)
  • it (4-51)
  • hostType (11-15)
packages/arkenv/src/create-env.ts (1)
  • createEnv (24-34)
packages/arkenv/src/index.test.ts (2)
  • expectTypeOf (32-39)
  • beforeEach (15-98)
packages/arkenv/src/index.ts (1)
packages/arkenv/src/index.test.ts (8)
  • process (81-97)
  • process (53-63)
  • expect (27-30)
  • process (41-51)
  • vi (21-25)
  • process (16-19)
  • arkenv (66-69)
  • createEnv (74-77)
🔇 Additional comments (3)
.changeset/large-taxis-check.md (1)

5-23: Changelog entry is clear and actionable.

Example matches the new API surface and reads well.

apps/www/content/docs/meta.json (1)

9-10: Nav entry added in the right section. LGTM.

apps/www/content/docs/quickstart.mdx (1)

121-125: Card addition is spot-on.

@github-actions github-actions bot added the @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv label Sep 10, 2025
@yamcodes yamcodes merged commit 721c014 into main Sep 10, 2025
6 of 8 checks passed
@yamcodes yamcodes deleted the export-type branch September 10, 2025 20:57
@github-actions github-actions bot mentioned this pull request Sep 10, 2025
yamcodes pushed a commit that referenced this pull request Sep 10, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## arkenv@0.6.0

### Minor Changes

- #### Expose `type` function
_[`#139`](#139)
[`721c014`](721c014)
[@yamcodes](https://github.com/yamcodes)_

ArkEnv now exposes a `type` function with built-in ArkEnv scope,
providing access to environment-specific types like `string.host` and
`number.port`.

    ```ts
    import { type } from "arkenv";

    const env = type({
      NODE_ENV: "string",
      HOST: "string.host",
      PORT: "number.port",
    });

    const result = env.assert({
      NODE_ENV: "development",
      HOST: "localhost",
      PORT: "3000",
    });
    ```

This extends ArkType's `type` function with ArkEnv-specific validations
for common environment variable patterns.

## @arkenv/vite-plugin@0.0.9

### Patch Changes

<details><summary>Updated 1 dependency</summary>

<small>


[`721c014`](721c014)

</small>

-   `arkenv@0.6.0`

</details>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Sep 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 22, 2025
@yamcodes yamcodes mentioned this pull request Jan 1, 2026
@yamcodes yamcodes added this to the v1 milestone Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv arkenv Changes to the `arkenv` npm package. docs Improvements or additions to documentation tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant