Skip to main content
The @talosjs/repository component is a thin data access layer. You register a repository class with a decorator, implement the IRepository contract, and resolve it from the container. The contract standardizes how repositories open and close their data source and return paginated, searchable results, so every repository in your app reads and writes the same way no matter what database sits underneath.

What the contract standardizes

IRepository<T, TCriteria> defines open, close, and find, and you implement it the same way for any data source. find is paginated: it returns a FilterResultType<T> carrying resources, total, totalPages, page, and limit, and it accepts an optional q query string alongside your own criteria fields for search. Generics thread your entity type T and criteria type TCriteria through the whole API. Register a repository with a decorator and you can resolve or inject it anywhere, at whichever scope you choose.

How it works

A repository implements the IRepository interface and is registered with @decorator.repository(). The decorator adds the class to the @talosjs/container, so you resolve it instead of constructing it by hand. The contract is intentionally small: find always merges your own filter fields with three reserved keys: The result is always shaped the same way:

Decorator and usage

@decorator.repository(scope?)

Registers a repository class with the container. It accepts an optional scope (defaults to EContainerScope.Singleton). Implement the IRepository<T, TCriteria> contract on your class:
Resolve it from the container and run a paginated, filtered query:
Pass a scope when you need a fresh instance per resolution:

Building dependable repositories

Provide open, close, and find on every repository so callers can treat them all identically. Default page to 1 and limit to a bounded value, and never return an unbounded result set. Compute totalPages with Math.ceil(total / limit) so callers can paginate reliably. Destructure page, limit, and q out of the criteria before building the query, then apply the rest as filter fields. Honor q consistently by applying the same search predicate to both the result query and the count, so the total matches the page. Pull repositories from the container, or inject them, rather than using new, so scope and dependencies wire up correctly. Choose the scope to fit the repository: Singleton for shared, stateless ones, and Transient or Request when each consumer needs isolated state.

CLI command

Scaffold a repository class and its test file with the generator. It writes the class under modules/<module>/src/repositories/<Name>Repository.ts, a spec under modules/<module>/tests/repositories/, and installs @talosjs/repository if it is missing.
The generated class is a TypeORM-backed repository with open, close, find (paginated + searchable), and full CRUD methods, ready for you to wire up to your entity:
See repository:create for the full command reference.

Use with Claude and Codex

The generator ships a matching repository:create skill. It runs the scaffold, then guides your AI agent through completing the repository: verifying the entity import path, adjusting the find search fields, and trimming or adding CRUD methods to fit the entity. Initialize the skills once for your agent.
Then ask Claude in natural language. It maps the request to the generator, runs it, and fills in the implementation:
Prompt
For example, the prompt above maps to repository:create --name=User, then completes the CRUD methods against the User entity.