ReviewOS

stacks/bun-query-builder

createQueryBuilder({ hooks }) is a compile error, and the as-any workaround silently never fires

#1071
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days ago

createQueryBuilder<DB>(state?: Partial<InternalState>) has no hooks member, so the widely-documented form is a compile error:

const db = createQueryBuilder<typeof schema>({ schema, meta, hooks: { ... } })
//                                                        ~~~~~ TS2353

It appears in ~12 files including README.md:164. Two problems compound:

  1. It does not compile — TS2353: Object literal may only specify known properties.
  2. The natural workaround, as any, compiles and then silently never fires the hooks, because hooks are read from the process-wide config, not from builder state. Users get a builder that looks configured and quietly ignores every hook.

The second is the harmful one: a silent no-op is worse than the compile error that precedes it.

Fix, in preference order:

  • Accept hooks in createQueryBuilder and merge it into the config the builder reads, making the documented form true; or
  • Leave the API as-is and correct the docs to setConfig({ hooks }), stating explicitly that hooks are process-wide rather than per-builder.

The first matches what the docs have promised for a long time. The second is a one-line docs change but leaves a real ergonomic gap, since per-builder hooks are the reasonable expectation.

Found while auditing after #1001.

Sign in to comment on this issue.