cardano-wasm:cardano-wasi-lib
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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.

Fields

  • Bool

    Is it a default export?

  • String

    Name of the symbol to export.

FunctionDec FunctionHeader

Function declaration.

InterfaceDec

Interface declaration.

Fields

ImportDec

Reference to import another TypeScript declaration file.

Fields

  • String

    Name of the symbol to import.

  • String

    Path to the TypeScript declaration file to import.

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

data FunctionParam Source #

Represents a function parameter in TypeScript.

Constructors

FunctionParam 

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.

Fields

InterfaceMethod

Defines a method in the interface.

Fields

buildInterfaceContentType :: InterfaceContentType -> Builder Source #

Creates a builder for a TypeScript interface content and type.

mconcatWith :: Builder -> [Builder] -> Builder Source #

Concatenates a list of builders with a separator. If the list is empty, it returns an empty builder.