From da3f89866f01350db4ad265c4fe59ac45fa68b55 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 11 Jan 2026 19:15:16 +0000 Subject: [PATCH] update @simplex-chat/types --- bots/src/API/Docs/Generate/TypeScript.hs | 17 +++++++++-------- .../types/typescript/package.json | 5 +++-- .../types/typescript/src/events.ts | 4 +++- .../types/typescript/src/responses.ts | 4 +++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/bots/src/API/Docs/Generate/TypeScript.hs b/bots/src/API/Docs/Generate/TypeScript.hs index c3049c100d..45fdd4c21c 100644 --- a/bots/src/API/Docs/Generate/TypeScript.hs +++ b/bots/src/API/Docs/Generate/TypeScript.hs @@ -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 <> "\"" diff --git a/packages/simplex-chat-client/types/typescript/package.json b/packages/simplex-chat-client/types/typescript/package.json index af4f594ded..a1283b1178 100644 --- a/packages/simplex-chat-client/types/typescript/package.json +++ b/packages/simplex-chat-client/types/typescript/package.json @@ -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", diff --git a/packages/simplex-chat-client/types/typescript/src/events.ts b/packages/simplex-chat-client/types/typescript/src/events.ts index d7a0419bbe..66d4d903de 100644 --- a/packages/simplex-chat-client/types/typescript/src/events.ts +++ b/packages/simplex-chat-client/types/typescript/src/events.ts @@ -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 } diff --git a/packages/simplex-chat-client/types/typescript/src/responses.ts b/packages/simplex-chat-client/types/typescript/src/responses.ts index 684aeec7af..cabebed5cf 100644 --- a/packages/simplex-chat-client/types/typescript/src/responses.ts +++ b/packages/simplex-chat-client/types/typescript/src/responses.ts @@ -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 }