Update tech_docs/CUE_your_new_friend.md
This commit is contained in:
@@ -220,3 +220,74 @@ CUE replaces **ad-hoc YAML/JSON** with **structured, validated, and reusable** c
|
||||
You can eliminate configuration errors and enforce policies **declaratively**.
|
||||
|
||||
**Next Step**: Try the [CUE Tutorial](https://cuelang.org/docs/tutorials/) or experiment in the **playground**! 🚀
|
||||
|
||||
|
||||
Here’s a **Mermaid.js diagram** that visually explains the CUE lattice (Top, Bottom, Unification, and Disjunction) in a way that’s both accurate and appealing for visual learners. You can embed this directly in your Gitea Markdown files (if Mermaid rendering is enabled):
|
||||
|
||||
```mermaid
|
||||
%% CUE Lattice Diagram
|
||||
graph TD
|
||||
A["⊤ (Top)"] --> B["Concrete Values"]
|
||||
A --> C["Constraints"]
|
||||
B --> D["Unification (&)"]
|
||||
C --> D
|
||||
D --> E["Valid Output"]
|
||||
D --> F["⊥ (Bottom, Invalid)"]
|
||||
B --> G["Disjunction (|)"]
|
||||
C --> G
|
||||
G --> H["Valid Alternative"]
|
||||
|
||||
style A fill:#4CAF50,stroke:#388E3C
|
||||
style F fill:#F44336,stroke:#D32F2F
|
||||
style E fill:#2196F3,stroke:#1976D2
|
||||
style H fill:#FF9800,stroke:#F57C00
|
||||
|
||||
%% Examples
|
||||
I["Example:\nname: string & =~'^[A-Z]'"] --> D
|
||||
J["Example:\nrole: 'admin' | 'user'"] --> G
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### **How to Use in Gitea**:
|
||||
1. Ensure Mermaid is enabled in your Gitea instance (check with admins).
|
||||
2. Paste the above code into a Markdown file (e.g., `README.md`).
|
||||
3. It will render as an interactive diagram.
|
||||
|
||||
---
|
||||
|
||||
### **Diagram Explanation**:
|
||||
1. **`⊤ (Top)`**
|
||||
- The root of all possible values (e.g., `string`, `int`, `{}`).
|
||||
- Branches into **concrete values** (like `"Alice"`) and **constraints** (like `>=18`).
|
||||
|
||||
2. **Unification (`&`)**
|
||||
- Merges constraints (like a strict AND gate).
|
||||
- Outputs either a **valid value** (if constraints are met) or **`⊥` (Bottom)** (if conflicts exist).
|
||||
|
||||
3. **Disjunction (`|`)**
|
||||
- Represents alternatives (like a flexible OR gate).
|
||||
- Outputs the **first valid alternative** (e.g., `"admin" | "user"`).
|
||||
|
||||
4. **`⊥ (Bottom)`**
|
||||
- The "error state" (e.g., `name: 42` when `string` is required).
|
||||
|
||||
---
|
||||
|
||||
### **Why This Works**:
|
||||
- **Visualizes the Lattice**: Shows how CUE narrows possibilities from `⊤` to valid outputs.
|
||||
- **Color-Coded**: Green (Top), Blue (Valid), Red (Error), Orange (Alternatives).
|
||||
- **Includes Examples**: Embedded real CUE snippets for clarity.
|
||||
|
||||
---
|
||||
|
||||
### **Alternate Version (Simpler)**:
|
||||
If you prefer a minimalistic view:
|
||||
```mermaid
|
||||
graph LR
|
||||
T["⊤ (Any Value)"] -->|Unification (&)| U["Valid"]
|
||||
T -->|Conflict| B["⊥ (Invalid)"]
|
||||
T -->|Disjunction (|)| D["A | B | C"]
|
||||
```
|
||||
|
||||
Let me know if you'd like to tweak the design (e.g., add more examples, change layouts)!
|
||||
Reference in New Issue
Block a user