entity-models

Defines conventions for declaring entity record models and mappers in TypeScript namespaces.

1|Updated Jan 14, 2024
One-click install
npx skills add https://github.com/Eyhenij/rt-tools --skill entity-models-eyhenij
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: entity-models
Source: https://github.com/Eyhenij/rt-tools/tree/main/.claude/skills/entity-models
Command: npx skills add https://github.com/Eyhenij/rt-tools --skill entity-models-eyhenij

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Teams building Angular applications with contract-driven backends often end up with inconsistent entity models: contract types leak into templates, hand-written copies of generated types silently diverge, and null handling varies per developer. This rule standardizes how record models and their mappers are declared so every entity follows the same structure. ## Core Features & Use Cases - Two-sided model convention: Declares Api (contract side) and State (screen side) inside one I<Entity> namespace, with optional Draft and nested Short levels for list rows. - Mapper discipline: Requires a mapper inheriting BaseMapper between the sides, with casts going through this.typeCast instead of ?? fallbacks, and screens reading only State. - Shared selection types: Mandates page, order, and filter types from @rt-tools/utils so no duplicate pagination types are created. - Use Case: When adding a new entity to an admin panel, load this rule to declare the namespace, levels, and mapper correctly, regenerate the contract, and avoid pitfalls like as Type casts or optional scalar fields. ## Quick Start Load the entity-models rule and declare a new record model with its namespace, levels, and BaseMapper-based mapper following the entity-models-new pattern.

Frequently Asked Questions about entity-models

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure an entity model in an Angular TypeScript project?

Declare both sides of the entity in one namespace named I<Entity>: an Api type aliasing the generated contract type and a readonly State type for screens. Place a mapper inheriting BaseMapper between them, and add a nested Short namespace for list-row levels.

How to map contract types to UI state without leaking them into templates?

Use a dedicated mapper per level that inherits BaseMapper and performs casts through this.typeCast rather than ?? fallbacks or as Type assertions. Screens and templates must read only the State side, never the contract type.

Should contract types be written by hand or generated?

The contract side should be declared as an alias of the generated type, not written by hand, because a hand-written copy diverges silently from the contract. In trees without a generator, a single shared hand-written declaration read by both sides is the documented exception.

Why avoid null and optional fields in entity State models?

Contracts with no optional scalars return default values rather than emptiness, so State expresses empty as an empty string or zero with an explanatory comment. Introducing null or undefined adds a second emptiness convention that checks for undefined cannot catch.

What are the limitations of getAsType in type casting?

getAsType accepts no default value: when a value falls outside the allowed set it logs to the console and returns the string 'unknown'. String fields with a closed set of values must be checked against the set explicitly.