Skip to content

Commit

Permalink
Release dev to alpha channel (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rune Finstad Halvorsen <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2021
2 parents 1dba38f + 756b1b5 commit a7f657a
Show file tree
Hide file tree
Showing 7 changed files with 665 additions and 154 deletions.
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ conversion package (e.g. JSON Schema to Runtypes).
We are thankful for all help with adding new functionality, fixing issues, or
improve the package. Feel free to open issues and pull requests ❤️

It's based on [ts-morph][ts-morph] 🎉

## Documentation

Apart from this README, you can find details and examples of using the SDK in
Expand All @@ -28,23 +26,55 @@ the following places:
## Example

```typescript
import { Project } from 'ts-morph';
import { generateRuntype } from 'generate-runtypes';

const project = new Project();
const file = project.createSourceFile('./my-file.ts');

generateRuntype(file, {
name: 'Post',
fields: [
{ name: 'title', type: 'String' },
{ name: 'body', type: 'String' },
{ name: 'author', type: 'String' },
{ name: 'comments', type: 'Array', subType: 'Comment' },
],
import { generateRuntypes } from 'generate-runtypes';

const sourceCode = generateRuntypes(
{
name: 'Comment',
type: {
kind: 'record',
fields: [
{ name: 'author', type: { kind: 'string' } },
{ name: 'body', type: { kind: 'string' } },
{ name: 'timestamp', type: { kind: 'number' } },
],
},
},
{
name: 'Post',
export: true,
type: {
kind: 'record',
fields: [
{ name: 'title', type: { kind: 'string' } },
{ name: 'body', type: { kind: 'string' } },
{ name: 'author', type: { kind: 'string' } },
{
name: 'comments',
type: { kind: 'array', type: { kind: 'named', name: 'Comment' } },
},
],
},
},
);
```

The generated code looks like this after formatting:

```typescript
const Comment = rt.Record({
author: rt.String,
body: rt.String,
timestamp: rt.Number,
});

export const Post = rt.Record({
title: rt.String,
body: rt.String,
author: rt.String,
comments: rt.Array(Comment),
});
```

[runtypes]: https://github.com/pelotom/runtypes
[ts-morph]: https://github.com/dsherret/ts-morph
[docs]: ./docs
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
},
"dependencies": {
"runtypes": "^5.0.2",
"ts-morph": "^10.0.2",
"typescript": "~4.1.3"
}
}
Loading

0 comments on commit a7f657a

Please sign in to comment.