Skip to content

Commit 79ee758

Browse files
committed
docs: add Usage to "explain" section in docs
1 parent 8a91922 commit 79ee758

2 files changed

Lines changed: 126 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ Then:
209209
$ typeid explain user_01h45ytscbebyvny4gc8cr8ma2
210210
```
211211

212+
Read more here: ["Docs: Explain"](https://akhundmurad.github.io/typeid-python/performance/).
213+
212214
## Design principles
213215

214216
* **Non-breaking**: stable APIs

docs/explain.md

Lines changed: 124 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,130 @@ If parsing fails, the explanation still succeeds — it simply reports that the
3939

4040
This distinction is important. `explain` is not a validator that throws errors; it is an inspection tool that always returns an answer.
4141

42+
## Usage
43+
44+
```console
45+
$ typeid explain user_01h45ytscbebyvny4gc8cr8ma2
46+
```
47+
48+
Example output:
49+
50+
```yaml
51+
id: user_01h45ytscbebyvny4gc8cr8ma2
52+
valid: true
53+
54+
parsed:
55+
prefix: user
56+
suffix: 01h45ytscbebyvny4gc8cr8ma2
57+
uuid: 01890bf0-846f-7762-8605-5a3abb40e0e5
58+
created_at: 2025-03-12T10:41:23Z
59+
sortable: true
60+
61+
schema:
62+
found: false
63+
```
64+
65+
Even without configuration, `typeid explain` can:
66+
67+
* validate the ID
68+
* extract the UUID
69+
* derive creation time (UUIDv7)
70+
* determine sortability
71+
72+
### Schema-based explanations
73+
74+
To make explanations richer, you can define a **TypeID schema** describing what each
75+
prefix represents.
76+
77+
#### Example schema (`typeid.schema.json`)
78+
79+
```json
80+
{
81+
"schema_version": 1,
82+
"types": {
83+
"user": {
84+
"name": "User",
85+
"description": "End-user account",
86+
"owner_team": "identity-platform",
87+
"pii": true,
88+
"retention": "7y",
89+
"links": {
90+
"logs": "https://logs.company/search?q={id}",
91+
"trace": "https://traces.company/?id={id}"
92+
}
93+
}
94+
}
95+
}
96+
```
97+
98+
#### Explain using schema
99+
100+
```console
101+
$ typeid explain user_01h45ytscbebyvny4gc8cr8ma2
102+
```
103+
104+
Output (excerpt):
105+
106+
```yaml
107+
schema:
108+
found: true
109+
name: User
110+
owner_team: identity-platform
111+
pii: true
112+
retention: 7y
113+
114+
links:
115+
logs: https://logs.company/search?q=user_01h45ytscbebyvny4gc8cr8ma2
116+
```
117+
118+
#### Schema discovery rules
119+
120+
If `--schema` is not provided, TypeID looks for a schema in the following order:
121+
122+
1. Environment variable:
123+
124+
```console
125+
TYPEID_SCHEMA=/path/to/schema.json
126+
```
127+
2. Current directory:
128+
129+
* `typeid.schema.json`
130+
* `typeid.schema.yaml`
131+
3. User config directory:
132+
133+
* `~/.config/typeid/schema.json`
134+
* `~/.config/typeid/schema.yaml`
135+
136+
If no schema is found, the command still works with derived information only.
137+
138+
#### YAML schemas (optional)
139+
140+
YAML schemas are supported if the optional dependency is installed:
141+
142+
```console
143+
pip install typeid-python[yaml]
144+
```
145+
146+
Example (`typeid.schema.yaml`):
147+
148+
```yaml
149+
schema_version: 1
150+
types:
151+
user:
152+
name: User
153+
owner_team: identity-platform
154+
links:
155+
logs: "https://logs.company/search?q={id}"
156+
```
157+
158+
### JSON output (machine-readable)
159+
160+
```console
161+
$ typeid explain user_01h45ytscbebyvny4gc8cr8ma2 --json
162+
```
163+
164+
Useful for: scripts, CI pipelines, IDE integrations
165+
42166
## Invalid vs unknown
43167

44168
An invalid identifier is one that cannot be parsed at all. Its structure is wrong, its encoding is broken, or it does not conform to the TypeID format.
@@ -152,9 +276,3 @@ A useful way to think about `typeid explain` is:
152276
> **OpenAPI, but for identifiers instead of HTTP endpoints**
153277

154278
It provides a shared, inspectable contract for something that is otherwise opaque and informal.
155-
156-
## Closing
157-
158-
Identifiers are part of a system’s interface, whether we acknowledge it or not.
159-
160-
By making identifiers inspectable and explainable, TypeID aims to reduce friction in debugging, improve communication across teams, and make systems slightly easier to reason about — without sacrificing compatibility or safety.

0 commit comments

Comments
 (0)