mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-01 20:08:57 +00:00
update @simplex-chat/types
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user