update @simplex-chat/types

This commit is contained in:
Evgeny Poberezkin
2026-01-11 19:15:16 +00:00
parent d50f2e963e
commit da3f89866f
4 changed files with 18 additions and 12 deletions
+9 -8
View File
@@ -58,7 +58,7 @@ responsesCodeText :: Text
responsesCodeText =
("// API Responses\n// " <> autoGenerated <> "\n")
<> "\nimport * as T from \"./types\"\n"
<> unionTypeCode "CR" "T." chatRespTypeDef chatRespConstrs ""
<> unionTypeCode True "CR" "T." chatRespTypeDef chatRespConstrs ""
where
chatRespTypeDef = APITypeDef {typeName' = "ChatResponse", typeDef = ATDUnion chatRespConstrs}
chatRespConstrs = L.fromList $ map responseType chatResponsesDocs
@@ -67,7 +67,7 @@ eventsCodeText :: Text
eventsCodeText =
("// API Events\n// " <> autoGenerated <> "\n")
<> "\nimport * as T from \"./types\"\n"
<> unionTypeCode "CEvt" "T." chatEventTypeDef chatEventConstrs ""
<> unionTypeCode True "CEvt" "T." chatEventTypeDef chatEventConstrs ""
where
chatEventTypeDef = APITypeDef {typeName' = "ChatEvent", typeDef = ATDUnion chatEventConstrs}
chatEventConstrs = L.fromList $ concatMap catEvents chatEventsDocs
@@ -98,18 +98,19 @@ typesCodeText = ("// API Types\n// " <> autoGenerated <> "\n") <> foldMap typeCo
<> foldMap (\m -> " " <> constrName m <> " = \"" <> T.pack m <> "\",\n") cs
<> "}\n"
<> (if typeSyntax == "" then "" else namespaceFuncCode)
ATDUnion cs -> unionTypeCode name' "" td cs typeSyntax
ATDUnion cs -> unionTypeCode False name' "" td cs typeSyntax
unionTypeCode :: Text -> String -> APITypeDef -> L.NonEmpty ATUnionMember -> Expr -> Text
unionTypeCode unionNamespace typesNamespace td@APITypeDef {typeName' = name} cs cmdSyntax =
("\nexport type " <> name' <> " = " <> constrsCode "" name' constrTypeRef (L.toList cs) <> "\n")
unionTypeCode :: Bool -> Text -> String -> APITypeDef -> L.NonEmpty ATUnionMember -> Expr -> Text
unionTypeCode openUnion unionNamespace typesNamespace td@APITypeDef {typeName' = name} cs cmdSyntax =
("\nexport type " <> name' <> " = " <> constrsCode "" name' constrTypeRef (L.toList cs) <> openStr "" (unionNamespace <> ".Interface") <> "\n")
<> ("export namespace " <> unionNamespace <> " {\n")
<> (" export type Tag = " <> constrsCode " " name' constrTag (L.toList cs) <> "\n")
<> (" interface Interface {\n type: Tag\n }\n")
<> (" export type Tag = " <> constrsCode " " name' constrTag (L.toList cs) <> openStr " " "string" <> "\n")
<> (" " <> (if openUnion then "export " else "") <> "interface Interface {\n type: Tag\n }\n")
<> foldMap constrType cs
<> (if cmdSyntax == "" then "" else funcCode td typesNamespace cmdSyntax)
<> "}\n"
where
openStr indent s = if openUnion then indent <> " | " <> s <> "\n" else ""
name' = T.pack name
constrTypeRef (ATUnionMember tag _) = unionNamespace <> "." <> constrName tag
constrTag (ATUnionMember tag _) = T.pack $ "\"" <> tag <> "\""
@@ -1,11 +1,12 @@
{
"name": "@simplex-chat/types",
"version": "6.5.0-beta.3",
"version": "0.2.1",
"description": "TypeScript types for SimpleX Chat bot libraries",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist",
"src"
],
"publishConfig": {
"access": "public",
@@ -49,6 +49,7 @@ export type ChatEvent =
| CEvt.MessageError
| CEvt.ChatError
| CEvt.ChatErrors
| CEvt.Interface
export namespace CEvt {
export type Tag =
@@ -97,8 +98,9 @@ export namespace CEvt {
| "messageError"
| "chatError"
| "chatErrors"
| string
interface Interface {
export interface Interface {
type: Tag
}
@@ -52,6 +52,7 @@ export type ChatResponse =
| CR.UserProfileUpdated
| CR.UserProfileNoChange
| CR.UsersList
| CR.Interface
export namespace CR {
export type Tag =
@@ -103,8 +104,9 @@ export namespace CR {
| "userProfileUpdated"
| "userProfileNoChange"
| "usersList"
| string
interface Interface {
export interface Interface {
type: Tag
}