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 macros for the `type-bridge-orm` crate.
//!
//! Provides `#[derive(TypeBridgeAttribute)]`, `#[derive(TypeBridgeEntity)]`,
//! and `#[derive(TypeBridgeRelation)]` to eliminate manual trait implementations.
use TokenStream;
/// Derive `TypeBridgeAttribute` for a newtype struct.
///
/// # Attributes
///
/// - `#[attribute(name = "attr-name", value_type = "string")]` (required)
///
/// # Supported value types
///
/// `"string"`, `"long"`, `"double"`, `"boolean"`, `"date"`,
/// `"datetime"`, `"datetime-tz"`, `"decimal"`, `"duration"`
///
/// # Example
///
/// ```ignore
/// #[derive(TypeBridgeAttribute, Debug, Clone, PartialEq)]
/// #[attribute(name = "name", value_type = "string")]
/// struct Name(pub String);
/// ```
/// Derive `TypeBridgeEntity` for a struct with TypeDB attribute fields.
///
/// # Requirements
///
/// - Must have a field `iid: Option<String>`
/// - All other fields must implement `TypeBridgeAttribute` (or be `Option<T>`
/// where `T: TypeBridgeAttribute`)
///
/// # Attributes
///
/// - `#[entity(name = "person")]` on the struct (required)
/// - `#[field(key)]` on a field to mark it as `@key`
/// - `#[field(name = "custom-attr")]` to override the attribute name
///
/// # Example
///
/// ```ignore
/// #[derive(TypeBridgeEntity)]
/// #[entity(name = "person")]
/// struct Person {
/// iid: Option<String>,
/// #[field(key)]
/// name: Name,
/// age: Age,
/// email: Option<Email>,
/// }
/// ```
/// Derive `TypeBridgeRelation` for a struct with role player fields.
///
/// # Requirements
///
/// - Must have a field `iid: Option<String>`
/// - Role player fields must be `RolePlayerRef` with `#[role(...)]`
/// - Other fields are treated as owned attributes
///
/// # Attributes
///
/// - `#[relation(name = "employment")]` on the struct (required)
/// - `#[role(name = "employee", player_type = "person")]` on `RolePlayerRef` fields
/// - `#[field(key)]` / `#[field(name = "...")]` on attribute fields
///
/// # Example
///
/// ```ignore
/// #[derive(TypeBridgeRelation)]
/// #[relation(name = "employment")]
/// struct Employment {
/// iid: Option<String>,
/// #[role(name = "employee", player_type = "person")]
/// employee: RolePlayerRef,
/// #[role(name = "employer", player_type = "company")]
/// employer: RolePlayerRef,
/// position: Option<Position>,
/// }
/// ```
/// Derive a declaration-ordered named selection constructor for the public
/// generated Rust query facade.
/// Generate Rust model types from a TypeQL schema file at compile time.
///
/// Reads a `.tql` file, parses its `define` block, and expands to
/// attribute definitions, entity structs, and relation structs — all
/// with the appropriate derive macros applied.
///
/// # Example
///
/// ```ignore
/// // In your crate's lib.rs or models.rs:
/// type_bridge_orm::include_schema!("schema/social.tql");
///
/// // This expands to attribute types (Name, Age, ...),
/// // entity structs (Person, Company, ...), and
/// // relation structs (Employment, ...) with full derive macros.
/// ```
///
/// The path is relative to the calling crate's `Cargo.toml` directory.