Skip to content

Commit

Permalink
Merge branch 'main' into ignore_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
escritorio-gustavo authored Apr 9, 2024
2 parents 1ca7434 + b9a4cca commit a88c5c6
Show file tree
Hide file tree
Showing 62 changed files with 2,388 additions and 717 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Bug report
about: Create a report to help us improve
title: 'bug: '
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Create the following type '....'
3. Derive/implement `TS`
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Version**
What version of the library are you using?

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'Feature request: '
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Goal

What is this PR attempting to achieve? Is it a bug fix? Is it related to an issue?
Closes #

## Changes

How did you go about solving the problem?

## Checklist

- [ ] I have followed the steps listed in the [Contributing guide](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md).
- [ ] If necessary, I have added documentation related to the changes made.
- [ ] I have added or updated the tests related to the changes made.
42 changes: 40 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

### Breaking

- `#[serde(with = "...")]` requires the use of `#[ts(as = "...")]` or `#[ts(type = "...")]` ([#280](https://github.com/Aleph-Alpha/ts-rs/pull/280))
- Fix incompatibility with serde for `snake_case`, `kebab-case` and `SCREAMING_SNAKE_CASE` ([#298](https://github.com/Aleph-Alpha/ts-rs/pull/298))
- `#[ts(rename_all = "...")]` no longer accepts variations in the string's casing, dashes and underscores to make behavior consistent with serde ([#298](https://github.com/Aleph-Alpha/ts-rs/pull/298))

### Features

- Add support for `#[ts(type = "..")]` directly on structs and enums ([#286](https://github.com/Aleph-Alpha/ts-rs/pull/286))
- Add support for `#[ts(as = "..")]` directly on structs and enums ([#288](https://github.com/Aleph-Alpha/ts-rs/pull/288))
- Add support for `#[ts(rename_all = "SCREAMING-KEBAB-CASE")]` ([#298](https://github.com/Aleph-Alpha/ts-rs/pull/298))

### Fixes

- Fix `#[ts(rename_all_fields = "...")]` on enums containing tuple or unit variants ([#287](https://github.com/Aleph-Alpha/ts-rs/pull/287))

# 8.1.0

### Breaking

### Features

- Add `#[ts(crate = "..")]` to allow usage of `#[derive(TS)]` from other proc-macro crates ([#274](https://github.com/Aleph-Alpha/ts-rs/pull/274))
- Add support types from `serde_json` behind cargo feature `serde-json-impl` ([#276](https://github.com/Aleph-Alpha/ts-rs/pull/276))

### Fixes

- Macro expansion for types with generic parameters now works without the `TS` trait in scope ([#281](https://github.com/Aleph-Alpha/ts-rs/pull/281))
- Fix enum flattening a struct that contains a flattened enum ([#282](https://github.com/Aleph-Alpha/ts-rs/pull/282))

# v8.0.0

### Breaking

- Export types as `type` instead of `ìnterface` ([#203](https://github.com/Aleph-Alpha/ts-rs/pull/203))
- Automatically export all dependencies when using `#[ts(export)]`, add `TS::dependency_types()` ([#221](https://github.com/Aleph-Alpha/ts-rs/pull/221))
- Remove support for "skip_serializing", "skip_serializing_if" and "skip_deserializing". ([#204](https://github.com/Aleph-Alpha/ts-rs/pull/204))
Expand All @@ -10,8 +42,10 @@
- Added `TS::dependency_types()` ([#221](https://github.com/Aleph-Alpha/ts-rs/pull/221))
- Added `TS::generics()` ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241))
- Added `TS::WithoutGenerics` ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241))
- `Result`, `Option`, `HashMap` and `Vec` had their implementations of `TS` changed ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241))
- Removed `TS::transparent()` ([#243](https://github.com/Aleph-Alpha/ts-rs/pull/243))
- Handling of output paths ([#247](https://github.com/Aleph-Alpha/ts-rs/pull/247), [#250](https://github.com/Aleph-Alpha/ts-rs/pull/250), [#256](https://github.com/Aleph-Alpha/ts-rs/pull/256))
- All paths specified using `#[ts(export_to = "...")]` are now relative to `TS_RS_EXPORT_DIR`, which defaults to `./bindings/`
- Replace `TS::export` with `TS::export`, `TS::export_all` and `TS::export_to_all` ([#263](https://github.com/Aleph-Alpha/ts-rs/pull/263))

### Features

Expand All @@ -27,11 +61,15 @@
- Support `#[serde(untagged)]` on individual enum variants ([#226](https://github.com/Aleph-Alpha/ts-rs/pull/226))
- Support for `#[serde(rename_all_fields = "...")]` ([#225](https://github.com/Aleph-Alpha/ts-rs/pull/225))
- Export Rust doc comments/attributes on structs/enums as TSDoc strings ([#187](https://github.com/Aleph-Alpha/ts-rs/pull/187))
- `Result`, `Option`, `HashMap` and `Vec` had their implementations of `TS` changed ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241))
- Implement `#[ts(...)]` equivalent for `#[serde(tag = "...")]` being used on a struct with named fields ([#244](https://github.com/Aleph-Alpha/ts-rs/pull/244))
- Implement `#[ts(concrete(..))]` to specify a concrete type for a generic parameter ([#264](https://github.com/Aleph-Alpha/ts-rs/pull/264))

### Fixes

- fix `#[ts(skip)]` and `#[serde(skip)]` in variants of adjacently or internally tagged enums ([#231](https://github.com/Aleph-Alpha/ts-rs/pull/231))
- Fix `#[ts(skip)]` and `#[serde(skip)]` in variants of adjacently or internally tagged enums ([#231](https://github.com/Aleph-Alpha/ts-rs/pull/231))
- `rename_all` with `camelCase` produces wrong names if fields were already in camelCase ([#198](https://github.com/Aleph-Alpha/ts-rs/pull/198))
- Improve support for references ([#199](https://github.com/Aleph-Alpha/ts-rs/pull/199))
- Generic type aliases generate correctly ([#233](https://github.com/Aleph-Alpha/ts-rs/pull/233))
- Improve compiler errors ([#257](https://github.com/Aleph-Alpha/ts-rs/pull/257))
- Update dependencies ([#255](https://github.com/Aleph-Alpha/ts-rs/pull/255))
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ There is nothing special going on here - just run `cargo build`.
To run the test suite, just run `cargo test` in the root directory.

### Formatting
To ensure proper formatting, please run `cargo +nightly fmt`.
To ensure proper formatting, please make sure you have the nigthly toolchain installed.
After that, in the project's root directory, create a file called `.git/hooks/pre-commit` without a file extension and add the following two lines:
```sh
#!/bin/sh
cargo +nightly fmt
```

This will make sure your files are formatted before your commit is sent, so you don't have to manually run `cargo +nightly fmt`
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["config", "macros", "ts-rs", "example"]
members = ["macros", "ts-rs", "example"]
resolver = "2"
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ts-rs
</h1>
<p align="center">
generate typescript type declarations from rust types
Generate typescript type declarations from rust types
</p>

<div align="center">
Expand All @@ -26,23 +26,23 @@ alt="Download" />
</a>
</div>

### why?
### Why?
When building a web application in rust, data structures have to be shared between backend and frontend.
Using this library, you can easily generate TypeScript bindings to your rust structs & enums so that you can keep your
types in one place.

ts-rs might also come in handy when working with webassembly.

### how?
### How?
ts-rs exposes a single trait, `TS`. Using a derive macro, you can implement this interface for your types.
Then, you can use this trait to obtain the TypeScript bindings.
We recommend doing this in your tests.
[See the example](https://github.com/Aleph-Alpha/ts-rs/blob/main/example/src/lib.rs) and [the docs](https://docs.rs/ts-rs/latest/ts_rs/).

### get started
### Get started
```toml
[dependencies]
ts-rs = "7.1"
ts-rs = "8.1"
```

```rust
Expand All @@ -58,7 +58,7 @@ struct User {
```
When running `cargo test`, the TypeScript bindings will be exported to the file `bindings/User.ts`.

### features
### Features
- generate type declarations from rust structs
- generate union declarations from rust enums
- inline types
Expand All @@ -75,6 +75,7 @@ When running `cargo test`, the TypeScript bindings will be exported to the file
| format | Enables formatting of the generated TypeScript bindings. <br/>Currently, this unfortunately adds quite a few dependencies. |
| no-serde-warnings | By default, warnings are printed during build if unsupported serde attributes are encountered. <br/>Enabling this feature silences these warnings. |
| import-esm | When enabled,`import` statements in the generated file will have the `.js` extension in the end of the path to conform to the ES Modules spec. <br/> Example: `import { MyStruct } from "./my_struct.js"` |
| serde-json-impl | Implement `TS` for types from *serde_json* |
| chrono-impl | Implement `TS` for types from *chrono* |
| bigdecimal-impl | Implement `TS` for types from *bigdecimal* |
| url-impl | Implement `TS` for types from *url* |
Expand All @@ -91,7 +92,7 @@ When running `cargo test`, the TypeScript bindings will be exported to the file
If there's a type you're dealing with which doesn't implement `TS`, use either
`#[ts(as = "..")]` or `#[ts(type = "..")]`, or open a PR.

### serde compatability
### `serde` compatability
With the `serde-compat` feature (enabled by default), serde attributes can be parsed for enums and structs.
Supported serde attributes:
- `rename`
Expand All @@ -109,17 +110,12 @@ from the generated type, but cannot use `#[serde(skip)]`, use `#[ts(skip)]` inst

When ts-rs encounters an unsupported serde attribute, a warning is emitted, unless the feature `no-serde-warnings` is enabled.

### contributing
### Contributing
Contributions are always welcome!
Feel free to open an issue, discuss using GitHub discussions or open a PR.
[See CONTRIBUTING.md](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md)

### todo
- [x] serde compatibility layer
- [x] documentation
- [x] use typescript types across files
- [x] more enum representations
- [x] generics
- [x] don't require `'static`
### MSRV
The Minimum Supported Rust Version for this crate is 1.75.0

License: MIT
10 changes: 0 additions & 10 deletions config/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions config/README.md

This file was deleted.

62 changes: 0 additions & 62 deletions config/src/lib.rs

This file was deleted.

3 changes: 2 additions & 1 deletion e2e/workspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["crate1", "crate2", "parent"]
members = ["crate1", "crate2", "parent", "renamed"]
resolver = "2"
7 changes: 7 additions & 0 deletions e2e/workspace/renamed/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "renamed"
version = "0.1.0"
edition = "2021"

[dependencies]
ts-renamed = { package = "ts-rs", path = "../../../ts-rs" }
12 changes: 12 additions & 0 deletions e2e/workspace/renamed/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use ts_renamed::TS;

#[derive(TS)]
#[ts(crate = "ts_renamed", export)]
pub struct SimpleStruct {
hello: String,
world: u32,
}

fn main() {
println!("Hello, world!");
}
3 changes: 1 addition & 2 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ts-rs-macros"
version = "7.1.1"
version = "8.1.0"
authors = ["Moritz Bischof <[email protected]>"]
edition = "2021"
description = "derive macro for ts-rs"
Expand All @@ -19,5 +19,4 @@ proc-macro = true
proc-macro2 = "1"
quote = "1"
syn = { version = "2.0.28", features = ["full", "extra-traits"] }
Inflector = { version = "0.11", default-features = false }
termcolor = { version = "1", optional = true }
Loading

0 comments on commit a88c5c6

Please sign in to comment.