1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! **Derive your `typescript` / `Rust` interop**
//! [](https://github.com/nicolaiunrein/zod/actions/workflows/ci.yml)
//! [](https://github.com/rust-secure-code/safety-dance/)
//! [](https://crates.io/crates/zod)
//! [](https://docs.rs/zod)
//! [](https://crates.io/crates/zod)
//! [](https://github.com/nicolaiunrein/zod/compare)
//!
//! This crate provides integrations with the [zod](https://github.com/colinhacks/zod) typescript library.
//!
//! **_NOTE:_** This crate is not ready for production yet!
//!
//! ## Overview
//! This crate generates [zod](https://github.com/colinhacks/zod) bindings for your `rust` types and
//! optionally generates an sdk fully automatically.
//!
//! ## Example
//! ```rust
//! # use zod::Namespace;
//! # use serde::{Serialize, Deserialize};
//! # use zod::Zod;
//! #[derive(Namespace)]
//! struct Ns;
//!
//! #[derive(Serialize, Deserialize, Zod)]
//! #[zod(namespace = "Ns")]
//! struct MyStruct {
//! port: u16,
//! data: MyData
//! }
//!
//! #[derive(Serialize, Deserialize, Zod)]
//! #[zod(namespace = "Ns")]
//! enum MyData {
//! Hello(String),
//! World(Vec<usize>)
//! }
//!
//! ```
//! Deriving Zod implements the [ZodType](https://docs.rs/zod-core/ZodType) trait for you exposing a couple of methods to the
//! typescript/schema representation of your rust types.
//!
//! Calling `MyStruct::schema()` will give you a string with a valid zod schema definition:
//! ```ts
//! z.object({ port: Rs.U16, data: Ns.MyData })
//! ```
//!
//! Respectively `MyData::schema()` will give you:
//!
//! ```ts
//! z.discriminatedUnion([
//! z.object({ Hello: Rs.String }),
//! z.object({ World: z.array(Rs.Usize) })
//! ])
//! ```
//!
//! There is also the `type_def` method which will give you a typescript type definition:
//! ```ts
//! { port: Rs.U16, data: Ns.MyData }
//! ```
//! and
//!
//! ```ts
//! { Hello: Rs.String } | { World: [Rs.Usize] }
//! ```
//!
//! ## TODO
//! - [x] Codegen for struct style enums
//! - [x] implement all missing serde attrs where possible. see: [ts-rs](https://docs.rs/ts-rs/latest/ts_rs/)
//!
//! - [x] rename
//! - [x] rename-all
//! - [x] tag
//! - [x] internally
//! - [x] externally
//! - [x] adjacently
//! - [x] untagged
//! - [x] skip
//! - [x] skip_deserializing
//! - [x] default
//! - [x] transparent structs
//! - [x] flatten
//!
//! - [x] implement tuple structs as z.tuple()
//! - [x] Restrict non-default fields in tuple structs to only come before the first default field
//! - [x] create namespace macro
//! - [x] RPC macros
//! - [x] codegen options (eg. schema prefix/suffix, type prefix/suffix)
//! - [x] add a mapping table to README.md
//! - [x] write detailed intro
//! - [x] write rust-docs
//!
//! - [ ] Consider to allow the use of generics otherwise force implementors to not have generics
//! - [ ] RPC ui tests
//! - [ ] improve diagnostics on rpc (eg. correct spans, better compile time errors)
//! - [ ] improve macro hygiene
//! - [ ] use crate_name in zod-derive
//! - [ ] const scope where possible
//!
//! - [ ] add integration tests with jest
//! - [ ] consider making Result/Option "smart" classes with methods like `unwrap`, `map`, `is_ok`, `is_none` etc.
//! - [ ] make rpc a feature or consider splitting the crates entirely
//!
//! ## Consideration?
//! - flattening a `std::collections::HashMap` onto a struct. This works in serde but not in zod because we represent the `HashMap` as a `z.map([..])` which represents a `Map` in ts/js.
//!
//! ## Contributing
//! Contribution is more than welcome. This crate is extensively tested but there are a lot of edge-cases. If you find anything that is not working but should, please let meknow.
//!
//!
//!
pub use *;
pub use *;