File size: 1,762 Bytes
93d826e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Package definition
package example

// Import statements
import (
    "strings"
    "time"
)

// Schema definitions
#Person: {
    name:     string
    age:      int & >=0 & <=120
    email?:   string & =~"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
    address?: #Address
}

#Address: {
    street:  string
    city:    string
    country: string
    zip:     string & =~"^[0-9]{5}$"
}

// Default values and constraints
#DefaultPerson: #Person & {
    name: string | *"John Doe"
    age:  int | *30
}

// List type definition
#Team: {
    name:    string
    members: [...#Person]
    leader:  #Person
}

// Computed fields
#Employee: #Person & {
    role:    string
    salary:  float
    taxRate: float

    // Computed field
    netSalary: salary * (1 - taxRate)
}

// Concrete values
exampleTeam: #Team & {
    name: "Engineering"
    members: [
        {
            name: "Alice Smith"
            age:  28
            email: "alice@example.com"
        },
        {
            name: "Bob Jones"
            age:  35
            email: "bob@example.com"
        }
    ]
    leader: {
        name:  "Carol Wilson"
        age:   40
        email: "carol@example.com"
    }
}

// Configuration with references and templates
#Config: {
    environment: "development" | "staging" | "production"
    database: {
        host:     string
        port:     int & >0 & <65536
        username: string
        password: string
    }
    features: [string]: bool
}

// Template usage
productionConfig: #Config & {
    environment: "production"
    database: {
        host:     "db.example.com"
        port:     5432
        username: "admin"
        password: "secret"
    }
    features: {
        "feature1": true
        "feature2": false
    }
}