Changelog - 2025-12-18
Repository Validation & Security Improvements
In one line. Wrong repository setups and invalid filters now fail loudly instead of silently, and two filter bypasses are fixed.
What changed
@repositoryneedsmodelanddataSource. Both are required for schema auto-discovery, and the first constructor parameter must extendAbstractDataSource.- Filters validate columns. An unknown column in
wherenow throws instead of being ignored. - Security. An empty
INarray now matches no records (it used to returntrue, bypassing filters).BETWEENnow requires an array of exactly 2 elements. - PostgreSQL regex.
REGEXPuses~(case-sensitive). NewIREGEXPuses~*(case-insensitive). logoption. All CRUD operations acceptoptions: { log: { use: true, level: 'debug' } }.- String IDs. They use a
textcolumn with a customizable generator (defaultcrypto.randomUUID()), for exampletext('id').primaryKey().$defaultFn(() => nanoid()). - Datasource schema auto-discovery. Schema is built from
@repositorybindings.
Who is affected
- Anyone with repository classes. Update constructors and decorators (below).
- Anyone using
REGEXPon PostgreSQL. Behavior now follows the PostgreSQL operators above. - Anyone relying on
IN: []matching everything. It now matches nothing.
Breaking changes
WARNING
Repository constructors, the @repository decorator and filters on unknown columns behave differently.
1. Repository constructor signature
Before:
typescript
constructor(opts: {
entityClass: TClass<BaseEntity<EntitySchema>>;
relations: { [relationName: string]: TRelationConfig };
dataSource: IDataSource;
})After:
typescript
constructor(ds?: IDataSource, opts?: { entityClass?: TClass<BaseEntity<EntitySchema>> })Zero boilerplate (recommended), or pass only the datasource:
typescript
@repository({ model: User, dataSource: PostgresDataSource })
export class UserRepository extends DefaultCRUDRepository<typeof User.schema> {
constructor(
@inject({ key: 'datasources.PostgresDataSource' }) ds: PostgresDataSource,
) {
super(ds);
}
}2. @repository requires dataSource
Before: @repository({ model: User }) silently failed to register the model.
After: it throws Invalid metadata | Missing 'dataSource'. Use:
typescript
@repository({ model: User, dataSource: PostgresDataSource })
export class UserRepository extends DefaultCRUDRepository<typeof User.schema> {}3. Constructor parameter type
Before: dataSource: any compiled.
After: use the concrete datasource type:
typescript
constructor(
@inject({ key: 'datasources.PostgresDataSource' })
dataSource: PostgresDataSource,
)4. Filter column validation
Before:
typescript
// Silently ignored 'invalidColumn'
await repo.find({ filter: { where: { invalidColumn: 'value' } } });After:
typescript
// Error: [toWhere] Table: User | Column NOT FOUND | key: 'invalidColumn'
await repo.find({ filter: { where: { invalidColumn: 'value' } } });Details
BETWEENwith a wrong value throws[BETWEEN] Invalid value: expected array of 2 elements.IREGEXPexample:repo.find({ filter: { where: { name: { IREGEXP: '^john' } } } }).