a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

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

fix(lex-cli): allow setting default value for const/enum values

Mary e2970ab7 7918bff7

+18 -33
+5
.changeset/fiery-pens-drive.md
··· 1 + --- 2 + '@atcute/lex-cli': patch 3 + --- 4 + 5 + allow setting default value for const/enum values
+13 -33
packages/lexicons/lex-cli/src/codegen.ts
··· 773 773 774 774 // LexPrimitive 775 775 case 'boolean': { 776 + let call = `${PURE} v.boolean()`; 777 + 776 778 if (spec.const !== undefined) { 777 - return `${PURE} v.literal(${spec.const})`; 779 + call = `${PURE} v.literal(${spec.const})`; 778 780 } 779 781 780 - let call = `${PURE} v.boolean()`; 781 - 782 782 if (spec.default !== undefined) { 783 783 call = `${PURE} v.optional(${call}, ${lit(spec.default)})`; 784 784 } ··· 786 786 return call; 787 787 } 788 788 case 'integer': { 789 - if (spec.const !== undefined) { 790 - return `${PURE} v.literal(${lit(spec.const)})`; 791 - } 792 - 793 - if (spec.enum !== undefined) { 794 - let call = `${PURE} v.literalEnum(${lit(spec.enum.toSorted())})`; 795 - 796 - if (spec.default !== undefined) { 797 - call = `${PURE} v.optional(${call}, ${lit(spec.default)})`; 798 - } 799 - 800 - return call; 801 - } 802 - 803 789 let pipe: string[] = []; 804 790 805 791 if ((spec.minimum ?? 0) > 0 || spec.maximum !== undefined) { ··· 812 798 813 799 let call = `${PURE} v.integer()`; 814 800 815 - if (pipe.length !== 0) { 801 + if (spec.const !== undefined) { 802 + call = `${PURE} v.literal(${lit(spec.const)})`; 803 + } else if (spec.enum !== undefined) { 804 + call = `${PURE} v.literalEnum(${lit(spec.enum.toSorted())})`; 805 + } else if (pipe.length !== 0) { 816 806 call = `${PURE} v.constrain(${call}, [ ${pipe.join(', ')} ])`; 817 807 } 818 808 ··· 823 813 return call; 824 814 } 825 815 case 'string': { 826 - if (spec.const !== undefined) { 827 - return `${PURE} v.literal(${lit(spec.const)})`; 828 - } 829 - 830 - if (spec.enum !== undefined) { 831 - let call = `${PURE} v.literalEnum(${lit(spec.enum.toSorted())})`; 832 - 833 - if (spec.default !== undefined) { 834 - call = `${PURE} v.optional(${call}, ${lit(spec.default)})`; 835 - } 836 - 837 - return call; 838 - } 839 - 840 816 let pipe: string[] = []; 841 817 842 818 if ((spec.minLength ?? 0) > 0 || spec.maxLength !== undefined) { ··· 908 884 } 909 885 } 910 886 911 - if (pipe.length !== 0) { 887 + if (spec.const !== undefined) { 888 + call = `${PURE} v.literal(${lit(spec.const)})`; 889 + } else if (spec.enum !== undefined) { 890 + call = `${PURE} v.literalEnum(${lit(spec.enum.toSorted())})`; 891 + } else if (pipe.length !== 0) { 912 892 call = `${PURE} v.constrain(${call}, [ ${pipe.join(', ')} ])`; 913 893 } 914 894