Skip to content

registerHook accepts event names the engine never dispatches — read filters on beforeFindOne/beforeCount silently never run #17713

Description

@hotlong

Problem

engine.registerHook(event, handler) accepts an event name the engine never dispatches. It logs a warning, registers the handler anyway, and the handler silently never runs.

The engine dispatches beforeFind / afterFind and the insert / update / delete pairs. beforeFind covers both find and findOne. count() and aggregate() dispatch no hook: they run through the middleware chain only, with the query AST on the operation context.

A downstream consumer registered read filters on beforeFindOne and beforeCount, expecting them to scope single-record reads and list totals. They sat inert through every boot, with about 40 "never dispatches" warnings per boot. The effect:

  • Single-record reads were still filtered, because beforeFind covers findOne.
  • count was not. A limited list returned a total counting rows the caller could not see.
  • aggregate was not either. A groupBy query was not narrowed by the filter at all.

Proposal

  1. Refuse at registration when the event is outside the dispatchable set, in line with ADR-0078 ("no silently inert metadata"). At minimum, make the warning an error in strict or test mode.
  2. Name the seam in the message. For beforeCount and beforeFindOne specifically, say that beforeFind already covers findOne, and that count / aggregate filtering belongs in middleware (operation: 'count' | 'aggregate').
  3. Document in the hook reference that read filters written as hooks do not apply to count / aggregate, and show the middleware equivalent.

Acceptance

  • Registering an undispatchable event fails loudly: it throws, or at least fails in strict mode.
  • A test covers each event name that the engine exposes but never dispatches.
  • The hook documentation lists which operations each event covers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions