Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-updates",
"--disable-workspace-trust",
"--skip-release-notes",
"--skip-welcome",
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode"
],
"outFiles": ["${workspaceFolder}/extensions/vscode/dist/*.js"],
"sourceMaps": true
},
{
"name": "Attach to Server",
"type": "node",
"request": "attach",
"port": 6009,
"restart": true,
"outFiles": ["${workspaceRoot}/*/*/dist/**/*.js"],
"skipFiles": ["<node_internals>/**"]
}
]
}
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"readme",
"website",
"valype & plugin",
"typescript"
"typescript",
"vscode",
"language-server",
"language-core",
"language-tools",
"website & readme"
],
"cSpell.words": [
"intf",
Expand Down
68 changes: 45 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- 🔌 Seamless unplugin integration (Vite/Rollup/esbuild/Astro/Farm/Nuxt/Rspack/Webpack)
- 🛡️ Unified type validation
- 💻 TypeScript plugin for IDE support
- 🚧 IDE/editor extension support (WIP)
- 🛠️ IDE/editor extension support

Valype = Validate + Type. Automatically generates runtime validators from TypeScript type definitions.

Expand Down Expand Up @@ -57,27 +57,7 @@ bun add -D unplugin-valype

2. Configure plugin for your build tool following [unplugin-valype docs](./packages/plugin/README.md)

3. For TypeScript language support, install the plugin:

```bash
npm install -D @valype/typescript-plugin
```

Then add to your tsconfig.json:

```json
{
"compilerOptions": {
"plugins": [
{
"name": "@valype/typescript-plugin"
}
]
}
}
```

> For VSCode users, ensure you're using the workspace version of TypeScript
3. For TypeScript language support, see [Editor Integration](#-editor-integration) below.

4. Define your types (use `.valype.ts` extension):

Expand All @@ -89,7 +69,7 @@ export interface User {
}
```

4. Use the generated validator:
5. Use the generated validator:

```typescript
import { validateUser } from './user.valype'
Expand Down Expand Up @@ -122,6 +102,48 @@ export declare function validateSome(data: unknown): ZodIssue[] | undefined
| [valype](https://www.npmjs.com/package/valype) | [![valype version](https://img.shields.io/npm/v/valype?color=a1b858&label=)](https://www.npmjs.com/package/valype) | Core schema generation logic |
| [unplugin-valype](https://www.npmjs.com/package/unplugin-valype) | [![unplugin-valype version](https://img.shields.io/npm/v/unplugin-valype?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-valype) | Build tool plugin |

## 🧑‍💻 Editor Integration

### VSCode Extension

You can get instant type hints, code completion, and go-to-definition for `.valype.ts` files by installing the [Valype VSCode extension](https://marketplace.visualstudio.com/items?itemName=yuzheng14.vscode-valype).

- No manual tsconfig plugin configuration required
- Works out of the box for all `.valype.ts` files
- Supports type checking, completion, navigation, and more

Just search for "Valype" in the VSCode Extensions Marketplace and install.

### TypeScript Language Service Plugin

If you want to manually configure or use in other editors, you can install the TypeScript language service plugin:

```bash
npm install -D @valype/typescript-plugin
```

Then add to your tsconfig.json:

```json
{
"compilerOptions": {
"plugins": [
{
"name": "@valype/typescript-plugin"
}
]
}
}
```

This enables type hints, completion, and navigation for `.valype.ts` files in any editor that supports TypeScript plugins.

> [!TIP]
> If you use this plugin in VSCode, for the best type experience, set VSCode to use the workspace TypeScript version:
> 1. Open a TypeScript file in VSCode
> 2. Click the TypeScript version number in the status bar
> 3. Select "Use Workspace Version"

## 💡 Motivation

While TypeScript ensures compile-time type safety, runtime data validation remains essential. Traditional solutions like Zod require duplicate type definitions and lose valuable tsdoc information. Valype solves this by:
Expand Down
52 changes: 48 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
- 🎯 类型安全的验证与 TypeScript 类型推断
- 🔌 无缝的 unplugin 集成 (Vite/Rollup/esbuild/Astro/Farm/Nuxt/Rspack/Webpack)
- 🛡️ 统一的类型验证
- 🚧 TypeScript 插件 (开发中)
- 🚧 IDE/编辑器扩展支持 (开发中)
- 💻 TypeScript 插件
- 🛠️ IDE/编辑器扩展支持

Valype = Validate + Type。自动从 TypeScript 类型定义生成运行时验证器。

Expand Down Expand Up @@ -57,7 +57,9 @@ bun add -D unplugin-valype

2. 根据 [unplugin-valype 文档](./packages/plugin/README.md) 为你的构建工具配置插件

3. 定义你的类型 (使用 `.valype.ts` 扩展名):
3. TypeScript 语言支持请参考下方 [编辑器集成](#-编辑器集成)。

4. 定义你的类型 (使用 `.valype.ts` 扩展名):

```typescript
// user.valype.ts
Expand All @@ -67,7 +69,7 @@ export interface User {
}
```

4. 使用生成的验证器:
5. 使用生成的验证器:

```typescript
import { validateUser } from './user.valype'
Expand Down Expand Up @@ -100,6 +102,48 @@ export declare function validateSome(data: unknown): ZodIssue[] | undefined
| [valype](https://www.npmjs.com/package/valype) | [![valype 版本](https://img.shields.io/npm/v/valype?color=a1b858&label=)](https://www.npmjs.com/package/valype) | 核心模式生成逻辑 |
| [unplugin-valype](https://www.npmjs.com/package/unplugin-valype) | [![unplugin-valype 版本](https://img.shields.io/npm/v/unplugin-valype?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-valype) | 构建工具插件 |

## 🧑‍💻 编辑器集成

### VSCode 扩展

只需安装 [Valype VSCode 扩展](https://marketplace.visualstudio.com/items?itemName=yuzheng14.vscode-valype),即可在 `.valype.ts` 文件中获得类型提示、补全、跳转等 IDE 体验。

- 无需手动配置 tsconfig 插件
- 对所有 `.valype.ts` 文件开箱即用
- 支持类型检查、补全、跳转等

在 VSCode 扩展市场搜索 “Valype” 并安装即可。

### TypeScript 语言服务插件

如需手动配置或在其他编辑器中使用,可以安装 TypeScript 语言服务插件:

```bash
npm install -D @valype/typescript-plugin
```

然后在 tsconfig.json 中添加:

```json
{
"compilerOptions": {
"plugins": [
{
"name": "@valype/typescript-plugin"
}
]
}
}
```

这样可以在支持 TypeScript 插件的编辑器中为 `.valype.ts` 文件启用类型提示、补全和跳转。

> [!TIP]
> 如果你在 VSCode 中使用该插件,为获得最佳类型体验,请设置为使用工作区的 TypeScript 版本:
> 1. 打开任意 TypeScript 文件
> 2. 点击状态栏中的 TypeScript 版本号
> 3. 选择“使用工作区版本”

## 💡 项目动机

TypeScript 提供了编译时的类型安全,但在运行时我们仍需要验证外部数据。传统方案(如 Zod)要求重复定义类型且会丢失代码提示文档(tsdoc)。Valype 通过自动生成运行时验证器,完美解决了这些问题:
Expand Down
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading