A human-friendly DSL for ATProto Lexicons
27
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update docs to include array constraints

+51 -3
+35 -3
website/content/docs/language-guide/03-constraints.md
··· 107 107 108 108 ## Array Constraints 109 109 110 - Arrays can be constrained by length: 110 + A constraint block written after `T[]` applies to **the array itself** — typically bounding the number of items: 111 111 112 112 ```mlf 113 113 tags: string[] constrained { 114 114 minLength: 1, 115 - maxLength: 10, 115 + maxLength: 10, // at most 10 tags 116 116 } 117 117 118 118 images: Uri[] constrained { 119 - maxLength: 4, 119 + maxLength: 4, // at most 4 image URLs 120 + } 121 + ``` 122 + 123 + ### Constraining Array Items 124 + 125 + To constrain **each item** rather than the array, wrap the item type in parentheses and put the constraint block inside: 126 + 127 + ```mlf 128 + record post { 129 + /// Each tag: at most 100 characters 130 + tags: (string constrained { maxLength: 100 })[], 131 + } 132 + ``` 133 + 134 + Without the parentheses, the constraint binds to the array, not the items. The two forms can also be combined when you need both levels: 135 + 136 + ```mlf 137 + record post { 138 + /// At most 20 tags; each tag at most 50 chars 139 + tags: (string constrained { maxLength: 50 })[] constrained { 140 + maxLength: 20, 141 + }, 142 + } 143 + ``` 144 + 145 + For patterns you'll reuse, naming the constrained item type keeps the field declarations short — see [Custom Types](/docs/language-guide/custom-types/#array-items): 146 + 147 + ```mlf 148 + inline type Tag = string constrained { maxLength: 100 }; 149 + 150 + record post { 151 + tags: Tag[], 120 152 } 121 153 ``` 122 154
+16
website/content/docs/language-guide/04-custom-types.md
··· 71 71 } 72 72 ``` 73 73 74 + ### Array Items 75 + 76 + Inline types are the cleanest way to constrain the items of an array. Writing the constraint directly on `T[]` binds it to the array (see [Array Constraints](/docs/language-guide/constraints/#array-constraints)); defining an inline type for the item lets the field declaration stay short while each element is still validated: 77 + 78 + ```mlf 79 + inline type Tag = string constrained { maxLength: 100 }; 80 + inline type PositiveInt = integer constrained { minimum: 0 }; 81 + 82 + record post { 83 + tags!: Tag[], // each tag constrained to 100 chars 84 + viewCounts!: PositiveInt[], // each integer must be ≥ 0 85 + } 86 + ``` 87 + 88 + This is equivalent to the parenthesized inline form `(string constrained { maxLength: 100 })[]` — pick whichever reads better at the call site. The inline-type form wins when the same shape appears in multiple fields. 89 + 74 90 ## Def Types 75 91 76 92 When you want a type to be **shared and referenced by name** in the generated lexicon, use `def type`: