mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-07 09:07:43 +00:00
bots api: fix typescript code, add start/stop commands (#6565)
This commit is contained in:
@@ -49,7 +49,7 @@ commandsCodeText =
|
||||
<> "}\n\n"
|
||||
<> ("export namespace " <> T.pack constrName <> " {\n")
|
||||
<> (" export type Response = " <> constrsCode " " "CR" (("CR." <> ) . T.pack . fstToUpper . memberTag) (map responseType responses))
|
||||
<> (if syntax == "" then "" else funcCode APITypeDef {typeName' = constrName, typeDef = ATDRecord params} syntax)
|
||||
<> (if syntax == "" then "" else funcCode APITypeDef {typeName' = constrName, typeDef = ATDRecord params} "T." syntax)
|
||||
<> "}\n"
|
||||
where
|
||||
constrName = fstToUpper tag
|
||||
@@ -86,7 +86,7 @@ typesCodeText = ("// API Types\n// " <> autoGenerated <> "\n") <> foldMap typeCo
|
||||
"ConnectionMode" -> T.pack $ map toUpper tag
|
||||
"FileProtocol" -> T.pack $ map toUpper tag
|
||||
_ -> T.replace "-" "_" $ T.pack $ fstToUpper tag
|
||||
namespaceFuncCode = "\nexport namespace " <> name' <> " {" <> funcCode td typeSyntax <> "}\n"
|
||||
namespaceFuncCode = "\nexport namespace " <> name' <> " {" <> funcCode td "" typeSyntax <> "}\n"
|
||||
typeDefCode = case typeDef of
|
||||
ATDRecord fields ->
|
||||
("\nexport interface " <> name' <> " {\n")
|
||||
@@ -107,7 +107,7 @@ unionTypeCode unionNamespace typesNamespace td@APITypeDef {typeName' = name} cs
|
||||
<> (" export type Tag = " <> constrsCode " " name' constrTag (L.toList cs) <> "\n")
|
||||
<> (" interface Interface {\n type: Tag\n }\n")
|
||||
<> foldMap constrType cs
|
||||
<> (if cmdSyntax == "" then "" else funcCode td cmdSyntax)
|
||||
<> (if cmdSyntax == "" then "" else funcCode td typesNamespace cmdSyntax)
|
||||
<> "}\n"
|
||||
where
|
||||
name' = T.pack name
|
||||
@@ -128,9 +128,9 @@ constrsCode indent name' constr cs
|
||||
line = T.intercalate " | " cs'
|
||||
cs' = map constr cs
|
||||
|
||||
funcCode :: APITypeDef -> Expr -> Text
|
||||
funcCode td@APITypeDef {typeName' = name, typeDef} cmdSyntax =
|
||||
"\n export function cmdString(" <> param <> ": " <> T.pack name <> "): string {\n return " <> jsSyntaxText True (name, self : typeFields) cmdSyntax <> "\n }\n"
|
||||
funcCode :: APITypeDef -> String -> Expr -> Text
|
||||
funcCode td@APITypeDef {typeName' = name, typeDef} typeNamespace cmdSyntax =
|
||||
"\n export function cmdString(" <> param <> ": " <> T.pack name <> "): string {\n return " <> jsSyntaxText True typeNamespace (name, self : typeFields) cmdSyntax <> "\n }\n"
|
||||
where
|
||||
param = if hasParams cmdSyntax then "self" else "_self"
|
||||
self = APIRecordField "self" (ATDef td)
|
||||
|
||||
Reference in New Issue
Block a user