All Projects → dtgorski → Typex

dtgorski / Typex

Licence: mit
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.

Programming Languages

go
31211 projects - #10 most used programming language
typescript
32286 projects
golang
3204 projects
type
21 projects

Projects that are alternatives of or similar to Typex

Dynein
DynamoDB CLI written in Rust.
Stars: ✭ 126 (-1.56%)
Mutual labels:  cli, export
Converter
database table to golang struct (table to struct) converter with cli and go lib support
Stars: ✭ 167 (+30.47%)
Mutual labels:  cli, struct
Pidtree
🚸 Cross platform children list of a PID.
Stars: ✭ 76 (-40.62%)
Mutual labels:  cli, tree
Jsonexport
{} → 📄 it's easy to convert JSON to CSV
Stars: ✭ 208 (+62.5%)
Mutual labels:  cli, export
Es2csv
Export from an Elasticsearch into a CSV file
Stars: ✭ 465 (+263.28%)
Mutual labels:  cli, export
Project Explorer
🎋A CLI tool to create an annotated tree visualization of any project
Stars: ✭ 485 (+278.91%)
Mutual labels:  cli, tree
Tree Node Cli
🌲 Node.js library to list the contents of directories in a tree-like format, similar to the Linux tree command
Stars: ✭ 102 (-20.31%)
Mutual labels:  cli, tree
Pretty Quick
⚡ Get Pretty Quick
Stars: ✭ 1,766 (+1279.69%)
Mutual labels:  cli
Tsed
📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: ✭ 1,941 (+1416.41%)
Mutual labels:  cli
Report
Report management package in PHP that aims to help you export information in a variety of formats
Stars: ✭ 125 (-2.34%)
Mutual labels:  export
Promplot
Create plots from Prometheus metrics and send them to you
Stars: ✭ 125 (-2.34%)
Mutual labels:  cli
Fx
Command-line tool and terminal JSON viewer 🔥
Stars: ✭ 11,295 (+8724.22%)
Mutual labels:  cli
Jsonfui
jsonfui is an interactive command-line JSON viewer.
Stars: ✭ 125 (-2.34%)
Mutual labels:  cli
Java Ds Algorithms
Data Structures and Algorithms in Java
Stars: ✭ 125 (-2.34%)
Mutual labels:  tree
Gitless
A simple version control system built on top of Git
Stars: ✭ 1,660 (+1196.88%)
Mutual labels:  cli
Grafana Import Export
shell scripts for importing and exporting Grafana's dashboards and datasources
Stars: ✭ 125 (-2.34%)
Mutual labels:  export
Grmon
Command line monitoring for goroutines
Stars: ✭ 1,703 (+1230.47%)
Mutual labels:  cli
Linuxdeploy Cli
Linux Deploy CLI
Stars: ✭ 127 (-0.78%)
Mutual labels:  cli
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (-1.56%)
Mutual labels:  cli
Ckube
A cli to simplify working with kubectl for some common workflows
Stars: ✭ 127 (-0.78%)
Mutual labels:  cli

Build Status Coverage Status Open Issues Report Card Awesome Go

typex

Examine Go types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration.

Installation

go get -u github.com/dtgorski/typex

Synopsis

The CLI command typex filters and displays Go type structures, interfaces and their relationships across package boundaries. It generates a type hierarchy tree with additional references to transitive dependencies vital for the filtered types. As an additional feature, typex exports the result tree as a TypeScript projection representing value objects or bare types.

Examples

Go type hierarchy layout

$ typex -f=Rune io/...

├── error interface {
│       Error() string
│   }
└── io
    ├── RuneReader interface {
    │       ReadRune() (r rune, size int, err error)
    │   }
    └── RuneScanner interface {
            io.RuneReader
            ReadRune() (r rune, size int, err error)
            UnreadRune() error
        }
$ typex -f=Render github.com/dtgorski/typex/...

└── github.com
    └── dtgorski
        └── typex
            └── internal
                ├── PathReplaceFunc func(string) string
                ├── go
                │   └── TypeRender struct {
                │           PathReplaceFunc internal.PathReplaceFunc
                │           IncludeUnexported bool
                │       }
                └── ts
                    └── TypeRender struct {
                            PathReplaceFunc internal.PathReplaceFunc
                            IncludeUnexported bool
                        }

TypeScript value object layout

$ typex -f=File -l=ts-class mime/multipart

export module mime {
    export module multipart {
        export class FileHeader {
            constructor(
                readonly Filename: string,
                readonly Header: net.textproto.MIMEHeader,
                readonly Size: number,
            ) {}
        }
    }
}
export module net {
    export module textproto {
        export type MIMEHeader = Record<string, string[]>
    }
}

TypeScript bare type layout

$ typex -f=File -l=ts-type mime/multipart

export module mime {
    export module multipart {
        export type FileHeader = {
            Filename: string,
            Header: net.textproto.MIMEHeader,
            Size: number,
        }
    }
}
export module net {
    export module textproto {
        export type MIMEHeader = Record<string, string[]>
    }
}

TypeScript and reserved keywords

Basically, the names of types and fields will be exported from Go without modification. Collisions with reserved keywords or standard type names in the target language may occur. To avoid conflicts, you may use the JSON tag annotation for the exported fields of a struct as described in the json.Marshal(...) documentation.

TypeScript and exportable types

Due to fundamental language differences, typex is not capable of exporting all type declarations one-to-one. Refer to the type mapping table below. Go channel, interface and function declarations will be omitted, references to these declarations will be typed with any.

TypeScript type mapping

TypeScript (resp. JavaScript aka ECMAScript) lacks a native integer number type. The numeric type provided there is inherently a 64 bit float. You should keep this in mind when working with exported numeric types - this includes byte and rune type aliases as well.

Go native type TypeScript type
bool boolean
string string
map Record<K, V>
struct (named) T
struct (anonymous) {}
array (slice) T[]
complex[64|128] any
chan, func, interface any
int[8|16|32|64] number
uint[8|16|32|64] number
byte(=uint8) number
rune(=int32) number
float[32|64] number
uintptr number

Usage

$ typex -h
Usage: typex [options] package...
Examine Go types and their transitive dependencies. Export
results as TypeScript value objects (or types) declaration.

Options:
    -f <name>
        Type name filter expression. Repeating the -f option
        is allowed, all expressions aggregate to an OR query.

        The <name> filter can be a type name, a path part or
        a regular expression. Especially in the latter case,
        <name> should be quoted or escaped correctly to avoid
        errors during shell interpolation. Filters are case
        sensitive, see examples below.

        The result tree will contain additional references to
        transitive dependencies vital for the filtered types.

    -l <layout>
        Modify the export layout. Available layouts are:
          * "go":       the default Go type dependency tree
          * "ts-type":  TypeScript type declaration projection
          * "ts-class": TypeScript value object projection

    -r <old-path>:<new-path>
        Replace matching portions of <old-path> in a fully
        qualified type name with <new-path> string. Repeating
        the -r option is allowed, substitutions will perform
        successively. <old-path> can be a regular expression.
        
        The path replacement/relocation can be used to modify
        locations of type hierarchies, e.g. prune off the
        "github.com" reference from qualified type name path
        by omitting the <new-path> part after the colon. 

    -t  Go tests (files suffixed _test.go) will be included
        in the result tree available for a filter expression

    -u  Unexported types (lowercase names) will be included
        in the result tree available for a filter expression.

    -x <name> 
        Exclude type names from export. Repeating this option
        is allowed, all expressions aggregate to an OR query.
        The exclusion filter can be a type name, a path part
        or a regular expression.

More options:
    -h  Display this usage help and exit.
    -v  Print program version and exit.

The 'package' argument denotes one or more package import path
patterns to be inspected. Patterns must be separated by space.
A pattern containing '...' specifies the active modules whose
modules paths match the pattern.

Examples:
    $ typex -u go/...
    $ typex -u -f=URL net/url
    $ typex github.com/your/repository/...
    $ typex -l=ts-type github.com/your/repository/...
    $ typex -r=github.com:a/b/c github.com/your/repository/...

This tool relies heavily on Go's package managing subsystem and
is bound to its features and environmental execution context.

Known issues

  • Occasional(?) internal error from Go's package managing subsystem has been reported on Go 1.14.6 darwin/amd64. Newer Go versions >= 1.15 seem to be not affected.

Disclaimer

The implementation and features of typex follow the YAGNI principle. There is no claim for completeness or reliability.

@dev

Try make:

$ make

 make help       Displays this list
 make clean      Removes build/test artifacts
 make build      Builds a static binary to ./bin/typex
 make debug      Starts debugger [:2345] with ./bin/typex
 make install    Compiles and installs typex in Go environment
 make test       Runs tests, reports coverage
 make tidy       Formats source files, cleans go.mod
 make sniff      Checks format and runs linter (void on success)

License

MIT - © dtg [at] lengo [dot] org

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].