Repository navigation
Conversation
|
Important Review skippedToo many files! This PR contains 239 files, which is 89 over the limit of 150. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (239)
You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe changes implement a repository-based data access pattern for Realm entities, transitioning from handler-centric architecture to hexagonal architecture. A new IEntityRepository interface and RealmRepositoryAdapter using TypeORM provide standardized CRUD and query operations. The RealmController is refactored to use injected repositories, with logic moved from separate handlers into controller methods. Identity repositories are updated to align with the new port interface. Changes
Sequence DiagramsequenceDiagram
participant Client
participant RealmController
participant RealmRepositoryAdapter
participant TypeORM as TypeORM Repository
participant DataSource
Client->>RealmController: GET /realms
activate RealmController
RealmController->>RealmRepositoryAdapter: findMany(query)
activate RealmRepositoryAdapter
RealmRepositoryAdapter->>TypeORM: createQueryBuilder('realm')
RealmRepositoryAdapter->>TypeORM: applyQuery(filters, fields, sort, pagination)
RealmRepositoryAdapter->>TypeORM: getManyAndCount()
TypeORM-->>RealmRepositoryAdapter: [realms[], count]
RealmRepositoryAdapter-->>RealmController: {data: realms[], meta: {pagination, total}}
deactivate RealmRepositoryAdapter
RealmController->>RealmController: formatResponse(data, meta)
RealmController-->>Client: 200 {data, meta}
deactivate RealmController
Client->>RealmController: POST /realms
activate RealmController
RealmController->>RealmController: validatePermissions(CREATE)
RealmController->>RealmController: validateInput(body)
RealmController->>RealmRepositoryAdapter: create(data)
activate RealmRepositoryAdapter
RealmRepositoryAdapter->>TypeORM: save(newRealm)
TypeORM-->>RealmRepositoryAdapter: savedRealm
RealmRepositoryAdapter-->>RealmController: realm
deactivate RealmRepositoryAdapter
RealmController-->>Client: 201 Created {data: realm}
deactivate RealmController
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 8
🧹 Nitpick comments (1)
apps/server-core/src/app/modules/database/repositories/realm/repository.ts (1)
100-102: Type cast inremovemethod.The
as anycast bypasses type safety. Consider aligning the entity type or using a more specific cast if TypeORM'sRepository<RealmEntity>expectsRealmEntityrather thanRealm.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/server-core/src/app/modules/database/repositories/realm/repository.ts` around lines 100 - 102, The remove method currently uses an unsafe cast (entity as any); update it to preserve type safety by passing a RealmEntity to TypeORM instead of casting: either change the repository's generic to Repository<Realm> if the ORM entity truly is Realm, or convert/mapping the incoming Realm DTO to the ORM RealmEntity before calling this.repository.remove; alternatively use this.repository.delete(entity.id) if only the id is available. Make the change in the async remove(entity: Realm): Promise<void> method and ensure types (Realm vs RealmEntity) align with this.repository's declared type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/server-core/src/adapters/http/controllers/entities/realm/module.ts`:
- Around line 217-292: The PUT path must bind the route identifier into the
payload when no entity exists so a create via PUT targets the addressed
resource: inside write(), after obtaining id (getRequestParamID) and before
running the validator (RoutupContainerAdapter/validatorAdapter.run) — when id is
present and entity is null — inject the identifier into the input used for
validation (if isUUID(id) set data.id = id, else set data.name = id), but if the
incoming payload already contains a conflicting id/name throw BadRequestError;
this ensures repository.create(data) and repository.validateJoinColumns(data)
run against the route identifier rather than creating a different realm.
In `@apps/server-core/src/app/modules/database/repositories/realm/repository.ts`:
- Around line 51-55: The allowed filters array passed into applyQuery (in the
repository where pagination is set) contains a duplicate 'built_in' entry; edit
the call that constructs { pagination } = applyQuery(qb, query, { defaultAlias:
'realm', filters: { allowed: [...] } }) to remove the duplicate 'built_in' so
each allowed filter value appears only once (keep the set: 'id', 'built_in',
'display_name', 'name').
- Around line 78-82: The ternary in findOneByIdOrName has inverted logic: when
isUUID(idOrName) is true you should call findOneById, not findOneByName. Update
the function body in findOneByIdOrName to call this.findOneById(idOrName) for
the true branch and this.findOneByName(idOrName, realm) for the false branch
(keeping the realm parameter for the name lookup) so UUIDs resolve by ID and
non-UUIDs resolve by name.
- Around line 29-45: In findOneByName, the initial WHERE binds the wrong
variable and the UUID branch uses the wrong table alias: change
qb.where('realm.name LIKE :name', { name: name }) (or a pattern based on name)
instead of using realmKey, and in the isUUID(realmKey) branch use the realm
alias and id column (e.g., qb.andWhere('realm.id = :realmId', { realmId:
realmKey })) while keeping the non-UUID branch as qb.andWhere('realm.name =
:realmName', { realmName: realmKey }); ensure parameter names match their bound
values and the alias is 'realm' consistently.
In `@apps/server-core/src/app/modules/identity/repositories/client.ts`:
- Around line 34-55: Update the ClientIdentityRepository method signatures to
match the IEntityRepository<Client> interface by adding the required parameters:
change findMany() to findMany(query: Record<string, any>), create() to
create(data: Partial<Client>), merge() to merge(entity: Client, data:
Partial<Client>), save() to save(entity: Client), remove() to remove(entity:
Client), and validateJoinColumns() to validateJoinColumns(data:
Partial<Client>), keeping the existing throw new Error('Method not
implemented.') bodies unchanged; locate these methods by name in client.ts
(methods: findMany, create, merge, save, remove, validateJoinColumns) and update
their parameter lists and return types accordingly.
In `@apps/server-core/src/app/modules/identity/repositories/robot.ts`:
- Around line 34-55: The class methods throw "Method not implemented" but their
signatures do not match the IEntityRepository<Robot> contract; update the method
declarations to include the missing parameters so they preserve the public API:
change findMany() to findMany(query), create() to create(data), merge() to
merge(entity, data), save() to save(entity), remove() to remove(entity), and
validateJoinColumns() to validateJoinColumns(data); keep the existing bodies
(throwing for now) but ensure parameter types match the interface (e.g., query,
data, entity) so TypeScript strict typing and substitutability are satisfied for
findMany, create, merge, save, remove, and validateJoinColumns.
In `@apps/server-core/src/app/modules/identity/repositories/user.ts`:
- Around line 41-63: The UserIdentityRepository currently implements placeholder
methods with no parameters, breaking the IEntityRepository<User> contract;
update the method signatures to match the interface: change findMany to async
findMany(query: Record<string, any>):
Promise<EntityRepositoryFindManyResult<User>>, create to create(data:
Partial<User>): User, merge to merge(target: User, source: Partial<User>): User,
save to async save(entity: User): Promise<User>, remove to async remove(entity:
User): Promise<void>, and validateJoinColumns to async
validateJoinColumns(entity: User): Promise<void> so callers and TypeScript
typing remain compatible (implementations can still throw or be deferred).
In `@plan-hexagonal-repos.md`:
- Around line 68-87: Annotate the three fenced code blocks in the plan that list
file paths (the blocks containing core/entities/{entity}/types.ts …, the "Per
entity, modify:" block with
adapters/http/controllers/entities/{entity}/module.ts …, and the "Per entity,
dead code after migration:" block with
adapters/http/controllers/entities/{entity}/handlers/) by adding a language tag
(e.g., ```text) to each opening fence so markdownlint MD040 is resolved; update
those three triple-backtick openings to include the language and leave the
enclosed content unchanged.
---
Nitpick comments:
In `@apps/server-core/src/app/modules/database/repositories/realm/repository.ts`:
- Around line 100-102: The remove method currently uses an unsafe cast (entity
as any); update it to preserve type safety by passing a RealmEntity to TypeORM
instead of casting: either change the repository's generic to Repository<Realm>
if the ORM entity truly is Realm, or convert/mapping the incoming Realm DTO to
the ORM RealmEntity before calling this.repository.remove; alternatively use
this.repository.delete(entity.id) if only the id is available. Make the change
in the async remove(entity: Realm): Promise<void> method and ensure types (Realm
vs RealmEntity) align with this.repository's declared type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a5b2e78f-3ded-48e8-bb03-df609019f8f0
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (18)
.claude/settings.local.jsonAGENTS.mdapps/server-core/package.jsonapps/server-core/src/adapters/http/controllers/entities/realm/index.tsapps/server-core/src/adapters/http/controllers/entities/realm/module.tsapps/server-core/src/app/modules/database/index.tsapps/server-core/src/app/modules/database/repositories/index.tsapps/server-core/src/app/modules/database/repositories/realm/index.tsapps/server-core/src/app/modules/database/repositories/realm/repository.tsapps/server-core/src/app/modules/http/modules/controller.tsapps/server-core/src/app/modules/identity/repositories/client.tsapps/server-core/src/app/modules/identity/repositories/robot.tsapps/server-core/src/app/modules/identity/repositories/user.tsapps/server-core/src/core/entities/index.tsapps/server-core/src/core/entities/realm/index.tsapps/server-core/src/core/entities/realm/types.tsapps/server-core/src/core/entities/types.tsplan-hexagonal-repos.md
💤 Files with no reviewable changes (1)
- apps/server-core/src/adapters/http/controllers/entities/realm/index.ts
| private async write(req: Request, res: Response, options: { | ||
| updateOnly?: boolean | ||
| } = {}): Promise<any> { | ||
| let group: string; | ||
| const id = getRequestParamID(req, { isUUID: false }); | ||
|
|
||
| let entity: Realm | null | undefined; | ||
| if (id) { | ||
| const where: Record<string, any> = {}; | ||
| if (isUUID(id)) { | ||
| where.id = id; | ||
| } else { | ||
| where.name = id; | ||
| } | ||
|
|
||
| entity = await this.repository.findOneBy(where); | ||
| if (!entity && options.updateOnly) { | ||
| throw new NotFoundError(); | ||
| } | ||
| } | ||
|
|
||
| const permissionChecker = useRequestPermissionChecker(req); | ||
| if (entity) { | ||
| await permissionChecker.preCheck({ name: PermissionName.REALM_UPDATE }); | ||
|
|
||
| group = RequestHandlerOperation.UPDATE; | ||
| } else { | ||
| await permissionChecker.preCheck({ name: PermissionName.REALM_CREATE }); | ||
|
|
||
| group = RequestHandlerOperation.CREATE; | ||
| } | ||
|
|
||
| const validator = new RealmValidator(); | ||
| const validatorAdapter = new RoutupContainerAdapter(validator); | ||
| const data = await validatorAdapter.run(req, { | ||
| group, | ||
| }); | ||
|
|
||
| await this.repository.validateJoinColumns(data); | ||
|
|
||
| if (entity) { | ||
| await permissionChecker.check({ | ||
| name: PermissionName.REALM_UPDATE, | ||
| input: new PolicyData({ | ||
| [BuiltInPolicyType.ATTRIBUTES]: { | ||
| ...entity, | ||
| ...data, | ||
| }, | ||
| }), | ||
| }); | ||
|
|
||
| if (entity.name === REALM_MASTER_NAME && isPropertySet(data, 'name') && entity.name !== data.name) { | ||
| throw new BadRequestError(`The name of the ${REALM_MASTER_NAME} can not be changed.`); | ||
| } | ||
| } else { | ||
| await permissionChecker.check({ | ||
| name: PermissionName.REALM_CREATE, | ||
| input: new PolicyData({ | ||
| [BuiltInPolicyType.ATTRIBUTES]: data, | ||
| }), | ||
| }); | ||
| } | ||
|
|
||
| // ---------------------------------------------- | ||
|
|
||
| if (entity) { | ||
| entity = this.repository.merge(entity, data); | ||
| await this.repository.save(entity); | ||
|
|
||
| return sendAccepted(res, entity); | ||
| } | ||
|
|
||
| entity = this.repository.create(data); | ||
| await this.repository.save(entity); | ||
|
|
||
| return sendCreated(res, entity); |
There was a problem hiding this comment.
Bind the PUT /realms/:id identifier when falling back to create.
When Line 221 resolves a path identifier but no entity exists, the create branch never copies or validates that identifier before this.repository.create(data). As written, PUT /realms/foo can create a different realm than foo, which breaks the addressed-resource semantics of the endpoint. Either make put() update-only as well, or inject/validate the route identifier before the create path runs.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/server-core/src/adapters/http/controllers/entities/realm/module.ts`
around lines 217 - 292, The PUT path must bind the route identifier into the
payload when no entity exists so a create via PUT targets the addressed
resource: inside write(), after obtaining id (getRequestParamID) and before
running the validator (RoutupContainerAdapter/validatorAdapter.run) — when id is
present and entity is null — inject the identifier into the input used for
validation (if isUUID(id) set data.id = id, else set data.name = id), but if the
incoming payload already contains a conflicting id/name throw BadRequestError;
this ensures repository.create(data) and repository.validateJoinColumns(data)
run against the route identifier rather than creating a different realm.
| async findMany(): Promise<EntityRepositoryFindManyResult<User>> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
|
|
||
| create(): User { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
|
|
||
| merge(): User { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
|
|
||
| async save(): Promise<User> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
|
|
||
| async remove(): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
|
|
||
| async validateJoinColumns(): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "IEntityRepository contract:"
sed -n '18,40p' apps/server-core/src/core/entities/types.ts
echo
echo "UserIdentityRepository placeholder signatures:"
sed -n '41,63p' apps/server-core/src/app/modules/identity/repositories/user.tsRepository: authup/authup
Length of output: 1358
Align UserIdentityRepository method signatures with IEntityRepository<User> contract.
The placeholder implementations erase all required parameters from the interface contract. For example, findMany() should accept query: Record<string, any>, create() should accept data: Partial<User>, and save() should accept entity: User. Without matching parameter signatures, the concrete class violates TypeScript strict typing and causes type incompatibility with callers that depend on the IEntityRepository<User> contract. Restore the parameter lists even if implementations remain deferred.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/server-core/src/app/modules/identity/repositories/user.ts` around lines
41 - 63, The UserIdentityRepository currently implements placeholder methods
with no parameters, breaking the IEntityRepository<User> contract; update the
method signatures to match the interface: change findMany to async
findMany(query: Record<string, any>):
Promise<EntityRepositoryFindManyResult<User>>, create to create(data:
Partial<User>): User, merge to merge(target: User, source: Partial<User>): User,
save to async save(entity: User): Promise<User>, remove to async remove(entity:
User): Promise<void>, and validateJoinColumns to async
validateJoinColumns(entity: User): Promise<void> so callers and TypeScript
typing remain compatible (implementations can still throw or be deferred).
Summary by CodeRabbit
Release Notes
New Features
Chores