[fix] fix moon fmt problem in readme files, pass `moon fmt --check` and `moon fmt`.
This commit is contained in:
parent
914d1cda31
commit
4f4f6a0e37
|
|
@ -25,7 +25,7 @@ In LLM Tool Calling, the model often produces **multiple errors at once** and **
|
|||
|
||||
## 🚀 Quick Start
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
let schema = @moon_zod.object({
|
||||
"name": @moon_zod.string().min(2).max(50),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
@ -221,7 +221,7 @@ moon run examples/json2schema # JSON → moon_zod schema
|
|||
| `object(Map[String, Schema], required_error?, invalid_type_error?)` | Validates objects. **Default: Strip mode** |
|
||||
| `enum_values(Array[String], required_error?, invalid_type_error?)` | Fixed set of allowed string values |
|
||||
| `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**: Constant value validation — only accepts exact JSON match |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent, need to truly implement |
|
||||
| `any(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value (pass-through) |
|
||||
| `unknown(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value as unknown (semantic marker) |
|
||||
| `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**: Transform raw input first, then validate against inner schema |
|
||||
|
|
@ -300,7 +300,7 @@ moon run examples/json2schema # JSON → moon_zod schema
|
|||
|
||||
### Core Types
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct ValidationError {
|
||||
path : String
|
||||
|
|
@ -331,7 +331,7 @@ moon run cmd/json2schema -- '{"hello": "world"}'
|
|||
|
||||
Output (copy-paste ready moon_zod code):
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"hello": @moon_zod.string(),
|
||||
})
|
||||
|
|
@ -369,7 +369,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json
|
|||
|
||||
Output:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"name": @moon_zod.string().min(2),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
@ -397,12 +397,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ
|
|||
|
||||
Output:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct Root {
|
||||
name : String
|
||||
age : Int64 // int
|
||||
age : Int64 // int
|
||||
} derive(ToJson, FromJson)
|
||||
|
||||
///|
|
||||
pub fn Root::to_schema() -> @moon_zod.Schema {
|
||||
let root = @moon_zod.object({
|
||||
"name": @moon_zod.string(),
|
||||
|
|
@ -558,7 +560,7 @@ Schema-to-Prompt (TS interface): ← auto-generated by schema_to_prompt(
|
|||
|
||||
moon_zod is designed for the **error feedback loop** — the key pattern that makes AI agents reliable:
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
/// Retry loop: validate → collect errors → feed back → retry
|
||||
fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) {
|
||||
|
|
@ -611,13 +613,33 @@ Product → uses type name `Product`
|
|||
Then **LLM sees only the definitions it needs**, reducing token count and improving clarity.
|
||||
|
||||
**Example usage:**
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
// Define named schemas
|
||||
let user_schema = @moon_zod.object({ ... }).name("User")
|
||||
let order_schema = @moon_zod.object({ ... }).name("Order")
|
||||
let product_schema = @moon_zod.object({ ... }).name("Product")
|
||||
|
||||
///|
|
||||
let user_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("User")
|
||||
|
||||
///|
|
||||
let order_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Order")
|
||||
|
||||
///|
|
||||
let product_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Product")
|
||||
|
||||
// Auto-extract + generate modular prompt
|
||||
|
||||
///|
|
||||
let prompt = @moon_zod.schema_to_prompt_named(user_schema)
|
||||
// Output:
|
||||
// export interface User { ... }
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ MoonBit 运行时 JSON Schema 校验库,受 [Zod](https://zod.dev) 和 [Pydant
|
|||
|
||||
## 🚀 快速开始
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
let schema = @moon_zod.object({
|
||||
"name": @moon_zod.string().min(2).max(50),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
@ -216,7 +216,7 @@ moon run examples/json2schema # JSON → moon_zod Schema
|
|||
| `object(Map[String, Schema], required_error?, invalid_type_error?)` | 校验对象。**默认:Strip 模式** |
|
||||
| `enum_values(Array[String], required_error?, invalid_type_error?)` | 固定的允许字符串值集合 |
|
||||
| `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**:常量值校验 — 仅接受完全匹配的 JSON |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图 |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图,有待真正实现 |
|
||||
| `any(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值(透传) |
|
||||
| `unknown(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值作为未知类型(语义标记) |
|
||||
| `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**:先转换原始输入,再针对内部 schema 进行校验 |
|
||||
|
|
@ -295,7 +295,7 @@ moon run examples/json2schema # JSON → moon_zod Schema
|
|||
|
||||
### 核心类型
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct ValidationError {
|
||||
path : String
|
||||
|
|
@ -326,7 +326,7 @@ moon run cmd/json2schema -- '{"hello": "world"}'
|
|||
|
||||
输出(可直接复制粘贴的moon_zod代码):
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"hello": @moon_zod.string(),
|
||||
})
|
||||
|
|
@ -364,7 +364,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json
|
|||
|
||||
输出:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"name": @moon_zod.string().min(2),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
@ -392,12 +392,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ
|
|||
|
||||
输出:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct Root {
|
||||
name : String
|
||||
age : Int64 // int
|
||||
age : Int64 // int
|
||||
} derive(ToJson, FromJson)
|
||||
|
||||
///|
|
||||
pub fn Root::to_schema() -> @moon_zod.Schema {
|
||||
let root = @moon_zod.object({
|
||||
"name": @moon_zod.string(),
|
||||
|
|
@ -550,7 +552,7 @@ Schema-to-Prompt (TS 接口): ← 由 schema_to_prompt() 自动
|
|||
|
||||
moon_zod 为**错误反馈循环**而设计 — 这是使 AI 智能体可靠的关键模式:
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
/// 重试循环:校验 → 收集错误 → 反馈 → 重试
|
||||
fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) {
|
||||
|
|
@ -603,13 +605,33 @@ Product → 使用类型名称 `Product`
|
|||
然后 **LLM 仅看到它需要的定义**,减少 Token 计数并提高清晰度。
|
||||
|
||||
**使用示例:**
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
// 定义命名 Schema
|
||||
let user_schema = @moon_zod.object({ ... }).name("User")
|
||||
let order_schema = @moon_zod.object({ ... }).name("Order")
|
||||
let product_schema = @moon_zod.object({ ... }).name("Product")
|
||||
|
||||
///|
|
||||
let user_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("User")
|
||||
|
||||
///|
|
||||
let order_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Order")
|
||||
|
||||
///|
|
||||
let product_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Product")
|
||||
|
||||
// 自动提取 + 生成模块化提示词
|
||||
|
||||
///|
|
||||
let prompt = @moon_zod.schema_to_prompt_named(user_schema)
|
||||
// 输出:
|
||||
// export interface User { ... }
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
| `object(Map[String, Schema], required_error?, invalid_type_error?)` | Validates objects. **Default: Strip mode** |
|
||||
| `enum_values(Array[String], required_error?, invalid_type_error?)` | Fixed set of allowed string values |
|
||||
| `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**: Constant value validation — only accepts exact JSON match |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent, need to truly implement |
|
||||
| `any(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value (pass-through) |
|
||||
| `unknown(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value as unknown (semantic marker) |
|
||||
| `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**: Transform raw input first, then validate against inner schema |
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
### Core Types
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct ValidationError {
|
||||
path : String
|
||||
|
|
|
|||
10
docs/CLI.md
10
docs/CLI.md
|
|
@ -8,7 +8,7 @@ moon run cmd/json2schema -- '{"hello": "world"}'
|
|||
|
||||
Output (copy-paste ready moon_zod code):
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"hello": @moon_zod.string(),
|
||||
})
|
||||
|
|
@ -46,7 +46,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json
|
|||
|
||||
Output:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"name": @moon_zod.string().min(2),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
@ -74,12 +74,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ
|
|||
|
||||
Output:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct Root {
|
||||
name : String
|
||||
age : Int64 // int
|
||||
age : Int64 // int
|
||||
} derive(ToJson, FromJson)
|
||||
|
||||
///|
|
||||
pub fn Root::to_schema() -> @moon_zod.Schema {
|
||||
let root = @moon_zod.object({
|
||||
"name": @moon_zod.string(),
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ Schema-to-Prompt (TS interface): ← auto-generated by schema_to_prompt(
|
|||
|
||||
moon_zod is designed for the **error feedback loop** — the key pattern that makes AI agents reliable:
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
/// Retry loop: validate → collect errors → feed back → retry
|
||||
fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) {
|
||||
|
|
@ -149,13 +149,33 @@ Product → uses type name `Product`
|
|||
Then **LLM sees only the definitions it needs**, reducing token count and improving clarity.
|
||||
|
||||
**Example usage:**
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
// Define named schemas
|
||||
let user_schema = @moon_zod.object({ ... }).name("User")
|
||||
let order_schema = @moon_zod.object({ ... }).name("Order")
|
||||
let product_schema = @moon_zod.object({ ... }).name("Product")
|
||||
|
||||
///|
|
||||
let user_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("User")
|
||||
|
||||
///|
|
||||
let order_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Order")
|
||||
|
||||
///|
|
||||
let product_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Product")
|
||||
|
||||
// Auto-extract + generate modular prompt
|
||||
|
||||
///|
|
||||
let prompt = @moon_zod.schema_to_prompt_named(user_schema)
|
||||
// Output:
|
||||
// export interface User { ... }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ In LLM Tool Calling, the model often produces **multiple errors at once** and **
|
|||
|
||||
## 🚀 Quick Start
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
let schema = @moon_zod.object({
|
||||
"name": @moon_zod.string().min(2).max(50),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
| `object(Map[String, Schema], required_error?, invalid_type_error?)` | 校验对象。**默认:Strip 模式** |
|
||||
| `enum_values(Array[String], required_error?, invalid_type_error?)` | 固定的允许字符串值集合 |
|
||||
| `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**:常量值校验 — 仅接受完全匹配的 JSON |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图 |
|
||||
| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图,有待真正实现 |
|
||||
| `any(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值(透传) |
|
||||
| `unknown(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值作为未知类型(语义标记) |
|
||||
| `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**:先转换原始输入,再针对内部 schema 进行校验 |
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
### 核心类型
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct ValidationError {
|
||||
path : String
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ moon run cmd/json2schema -- '{"hello": "world"}'
|
|||
|
||||
输出(可直接复制粘贴的moon_zod代码):
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"hello": @moon_zod.string(),
|
||||
})
|
||||
|
|
@ -46,7 +46,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json
|
|||
|
||||
输出:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
@moon_zod.object({
|
||||
"name": @moon_zod.string().min(2),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
@ -74,12 +74,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ
|
|||
|
||||
输出:
|
||||
|
||||
```moonbit
|
||||
```moonbit nocheck
|
||||
///|
|
||||
pub struct Root {
|
||||
name : String
|
||||
age : Int64 // int
|
||||
age : Int64 // int
|
||||
} derive(ToJson, FromJson)
|
||||
|
||||
///|
|
||||
pub fn Root::to_schema() -> @moon_zod.Schema {
|
||||
let root = @moon_zod.object({
|
||||
"name": @moon_zod.string(),
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ Schema-to-Prompt (TS 接口): ← 由 schema_to_prompt() 自动
|
|||
|
||||
moon_zod 为**错误反馈循环**而设计 — 这是使 AI 智能体可靠的关键模式:
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
///|
|
||||
/// 重试循环:校验 → 收集错误 → 反馈 → 重试
|
||||
fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) {
|
||||
|
|
@ -150,13 +150,33 @@ Product → 使用类型名称 `Product`
|
|||
然后 **LLM 仅看到它需要的定义**,减少 Token 计数并提高清晰度。
|
||||
|
||||
**使用示例:**
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
// 定义命名 Schema
|
||||
let user_schema = @moon_zod.object({ ... }).name("User")
|
||||
let order_schema = @moon_zod.object({ ... }).name("Order")
|
||||
let product_schema = @moon_zod.object({ ... }).name("Product")
|
||||
|
||||
///|
|
||||
let user_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("User")
|
||||
|
||||
///|
|
||||
let order_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Order")
|
||||
|
||||
///|
|
||||
let product_schema = @moon_zod.object(
|
||||
{
|
||||
...
|
||||
},
|
||||
).name("Product")
|
||||
|
||||
// 自动提取 + 生成模块化提示词
|
||||
|
||||
///|
|
||||
let prompt = @moon_zod.schema_to_prompt_named(user_schema)
|
||||
// 输出:
|
||||
// export interface User { ... }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
## 🚀 快速开始
|
||||
|
||||
```mbt nocheck
|
||||
```moonbit nocheck
|
||||
let schema = @moon_zod.object({
|
||||
"name": @moon_zod.string().min(2).max(50),
|
||||
"age": @moon_zod.number().int().min(0).max(150),
|
||||
|
|
|
|||
Loading…
Reference in New Issue