A human-friendly DSL for ATProto Lexicons
27
fork

Configure Feed

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

Preserve bool/byte constraints lex->mlf

authored by stavola.xyz and committed by

Tangled 340904f7 e6b00ed8

+40 -2
+14 -2
mlf-cli/src/generate/mlf.rs
··· 827 827 ) -> Result<Rendered, MlfGenerateError> { 828 828 let type_name = type_def.get("type").and_then(|v| v.as_str()); 829 829 830 + // Primitive types that the ATProto spec defines with constraint fields 831 + // are routed through `with_constraints`; it returns an atom when no 832 + // constraint keys are present, so it's equally valid for inputs 833 + // written without any. The spec permits: 834 + // boolean — default, const 835 + // integer — minimum, maximum, enum, default, const 836 + // string — format, min/maxLength, min/maxGraphemes, knownValues, 837 + // enum, default, const (via `render_string`) 838 + // bytes — minLength, maxLength 839 + // blob — accept, maxSize 840 + // `null` and `unknown` have no defined constraint fields and stay 841 + // atomic. 830 842 match type_name { 831 843 Some("null") => Ok(Rendered::atom("null")), 832 - Some("boolean") => Ok(Rendered::atom("boolean")), 844 + Some("boolean") => Ok(Rendered::with_constraints("boolean", type_def, indent_level)), 833 845 Some("integer") => Ok(Rendered::with_constraints("integer", type_def, indent_level)), 834 846 Some("string") => Ok(render_string(type_def, indent_level)), 835 - Some("bytes") => Ok(Rendered::atom("bytes")), 847 + Some("bytes") => Ok(Rendered::with_constraints("bytes", type_def, indent_level)), 836 848 Some("blob") => Ok(Rendered::with_constraints("blob", type_def, indent_level)), 837 849 Some("unknown") => Ok(Rendered::atom("unknown")), 838 850 Some("array") => render_array(type_def, ctx, indent_level),
+13
tests/lexicon_to_mlf/all_constraint_keys/expected.mlf
··· 23 23 default: "active", 24 24 }; 25 25 26 + def type blocked = boolean constrained { 27 + const: true, 28 + }; 29 + 30 + def type flag = boolean constrained { 31 + default: false, 32 + }; 33 + 34 + def type digest = bytes constrained { 35 + minLength: 32, 36 + maxLength: 64, 37 + }; 38 +
+13
tests/lexicon_to_mlf/all_constraint_keys/input.json
··· 26 26 "type": "string", 27 27 "enum": ["active", "inactive"], 28 28 "default": "active" 29 + }, 30 + "blocked": { 31 + "type": "boolean", 32 + "const": true 33 + }, 34 + "flag": { 35 + "type": "boolean", 36 + "default": false 37 + }, 38 + "digest": { 39 + "type": "bytes", 40 + "minLength": 32, 41 + "maxLength": 64 29 42 } 30 43 } 31 44 }