Skip to content

Commit e4d6f88

Browse files
committed
docs(rust): full documentation and metadata polish for Rust core
- Add Cargo.toml metadata (license, repository, authors) to workspace and all 3 crates - Add #![warn(missing_docs)] to core and python crates with 0 warnings - Document all 248 public items in the core crate (ast, schema, validation, value_coercion, compiler, query_parser, reserved_words) - Add crate-level //! docs and /// module docs to all modules - Document python crate public structs, add #[allow(missing_docs)] on PyO3 AST wrappers - Fix all rustdoc broken intra-doc links (14 warnings → 0) - Write READMEs for core, python crates and rewrite workspace README - Add Rust Core section to root project README with performance numbers - Fix Python UP047 lint (TypeVar → PEP 695 type parameter syntax)
1 parent ce00cb8 commit e4d6f88

20 files changed

Lines changed: 794 additions & 50 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ uv run pytest -m "" -v # Run all tests
363363
./check.sh # Run linting and type checking
364364
```
365365

366+
## Rust Core
367+
368+
The project includes a Rust core (`type-bridge-core/`) that provides high-performance implementations of the query compiler, validation engine, and value coercer. When the native extension is installed, Python automatically delegates to Rust for:
369+
370+
- **Validation**~8.6x faster schema-aware query validation
371+
- **Compilation**~1.3x faster AST-to-TypeQL compilation via serde bridge
372+
- **Value coercion** — Type-safe value coercion and TypeQL literal formatting
373+
374+
The Rust core is a Cargo workspace with three crates:
375+
376+
| Crate | Description |
377+
|-------|-------------|
378+
| `type-bridge-core-lib` | Pure-Rust AST, schema parser, query compiler, and validation engine |
379+
| `type-bridge-core` | PyO3 bindings exposing the Rust core to Python |
380+
| `type-bridge-server` | Transport-agnostic query pipeline with HTTP API |
381+
382+
See [`type-bridge-core/README.md`](type-bridge-core/README.md) for build instructions and architecture details.
383+
366384
## Requirements
367385

368386
- Python 3.13+

type-bridge-core/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
resolver = "3"
33
members = ["crates/core", "crates/python", "crates/server"]
44

5+
[workspace.package]
6+
license = "MIT"
7+
repository = "https://github.com/ds1sqe/type-bridge"
8+
authors = ["ds1sqe"]
9+
510
[workspace.lints.rust]
611
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)', 'cfg(coverage)'] }

type-bridge-core/README.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
# type-bridge-core
22

3-
Rust core for the `type-bridge` TypeDB ORM.
3+
Rust core for the **type-bridge** TypeDB ORM — high-performance AST, schema parser, query compiler, validation engine, and value coercer.
44

5-
## Overview
5+
## Workspace structure
66

7-
This crate provides a high-performance, shared type system and query engine for `type-bridge`. It enables:
8-
9-
- **Bidirectional Validation**: Define validation rules once in Rust and enforce them on both client (Python) and server (Rust/WASM).
10-
- **Query Object Portability**: First-class AST objects that can be serialized and moved between runtimes.
11-
- **Performance**: High-speed query compilation and schema parsing.
7+
```
8+
type-bridge-core/
9+
├── Cargo.toml # Workspace root
10+
└── crates/
11+
├── core/ # type-bridge-core-lib (pure Rust, no runtime deps)
12+
├── python/ # type-bridge-core (PyO3 bindings → Python)
13+
└── server/ # type-bridge-server (query pipeline + HTTP API)
14+
```
1215

13-
## Structure
16+
## Crates
1417

15-
- `src/core`: Pure Rust implementation of the AST, schema, and validation engine. This is runtime-agnostic.
16-
- `src/ast`: PyO3 wrappers for the core AST nodes, providing an idiomatic Python API.
17-
- `src/lib.rs`: PyO3 module definition.
18+
| Crate | Description |
19+
|-------|-------------|
20+
| [`type-bridge-core-lib`](crates/core/) | Pure-Rust TypeQL AST, schema parser, query compiler, validation engine, and value coercer |
21+
| [`type-bridge-core`](crates/python/) | PyO3 bindings exposing the Rust core to Python via serde-tagged-enum dicts |
22+
| [`type-bridge-server`](crates/server/) | Transport-agnostic query pipeline with validation, interceptors, and HTTP API |
1823

1924
## Building
2025

21-
To build the Python extension:
22-
2326
```bash
27+
# Check all crates (requires PYO3 compat flag on Python ≥ 3.14)
28+
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 cargo check --all-targets
29+
30+
# Build the Python extension
2431
cd type-bridge-core
25-
maturin develop
32+
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin develop
33+
34+
# Run tests
35+
cargo test -p type-bridge-core-lib -p type-bridge-server
36+
37+
# Generate docs
38+
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 cargo doc --no-deps --open
39+
```
40+
41+
## Local CI mirror
42+
43+
Use the project-level check script to mirror CI locally:
44+
45+
```bash
46+
./scripts/check.sh rust # Rust checks only
47+
./scripts/check.sh python # Python checks only
48+
./scripts/check.sh # Both
2649
```
2750

28-
## Status
51+
## License
2952

30-
This is an initial implementation following the RFC in issue #95. Key structures are in place, with logic being ported from Python.
53+
MIT

type-bridge-core/crates/core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
name = "type-bridge-core-lib"
33
version = "0.1.0-dev.0"
44
edition = "2024"
5+
description = "TypeQL AST, schema parser, query compiler, and validation engine for type-bridge"
6+
license.workspace = true
7+
repository.workspace = true
8+
authors.workspace = true
59

610
[features]
711
default = []
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# type-bridge-core-lib
2+
3+
Pure-Rust TypeQL AST, schema parser, query compiler, validation engine, and value coercer for **type-bridge**.
4+
5+
## Modules
6+
7+
| Module | Purpose |
8+
|--------|---------|
9+
| `ast` | TypeQL Abstract Syntax Tree — patterns, statements, clauses, and values |
10+
| `schema` | Schema representation with entity / relation / attribute types and inheritance resolution |
11+
| `validation` | Schema-aware query validation plus a portable JSON validation-rule DSL |
12+
| `compiler` | Compiles an AST back into a TypeQL query string |
13+
| `query_parser` | Parses a TypeQL query string into the AST (bidirectional round-trip) |
14+
| `value_coercion` | Coerces raw values into TypeDB value-types and formats TypeQL literals |
15+
| `reserved_words` | TypeQL reserved-word detection |
16+
| `parser` | Low-level Winnow grammar consumed by `query_parser` and `schema` |
17+
18+
## Usage
19+
20+
```rust
21+
use type_bridge_core_lib::query_parser::parse_typeql_query;
22+
use type_bridge_core_lib::compiler::QueryCompiler;
23+
use type_bridge_core_lib::schema::TypeSchema;
24+
use type_bridge_core_lib::validation::ValidationEngine;
25+
26+
// Parse a TypeQL query into AST clauses
27+
let clauses = parse_typeql_query("match $p isa person, has name 'Alice';").unwrap();
28+
29+
// Compile back to TypeQL
30+
let compiler = QueryCompiler::new();
31+
let typeql = compiler.compile(&clauses);
32+
assert_eq!(typeql, "match $p isa person, has name 'Alice';");
33+
34+
// Validate against a schema
35+
let schema = TypeSchema::from_typeql("define entity person, owns name; attribute name, value string;").unwrap();
36+
let engine = ValidationEngine::new();
37+
let result = engine.validate_query(&clauses, &schema);
38+
assert!(result.is_valid);
39+
```
40+
41+
## Feature flags
42+
43+
| Feature | Default | Effect |
44+
|---------|---------|--------|
45+
| `pyo3` | no | Enables `#[derive(FromPyObject)]` on AST types for PyO3 interop |
46+
47+
## Testing
48+
49+
```bash
50+
cargo test -p type-bridge-core-lib
51+
```
52+
53+
## License
54+
55+
MIT

0 commit comments

Comments
 (0)