Merge branch 'master' into f/badge-subscriptions

# Conflicts:
#	src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt
This commit is contained in:
spacedandy-agents-simplex committed 2026-10-19 09:49:17 +00:00
commit d50488460d
113 files changed
+8786 -10549

No files matched your search

+22 -23
View File
@@ -60,10 +60,7 @@ commandsCodeText =
<> respAliasLine
where
constrName = T.pack $ fstToUpper tag
classDef =
("class " <> constrName <> "(TypedDict):\n")
<> bodyOrPass (fieldsCodePy " " "T." params)
<> "\n"
classDef = typedDictCode constrName (fieldsCodePy "T." params) <> "\n"
cmdStringFunc =
("\ndef " <> constrName <> "_cmd_string(self: " <> constrName <> ") -> str:\n")
<> " return " <> pySelfSyntaxText "T." (fstToUpper tag, params) syntax <> "\n"
@@ -143,9 +140,7 @@ typesCodeText =
"FileProtocol" -> map toUpper m
_ -> m
typeDefCode = case typeDef of
ATDRecord fields ->
("\nclass " <> name' <> "(TypedDict):\n")
<> bodyOrPass (fieldsCodePy " " "" fields)
ATDRecord fields -> "\n" <> typedDictCode name' (fieldsCodePy "" fields)
ATDEnum cs ->
"\n" <> name' <> " = Literal["
<> T.intercalate ", " (map (\m -> "\"" <> T.pack (enumValue m) <> "\"") $ L.toList cs)
@@ -231,9 +226,7 @@ unionTypeCodePy memberName typesNamespace name cs =
constrTypeRef (ATUnionMember tag _) = memberName name tag
tagLiterals = T.intercalate ", " $ map (\(ATUnionMember tag _) -> "\"" <> T.pack tag <> "\"") $ L.toList cs
memberClass (ATUnionMember tag fields) =
("\nclass " <> memberName name tag <> "(TypedDict):\n")
<> (" type: Literal[\"" <> T.pack tag <> "\"]\n")
<> fieldsCodePy " " typesNamespace fields
"\n" <> typedDictCode (memberName name tag) (("type", "Literal[\"" <> T.pack tag <> "\"]", "") : fieldsCodePy typesNamespace fields)
-- | Render the right-hand side of a union alias: either inline (one line) or
-- multi-line wrapped in parentheses with `|` separators between alternatives.
@@ -248,21 +241,27 @@ unionAliasRhs lhs constr cs
(h : t) -> h : map ("| " <>) t
cs' = map constr cs
-- | Emit a body of `pass` if there are no fields, otherwise the rendered
-- fields as-is.
bodyOrPass :: Text -> Text
bodyOrPass body
| T.null body = " pass\n"
| otherwise = body
typedDictCode :: Text -> [(Text, Text, Text)] -> Text
typedDictCode name fields
| any (\(field, _, _) -> field `elem` pyKeywords) fields =
(name <> " = TypedDict(\"" <> name <> "\", {\n")
<> foldMap (\(field, t, comment) -> " \"" <> field <> "\": " <> t <> "," <> comment <> "\n") fields
<> "})\n"
| null fields = "class " <> name <> "(TypedDict):\n pass\n"
| otherwise =
("class " <> name <> "(TypedDict):\n")
<> foldMap (\(field, t, comment) -> " " <> field <> ": " <> t <> comment <> "\n") fields
-- | Render record fields for a TypedDict body. Each field becomes
-- `<indent><name>: <type>[ # <comment>]`. Optional fields wrap the type in
-- `NotRequired[...]`.
fieldsCodePy :: Text -> Text -> [APIRecordField] -> Text
fieldsCodePy indent namespace = foldMap render
pyKeywords :: [Text]
pyKeywords =
["False", "None", "True", "and", "as", "assert", "async", "await", "break", "class", "continue", "def", "del", "elif", "else", "except", "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return", "try", "while", "with", "yield"]
-- | Render record fields for a TypedDict as name, type and comment.
-- Optional fields wrap the type in `NotRequired[...]`.
fieldsCodePy :: Text -> [APIRecordField] -> [(Text, Text, Text)]
fieldsCodePy namespace = map render
where
render (APIRecordField name t) =
indent <> T.pack name <> ": " <> wrapOptional t (typeText t) <> typeComment t <> "\n"
render (APIRecordField name t) = (T.pack name, wrapOptional t (typeText t), typeComment t)
wrapOptional t inner = case t of
ATOptional _ -> "NotRequired[" <> inner <> "]"
_ -> inner
+11 -1
View File
@@ -224,6 +224,7 @@ chatTypesDocsData =
(sti @BadgeServiceErrorCode, STEnum' (consSep "BSE" '_'), "", ["BSEUnknown"], "", ""),
(sti @BlockingInfo, STRecord, "", [], "", ""),
(sti @BlockingReason, STEnum, "BR", [], "", ""),
(sti @BlockToken, STUnion, "", [], "", ""),
(sti @BrokerErrorType, STUnion, "", [], "", ""),
(sti @BusinessChatInfo, STRecord, "", [], "", ""),
(sti @BusinessChatType, STEnum, "BC", [], "", ""),
@@ -285,7 +286,7 @@ chatTypesDocsData =
(sti @FileStatus, STEnum, "FS", [], "", ""),
(sti @FileTransferMeta, STRecord, "", [], "", ""),
(sti @FileType, STEnum' (consLower "FT"), "", [], "", ""),
(sti @Format, STUnion, "", ["Unknown"], "", ""),
(sti @Format, STUnion, "", ["Unknown"], "", "The format markup is a token of block Markdown syntax; its text is the syntax. The format escape is the backslash of a backslash escape. Bold singleStar: written with single stars."),
(sti @FormattedText, STRecord, "", [], "", ""),
(sti @FullGroupPreferences, STRecord, "", [], "", ""),
(sti @FullPreferences, STRecord, "", [], "", ""),
@@ -321,8 +322,10 @@ chatTypesDocsData =
(sti @LinkContent, STUnion, "LC", [], "", ""),
(sti @LinkOwnerSig, STRecord, "", [], "", ""),
(sti @LinkPreview, STRecord, "", [], "", ""),
(sti @ListEntry, STRecord, "", [], "", ""),
(sti @BadgeInfo, STRecord, "", [], "", ""),
(sti @LocalProfile, STRecord, "", [], "", ""),
(sti @MarkdownBlock, STUnion, "", ["UnknownBlock"], "", ""),
(sti @MemberCriteria, STEnum1, "MC", [], "", ""),
(sti @MsgChatLink, STUnion, "MCL", [], "", "Connection link sent in a message - only short links are allowed."),
(sti @MsgContent, STUnion, "MC", [], "", ""),
@@ -371,6 +374,7 @@ chatTypesDocsData =
(sti @ReportReason, STEnum' (dropPfxSfx "RR" ""), "", ["RRUnknown"], "", ""),
(sti @RoleGroupPreference, STRecord, "", [], "", ""),
(sti @SecurityCode, STRecord, "", [], "", ""),
(sti @SegmentRange, STRecord, "", [], "", ""),
(sti @SimplePreference, STRecord, "", [], "", ""),
(sti @SimplexDomain, STRecord, "", [], "", ""),
(sti @SimplexDomainClaim, STRecord, "", [], "", ""),
@@ -391,6 +395,7 @@ chatTypesDocsData =
(sti @SubscriptionStatus, STUnion, "SS", [], "", ""),
(sti @SupportGroupPreference, STRecord, "", [], "", ""),
(sti @SwitchPhase, STEnum, "SP", [], "", ""),
(sti @TableAlign, STEnum, "TA", [], "", ""),
(sti @TimedMessagesGroupPreference, STRecord, "", [], "", ""),
(sti @TimedMessagesPreference, STRecord, "", [], "", ""),
(sti @TransportError, STUnion, "TE", [], "", ""),
@@ -457,6 +462,7 @@ deriving instance Generic BadgeRedeemError
deriving instance Generic BadgeServiceErrorCode
deriving instance Generic BlockingInfo
deriving instance Generic BlockingReason
deriving instance Generic BlockToken
deriving instance Generic BrokerErrorType
deriving instance Generic BusinessChatInfo
deriving instance Generic BusinessChatType
@@ -561,8 +567,10 @@ deriving instance Generic JSONCIStatus
deriving instance Generic LinkContent
deriving instance Generic LinkOwnerSig
deriving instance Generic LinkPreview
deriving instance Generic ListEntry
deriving instance Generic BadgeInfo
deriving instance Generic LocalProfile
deriving instance Generic MarkdownBlock
deriving instance Generic MemberCriteria
deriving instance Generic MsgChatLink
deriving instance Generic MsgContent
@@ -610,6 +618,7 @@ deriving instance Generic RemoteCtrlSessionState
deriving instance Generic RemoteCtrlStopReason
deriving instance Generic ReportReason
deriving instance Generic SecurityCode
deriving instance Generic SegmentRange
deriving instance Generic SimplexDomain
deriving instance Generic SimplexDomainClaim
deriving instance Generic SimplexDomainError
@@ -629,6 +638,7 @@ deriving instance Generic StoreError
deriving instance Generic SubscriptionStatus
deriving instance Generic SupportGroupPreference
deriving instance Generic SwitchPhase
deriving instance Generic TableAlign
deriving instance Generic TimedMessagesGroupPreference
deriving instance Generic TimedMessagesPreference
deriving instance Generic TransportError