Repository navigation
refactor(server-kit)!: drop vault re-export & add domain-event handler dispose contract - #3113
Conversation
… dispose contract - Remove the vault module entirely (pure @hapic/vault re-export with no monorepo consumers; import @hapic/vault directly instead) and the @hapic/vault dependency. - IDomainEventHandler gains an optional dispose() hook; DomainEventPublisher.dispose() invokes it on every registered handler and clears the registry. DatabaseModule.teardown() disposes the publisher before disconnecting the owned redis client, so future resource-owning handlers clean up on shutdown. BREAKING CHANGE: @authup/server-kit no longer exports VaultClient / createVaultClient.
📝 WalkthroughWalkthroughThe PR implements event publisher disposal lifecycle management by adding optional dispose hooks to domain event handlers, integrating publisher tracking into DatabaseModule for graceful teardown, and removes vault from server-kit's public API while updating documentation to reflect the architectural change. ChangesEvent Publisher Disposal and Server-Kit Cleanup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. 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 |
authup
@authup/client-web
@authup/server-core
@authup/access
@authup/client-web-kit
@authup/client-web-kit-theme
@authup/client-web-nuxt
@authup/client-web-theme
@authup/core-http-kit
@authup/core-kit
@authup/core-realtime-kit
@authup/errors
@authup/i18n
@authup/kit
@authup/server-adapter-kit
@authup/server-adapter-node
@authup/server-adapter-socket-io
@authup/server-adapter-web
@authup/server-kit
@authup/server-test-kit
@authup/specs
commit: |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/server-core/src/app/modules/database/module.ts (1)
108-116:⚠️ Potential issue | 🟠 Major | ⚡ Quick winGuarantee Redis cleanup even when publisher disposal fails.
At Line 109, a thrown error from
await this.eventPublisher.dispose()aborts teardown before Line 114, so the Redis client may never disconnect. Wrap disposal and disconnect paths intry/finallyso connection cleanup is guaranteed.Suggested patch
- if (this.eventPublisher) { - await this.eventPublisher.dispose(); - this.eventPublisher = undefined; - } - - if (this.eventRedisClient) { - this.eventRedisClient.disconnect(); - this.eventRedisClient = undefined; - } + try { + if (this.eventPublisher) { + await this.eventPublisher.dispose(); + } + } finally { + this.eventPublisher = undefined; + + if (this.eventRedisClient) { + this.eventRedisClient.disconnect(); + this.eventRedisClient = undefined; + } + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server-core/src/app/modules/database/module.ts` around lines 108 - 116, The teardown currently calls await this.eventPublisher.dispose() then this.eventRedisClient.disconnect(), but if dispose throws the disconnect is skipped; update the block around this.eventPublisher.dispose() and this.eventRedisClient.disconnect() to ensure Redis is always disconnected by using try/finally: call await this.eventPublisher.dispose() inside the try (guarding null checks on this.eventPublisher), and in the finally ensure this.eventRedisClient.disconnect() and clear this.eventRedisClient regardless of errors; also clear this.eventPublisher = undefined after successful dispose or in a catch as appropriate so both this.eventPublisher and this.eventRedisClient are deterministically cleaned up.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/server-core/src/app/modules/database/module.ts`:
- Around line 108-116: The teardown currently calls await
this.eventPublisher.dispose() then this.eventRedisClient.disconnect(), but if
dispose throws the disconnect is skipped; update the block around
this.eventPublisher.dispose() and this.eventRedisClient.disconnect() to ensure
Redis is always disconnected by using try/finally: call await
this.eventPublisher.dispose() inside the try (guarding null checks on
this.eventPublisher), and in the finally ensure
this.eventRedisClient.disconnect() and clear this.eventRedisClient regardless of
errors; also clear this.eventPublisher = undefined after successful dispose or
in a catch as appropriate so both this.eventPublisher and this.eventRedisClient
are deterministically cleaned up.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1d8c1302-47ef-4380-939f-0375b2fc79bc
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (8)
.agents/structure.mdapps/server-core/src/app/modules/database/module.tspackages/server-kit/package.jsonpackages/server-kit/src/domain-event/module.tspackages/server-kit/src/domain-event/types.tspackages/server-kit/src/index.tspackages/server-kit/src/vault/index.tspackages/server-kit/src/vault/module.ts
💤 Files with no reviewable changes (4)
- packages/server-kit/package.json
- packages/server-kit/src/vault/module.ts
- packages/server-kit/src/vault/index.ts
- packages/server-kit/src/index.ts
Summary
Follow-up to #3112, resolving the two open review points:
packages/server-kit/src/vaultwas a pure re-export of@hapic/vault(VaultClient,createVaultClient) with zero consumers in the monorepo after the singleton removal. The folder and the@hapic/vaultdependency are gone; downstream users should import@hapic/vaultdirectly. (packages/core-http-kit's own@hapic/vaultdependency is unrelated and untouched.)IDomainEventHandlergains an optionaldispose?(): Promise<void>;DomainEventPublisher.dispose()invokes it on every registered handler and clears the registry, andDatabaseModule.teardown()disposes the publisher before disconnecting the redis client it owns — so a future resource-owning handler (own connection, AMQP channel, …) cleans up on shutdown instead of leaking.Breaking changes
@authup/server-kitno longer exportsVaultClient/createVaultClient.Test plan
npm run test --workspace=apps/server-core— 88 files / 865 tests pass@hapic/vaultremoved from server-kit's tree)🤖 Generated with Claude Code
Summary by CodeRabbit
Breaking Changes
@hapic/vaultinstead.New Features
Improvements