Skip to content

Commit 7fe4d59

Browse files
ivanauthclaudemiparnisari
authored
docs: add underscore prefix convention for private identifiers (#421)
Co-authored-by: Claude <[email protected]> Co-authored-by: Maria Ines Parnisari <[email protected]>
1 parent 0b27c64 commit 7fe4d59

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/spicedb/concepts/schema/page.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,35 @@ Examples:
437437
to a _computed_ set of subjects.
438438
</Callout>
439439

440+
### Private/Internal Identifiers
441+
442+
SpiceDB supports using an underscore (`_`) prefix for identifiers to establish a convention for marking definitions, relations, or permissions as "private" or "internal". This is a naming convention only—they are not treated any different at runtime, and they can still be used in relationships and permission checks like
443+
any other identifier.
444+
445+
```zed
446+
definition document {
447+
relation viewer: user
448+
relation _internal_viewer: user // private: internal use only
449+
450+
permission _can_view = viewer + _internal_viewer // private: synthetic
451+
permission view = _can_view // public API
452+
}
453+
```
454+
455+
This convention is useful for:
456+
457+
- **Synthetic permissions**: Permissions that exist only to compose other permissions
458+
- **Internal relations**: Relations not meant to be directly referenced by application code
459+
- **Implementation details**: Parts of your schema that may change without affecting the public API
460+
461+
#### Identifier Rules
462+
463+
- Identifiers can begin with a lowercase letter (`a-z`) or underscore (`_`)
464+
- After the first character, identifiers can contain lowercase letters, numbers, and underscores
465+
- Identifiers must be 3-64 characters long and end with an alphanumeric character
466+
- Valid: `_ab`, `_private`, `_internal_relation`, `_helper123`
467+
- Invalid: `_` (too short), `_a` (too short), `_trailing_` (cannot end with underscore)
468+
440469
## Comments
441470

442471
### Documentation Comments

0 commit comments

Comments
 (0)