Skip to content

Commit 0d7ca79

Browse files
committed
docs: well-known instance generation
Signed-off-by: devjow <me@devjow.com>
1 parent 5bf5313 commit 0d7ca79

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

gts-macros/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,56 @@ pub const ORDERS_TOPIC: &str = r#"{
448448
}"#;
449449
```
450450

451+
### Quick Start Guide
452+
453+
**Step 1 — Declare the instance in a Rust source file:**
454+
455+
```rust
456+
// src/gts/mod.rs
457+
#[gts_macros::gts_well_known_instance(
458+
dir_path = "instances",
459+
schema_id = "gts.x.core.events.topic.v1~",
460+
instance_segment = "x.commerce._.orders.v1.0"
461+
)]
462+
pub const ORDERS_TOPIC: &str = r#"{
463+
"name": "orders",
464+
"description": "Order lifecycle events topic",
465+
"retention": "P90D",
466+
"partitions": 16
467+
}"#;
468+
```
469+
470+
**Step 2 — Run the CLI to generate the `.instance.json` file:**
471+
472+
```bash
473+
gts generate-from-rust --source src/ --mode instances
474+
```
475+
476+
This produces `instances/gts.x.core.events.topic.v1~x.commerce._.orders.v1.0.instance.json` with the `"id"` field injected automatically.
477+
478+
**Step 3 — Use the instance:**
479+
480+
```rust
481+
// Reference the const directly (it's just a &str containing JSON)
482+
let topic: serde_json::Value = serde_json::from_str(ORDERS_TOPIC)?;
483+
484+
// The full instance ID is schema_id + instance_segment
485+
let instance_id = "gts.x.core.events.topic.v1~x.commerce._.orders.v1.0";
486+
487+
// Register or look up via the types-registry
488+
let entity = registry.get(instance_id).await?;
489+
```
490+
491+
The generated `.instance.json` file can also be loaded by the types-registry at bootstrap as seed data, or validated against its parent schema.
492+
493+
### When to use this vs runtime registration
494+
495+
| Use `#[gts_well_known_instance]` | Use `gts_make_instance_id()` + `register()` |
496+
|---|---|
497+
| Instance payload is **fully known at compile time** | Payload depends on **runtime config** (vendor, priority, etc.) |
498+
| Seed data, built-in defaults, test fixtures | Deployment-specific plugin registration |
499+
| Produces a static `.instance.json` file | Registers in-memory at module `init()` |
500+
451501
### Parameters
452502

453503
| Parameter | Required | Description |

0 commit comments

Comments
 (0)