Skip to content

Commit

Permalink
readme | documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Jul 31, 2023
1 parent cd23d3a commit f0b7951
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 7 deletions.
Binary file removed arch.png
Binary file not shown.
Binary file added codegen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
TypeBox-Transform: Code Generation Tools for TypeBox

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
72 changes: 65 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
# typebox-codegen
<div align='center'>

<h1>TypeBox Codegen</h1>

<p>Code Generation Tools for TypeBox</p>

<img src="codegen.png" />

<br />

</div>

## Overview

This package provides code generation for TypeBox types
This library implements various code generation tools for transforming TypeScript types into TypeBox types as well as several other type representations. This library works by first transforming TypeScript type representations into a TypeBox Type Model. The Model can then be passed to various code generators that map the TypeBox Model into various target representations.

The library contains various code generators for libraries such as Zod, Io-Ts, ArkType and Valibot, no-library function generators for JavaScript and TypeScript as well as TypeScript to JSON Schema generation derived from TypeBox schematics. These tools are written as a backend for CLI tooling, website integration and as a system to assert TypeBox alignment with the TypeScript type system.

License MIT

## Architecture
## Usage

The following is the initial architecture for code transformations to be provided by this package
```typescript
import * as Codegen from '@sinclair/typebox-codegen'

<img src="arch.png" />
const Code = `
export type T = {
x: number,
y: number,
z: number
}
`
// ----------------------------------------------------------------------------
//
// TypeScriptToTypeBox
//
// Generates an immediate TypeScript to TypeBox type code transformation
//
// ----------------------------------------------------------------------------

console.log('TypeScript To TypeBox', Codegen.TypeScriptToTypeBox.Generate(Code))

// ----------------------------------------------------------------------------
//
// TypeScriptToModel
//
// Generates an in-memory TypeBox Type Model
//
// ----------------------------------------------------------------------------

const model = Codegen.TypeScriptToModel.Generate(Code)

// ----------------------------------------------------------------------------
//
// ModelToX
//
// The TypeBox Type Model can be passed to several generators which map the
// Model into varying type representations.
//
// ----------------------------------------------------------------------------

console.log('TypeBoxModel', model)
console.log('Model To JsonSchema', Codegen.ModelToJsonSchema.Generate(model))
console.log('Model To JavaScript', Codegen.ModelToJavaScript.Generate(model))
console.log('Model To TypeScript', Codegen.ModelToTypeScript.Generate(model))
console.log('Model To Valibot', Codegen.ModelToValibot.Generate(model))
console.log('Model To Value', Codegen.ModelToValue.Generate(model))
console.log('Model To Yup', Codegen.ModelToYup.Generate(model))
console.log('Model To Zod', Codegen.ModelToZod.Generate(model))
console.log('Model To ArkType', Codegen.ModelToArkType.Generate(model))
```

## Running Local

Expand All @@ -22,8 +82,6 @@ $ npm format # prettier pass for `src` and `example`
$ npm clean # remove the `target` directory.

$ npm start # run the `example` script in node

$ npm serve # run the `example` script in browser
```

## Formatting hook
Expand Down

0 comments on commit f0b7951

Please sign in to comment.