| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Wasm.Api.TypeScriptDefs
Description
This module defines a basic AST for generating TypeScript declaration files, and basic pretty-printing functionality.
The reason we define a custom tool for generating TypeScript declaration files is that existing libraries like `aeson-typescript` and `servant-typescript` are not aimed at generating custom TypeScript interface declaration files for a specific API, but rather at generating TypeScript interfaces for Haskell data types and servant HTTP APIs respectively. And other libraries that align with our needs, like `language-typescript`, are not actively maintained.
Synopsis
- writeTypeScriptToDir :: FilePath -> TypeScriptFile -> IO ()
- buildMultilineComment :: Int -> [String] -> Builder
- data TypeScriptFile = TypeScriptFile {}
- buildTypeScriptFile :: TypeScriptFile -> Builder
- data Declaration = Declaration {}
- buildDeclaration :: Declaration -> Builder
- data DeclarationType
- buildDeclarationType :: DeclarationType -> Builder
- data GroupedInterfaceContent
- buildGroupedInterfaceContent :: Int -> GroupedInterfaceContent -> Builder
- data InterfaceContentGroup = InterfaceContentGroup {}
- data FunctionParam = FunctionParam {}
- buildFunctionParam :: FunctionParam -> Builder
- data FunctionHeader = FunctionHeader {}
- buildFunctionHeader :: FunctionHeader -> Builder
- data InterfaceContent = InterfaceContent {}
- buildInterfaceContent :: Int -> InterfaceContent -> Builder
- data InterfaceContentType
- buildInterfaceContentType :: InterfaceContentType -> Builder
- mconcatWith :: Builder -> [Builder] -> Builder
Documentation
writeTypeScriptToDir :: FilePath -> TypeScriptFile -> IO () Source #
Output the TypeScript declaration files to the specified directory.
buildMultilineComment :: Int -> [String] -> Builder Source #
Creates a builder for a JavaScript-style multiline comment
with the specified indentation level (in spaces) and each line
in the list of strings as a separate line in the comment.
The first line starts with /**, subsequent lines (corresponding
to each line in the list) start with ` * `,
and the last line ends with ` */`.
The indentation level is used to indent the entire comment block.
data TypeScriptFile Source #
Represents the top-level structure of a TypeScript declaration file.
Constructors
| TypeScriptFile | |
Fields
| |
buildTypeScriptFile :: TypeScriptFile -> Builder Source #
Creates a builder for a TypeScript declaration file. It adds a comment to the top of the file with the file name.
data Declaration Source #
Wraps a TypeScript declaration with a comment.
The TypeScript declaration can have any of the types
defined by DeclarationType.
Constructors
| Declaration | |
Fields
| |
buildDeclaration :: Declaration -> Builder Source #
Creates a builder for a TypeScript declaration.
data DeclarationType Source #
Represents a TypeScript declaration content of some type.
Constructors
| ExportDec | Export declaration. |
| FunctionDec FunctionHeader | Function declaration. |
| InterfaceDec | Interface declaration. |
Fields
| |
| ImportDec | Reference to import another TypeScript declaration file. |
buildDeclarationType :: DeclarationType -> Builder Source #
Creates a builder for a TypeScript declaration type and content.
data GroupedInterfaceContent Source #
Constructors
| GroupedInterfaceContent InterfaceContentGroup | A group of interface contents (potentially with subgroups). |
| SingleInterfaceContent InterfaceContent | A single interface content. |
data InterfaceContentGroup Source #
Constructors
| InterfaceContentGroup | |
Fields
| |
buildFunctionParam :: FunctionParam -> Builder Source #
Creates a builder for a TypeScript function parameter.
data FunctionHeader Source #
Represents a TypeScript function header.
Constructors
| FunctionHeader | |
Fields
| |
buildFunctionHeader :: FunctionHeader -> Builder Source #
Creates a builder for a TypeScript function header.
data InterfaceContent Source #
Represents a TypeScript interface content of some type
out of the ones defined by InterfaceContentType.
Constructors
| InterfaceContent | |
Fields
| |
buildInterfaceContent :: Int -> InterfaceContent -> Builder Source #
Creates a builder for a TypeScript interface content.
data InterfaceContentType Source #
Represents a TypeScript interface type and content.
Constructors
| InterfaceProperty | Defines a property in the interface. |
| InterfaceMethod | Defines a method in the interface. |
Fields
| |
buildInterfaceContentType :: InterfaceContentType -> Builder Source #
Creates a builder for a TypeScript interface content and type.