Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Return a consistent DTO shape across all sources implementing the same contract
Return the same public DTO fields regardless of whether data came from a live write, cache hit or fallback query. Keep internal routing and cache metadata separate from the serialized response.
Bad example
| 1 | type Item = { id: string; title: string }; |
| 2 | const fromCache = (item: Item, routingKeys: string[]) => ({ ...item, routingKeys }); |
| 3 | const fromLive = (item: Item) => item; |
Explanation (EN)
The same item exposes extra fields depending on its retrieval path.
Objašnjenje (HR)
Isti zapis izlaže dodatna polja ovisno o putu dohvaćanja.
Good example
| 1 | type Item = { id: string; title: string }; |
| 2 | const publicItem = (item: Item): Item => ({ id: item.id, title: item.title }); |
| 3 | const cacheEntry = (item: Item, routingKeys: string[]) => ({ item: publicItem(item), routingKeys }); |
Explanation (EN)
Store internal metadata separately and return only the public item on every path.
Objašnjenje (HR)
Interne podatke drži odvojeno i sa svakog puta vrati samo javni zapis.
Notes (EN)
Use one shared response contract and check cold, warm and live-write responses. Internal routing fields should not be added to the DTO merely to simplify cache reconstruction.
Bilješke (HR)
Koristi zajednički ugovor odgovora i provjeri hladni cache, topli cache i izravne upise.
Exceptions / Tradeoffs (EN)
Metadata that is intentionally part of the documented public contract may be exposed consistently.
Iznimke / Tradeoffi (HR)
Metapodaci koji su namjerno dio javnog ugovora mogu se dosljedno izložiti.