Changelog - 2026-11-08
CrudControllerFactory.build and SearchControllerFactory.build replace the define functions, and a controller has the routes you list
Breaking New FeatureIn one line. CrudControllerFactory.build({ repository, routes }) and SearchControllerFactory.build({ repository, routes }) build a controller from the repository class. A route you list exists and a route you do not list does not. The class ControllerFactory is renamed CrudControllerFactory and defineCrudController is gone, with no alias: ControllerFactory is no longer exported.
What changed
CrudControllerFactory.buildtakes the repository class. The entity comes from@repository({ model })on that class, so you name it once. The container injects the repository by the class name.- The path is only on
@controller({ path }). The name is the class name.controller.basePathandcontroller.nameare gone. routesis the whole list.routes: { find: true, create: true }builds those two routes. A route takestrueor a config (authenticate,authorize,request,response), and a route's ownauthenticateandauthorizereplace the controller's.CrudRoutes.READlists the four read routes:count,find,findById,findOne.routes: { ...CrudRoutes.READ, create: true }adds one write route.- Restore routes are new.
restoreByIdisPOST /{id}/restore, andrestoreByisPOST /restorewithwherein the query. They are checked against the UPDATE scope of the model. There is no route that lists deleted rows. - A restore route needs a repository that has both restore methods. The types refuse
restoreByIdandrestoreByfor a repository class that lacks either one, and the build throws for a caller the types do not reach. - The generated routes register after the subclass's
binding(). A custom static path you declare there, such asGET /featured, is no longer taken byGET /{id}. The same order means a customGET /countinbinding()now shadows the generatedcountroute, where before the generated one came first. - A new hook,
bindDefaultRoutes(), onBaseRestController. It registers the routes a generated controller brings, afterbinding(). A hand-written controller does not need it. - The row types come from the repository class.
AbstractRepositorycarries two phantom markers,$inferDataand$inferPersist(no runtime value), the way an entity does, andTRepositoryDataObjectandTRepositoryPersistObjectread them.this.repositoryand the payloads of a generated controller are typed with the exact row of a relational table or a search document. - The write-route check covers only listed routes.
CrudControllerFactory.buildstill refuses to boot when a listed write route would inherit a controller-levelauthorizewhose action isread. A route you do not list is not checked. - An update reads its
dataonce.updateById,updateBy,updateEach,upsertand a soft delete copy the caller'sdatainto a plain object, check that copy fordeletedAt, and write that same copy. - The old-function-names codemod follows the rename.
registerFactoryRepositoryInjectionis rewritten toCrudControllerFactory.registerRepositoryInjection. SearchControllerFactory.buildreplacesSearchControllerFactory.defineSearchController, with the same shape: the repository class,routes: { search: true, multiSearch: true }, the path on@controller, and the document type from the repository class.scope,engineParams,modes,authenticateandauthorizeare unchanged. A scoped controller cannot listmultiSearch, andbuildthrows when it does.
Who is affected
- Every call to
ControllerFactory.defineCrudController, and every other use of the nameControllerFactory(an import, a type, a static such asregisterRepositoryInjection). Rewrite the call toCrudControllerFactory.build, as below, and rename the rest toCrudControllerFactory. - A CRUD controller that used
controller.readonly,controller.enabledRoutesor a route'senabled. List the routes instead. - A CRUD controller subclass that called
super.binding(). The generatedbinding()is now empty, so the call does nothing: delete it. - A call that gave
controller.isStrict, anentitythat is not the model of the repository, or type arguments (defineCrudController<TRecord>). See the three rewrites below. - Code that imports
ICrudControllerOptions. Its type parameter is now the repository class, not the route map. - Code that extends
AbstractCrudController, or callsCrudControllerFactory.assertWriteVerbsDeclareAuthorize(before:ControllerFactory.) orRouteConfigResolver.defineControllerRouteConfigs.AbstractCrudControllerno longer takes apathoption (the path is the@controllerone).assertWriteVerbsDeclareAuthorizetakes{ repositoryName, authorize, routes }instead of{ controllerName, authorize, routes, readonly, enabledRoutes }.defineControllerRouteConfigslost itsRoutestype parameter, and builds a definition only for a listed route. - A repository class that subclasses
AbstractRepositoryand declares a member named$inferDataor$inferPersist. Rename it. - Every call to
SearchControllerFactory.defineSearchController. Rewrite it as below. A repository class with no document type (extends DefaultSearchRepository) fails to compile against the controller until it names the type:DefaultSearchRepository<TArticle>. - A custom controller factory that calls
ControllerFactory.registerRepositoryInjection. It is nowCrudControllerFactory.registerRepositoryInjection, and the optioncontrollerNameis removed. - A repository class with no
@repository({ model }).CrudControllerFactory.buildcannot resolve the entity and throws at build. - Everyone else. No action needed.
Breaking changes
WARNING
Every CRUD controller built with defineCrudController stops compiling. Each old form has one new form.
The factory, the path and the entity:
// Before
const _Controller = ControllerFactory.defineCrudController({
entity: () => Note,
repository: { name: NoteRepository.name },
controller: { name: 'NoteController', basePath: '/notes' },
});
@controller({ path: '/notes' })
export class NoteController extends _Controller {}
// After
const _Controller = CrudControllerFactory.build({
repository: NoteRepository, // @repository({ model: Note, ... }) supplies the entity
routes: { ...CrudRoutes.READ, create: true, updateById: true, updateBy: true, deleteById: true, deleteBy: true },
});
@controller({ path: '/notes' })
export class NoteController extends _Controller {}The old call built all nine routes. List all nine to keep them.
controller.isStrict moves to the top level:
// Before
controller: { name: 'NoteController', basePath: '/notes', isStrict: { path: true, requestSchema: true } },
// After
isStrict: { path: true, requestSchema: true },An entity thunk or class moves to the repository. The entity of a controller is the model of its @repository decorator, which takes a class or a thunk. A controller whose entity was not the model of its repository has no equivalent: give it a repository class whose model is that entity.
// Before
ControllerFactory.defineCrudController({ entity: () => Note, repository: { name: NoteRepository.name }, ... });
// After
@repository({ model: () => Note, dataSource: PostgresDataSource })
export class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}
CrudControllerFactory.build({ repository: NoteRepository, ... });Type arguments are gone. CrudControllerFactory.build takes the row types from the repository class, so drop them:
// Before
ControllerFactory.defineCrudController<TNote>({ ... });
// After
CrudControllerFactory.build({ ... });SearchControllerFactory.defineSearchController:
// Before
const _Search = SearchControllerFactory.defineSearchController({
entity: ArticleDocument,
repository: { name: ArticleRepository.name },
controller: { name: 'ArticleSearchController', basePath: '/articles', isStrict: true },
routes: { multiSearch: { enabled: false } },
});
// After
const _Search = SearchControllerFactory.build({
repository: ArticleRepository, // @repository({ model: ArticleDocument, ... }) supplies the entity
isStrict: true,
routes: { search: true },
});Both routes were on before unless you turned one off: list search: true, multiSearch: true to keep both.
controller.readonly:
// Before
controller: { name: 'NoteController', basePath: '/notes', readonly: true },
// After
routes: CrudRoutes.READ,controller.enabledRoutes:
// Before
controller: { name: 'NoteController', basePath: '/notes', enabledRoutes: ['count', 'create'] },
// After
routes: { count: true, create: true },A route's enabled: false:
// Before: every route on, two switched off
routes: { deleteBy: { enabled: false }, updateBy: { enabled: false } },
// After: list the seven you want
routes: { ...CrudRoutes.READ, create: true, updateById: true, deleteById: true },A route's enabled: true with a config:
// Before
routes: { findById: { enabled: true, request: { params: IdSchema } } },
// After
routes: { findById: { request: { params: IdSchema } } },super.binding() in a CRUD controller:
// Before
override binding() {
super.binding();
this.defineRoute({ configs: featuredConfigs, handler: (context) => this.featured({ context }) });
}
// After
override binding() {
this.defineRoute({ configs: featuredConfigs, handler: (context) => this.featured({ context }) });
}registerRepositoryInjection in a custom factory:
// Before
ControllerFactory.registerRepositoryInjection({
target: GeneratedController,
factoryName: 'defineReportController',
controllerName: 'ReportController',
repositoryName: ReportRepository.name,
});
// After
CrudControllerFactory.registerRepositoryInjection({
target: GeneratedController,
factoryName: 'defineReportController',
repositoryName: ReportRepository.name,
});Find the call sites:
rg -n '\bControllerFactory\b|defineCrudController|defineSearchController' --glob '*.{ts,tsx,js,mjs,cjs}' --glob '!node_modules' # SearchControllerFactory is another class and stays
rg -n 'enabledRoutes|\breadonly:\s*true|\benabled:\s*(true|false)' --glob '*.{ts,tsx,js,mjs,cjs}' --glob '!node_modules' # enabled: also matches unrelated options; read each hit
rg -n 'basePath|controller:\s*\{|isStrict' --glob '*.{ts,tsx,js,mjs,cjs}' --glob '!node_modules' # controller: { name, basePath, isStrict } of a CRUD factory call
rg -n 'super\.binding\(\)' --glob '*.{ts,tsx,js,mjs,cjs}' --glob '!node_modules'
rg -n 'controllerName' --glob '*.{ts,tsx,js,mjs,cjs}' --glob '!node_modules'The typecheck finds the rest: "Property 'defineCrudController' does not exist".
Details
| File | Package |
|---|---|
src/base/controllers/factory/{controller,definition}.ts, src/base/controllers/common/{constants,types/*}.ts | kernel |
src/base/controllers/factory/crud/{abstract,persistable}.ts, src/base/controllers/rest/abstract.ts | kernel |
src/relational/core/repositories/core/{persistable,soft-deletable}.ts | connectors |
src/search/core/controllers/{factory,abstract}.ts | connectors |