Skip to content

fix(routes): run every database query with .run() for interface-database 0.4 - #133

Merged
Upd4ting merged 2 commits into
mainfrom
fix/run-database-queries
Nov 13, 2026
Merged

Upd4ting merged 2 commits into
mainfrom
fix/run-database-queries

Conversation

@Upd4ting

Copy link
Copy Markdown
Member

Why

ANT-2424. interface-database 0.4.0 made queries non-thenable: a query runs only through .run(). DefaultRoutes awaited queries directly. On interface-database 0.4.0 with mongodb 1.8.0, New answered 500 "(intermediate value) is not iterable", List returned its total as a query object, and Get, Edit and Delete handled query objects instead of rows (found by ANT-2382 on dms). This PR runs every query, and keeps interface-database 0.3 working.

What

  • Every awaited query in src now runs through .run(). The sweep is type-aware: with the 0.4 types, oxlint's await-thenable reported each awaited query and each query passed to Promise.all. A TypeScript-checker codemod appended .run() to every expression typed as a query, and three optional chains (Schema.get(...)?.…delete()) were fixed by hand. await-thenable now reports none.
    • In DefaultRoutes: Get (fromDatabase(await query.run())), List (Promise.all([queryPaged.run(), queryTotal.run()])), New (insert(...).run()), Edit (the Query.Get read and the update), and Delete.
    • The rest are test fixtures and helpers.
  • No other path leaves a query unrun. A checker scan found no async function in src that returns a query, and no .then on one. Query.Get, Query.List, Query.ListPage and Query.Delete still return queries for the caller to run, unchanged.
  • The deferred-joined wrapper answers itself from cast. In 0.4, Stream.cast() returns new Stream(undefined, this), which copies the wrapper's raw stages into a plain stream and drops the deferred @Joined lookups. listAsConsumer-style callers then lost every joined field (10 failing tests). In 0.3, cast returned this; the wrapper's cast now does that on every version.
  • docs/10.joined.md runs Query.ListPage(...) and the total with .run(), and says Query.* results are queries to run.
  • Dev and test setup. @antelopejs/interface-database dev dependency ^0.4.0. The test project and the verify harness move to @antelopejs/mongodb 1.8.0, which implements 0.4. README tested-with reads 0.4.0.
flowchart LR
  route["DefaultRoutes / Query helpers"] --> q["Query (0.4: not thenable)"]
  q -- "before: await query" --> obj["query object: 500, total = object"]
  q -- "now: await query.run()" --> rows["rows / count / ids"]
  list["Query.List wrapper"] -- ".cast() keeps the wrapper" --> joined["deferred @Joined lookups kept"]
Loading

Supported range

@antelopejs/interface-database stays >=0.1.10 <1.0.0. .run() exists on every version from 0.1.10 to 0.4.0, so 0.3 keeps working: the full suite passes on 0.3.3 with mongodb 1.7.0 (220 passing). No peer change, so this fits dms#888's >=0.7.2 <0.8.0 pin as a 0.7.x patch.

Attention

  • Consumers on interface-database 0.4 must call .run() on whatever they await from Query.List (the stream and the total), Query.ListPage, Query.Get and Query.Delete. An await without it answers the query object, as the dms /count/batch symptom shows.
  • Declarations are unchanged and runtime exports are identical (27 names). antelopejs-api-diff origin/main cannot build its base, because origin/main does not compile against interface-database 0.4. The comparison below builds origin/main with its own lockfile.

SAFETY comments added

None. The suppression budget is unchanged.

Proof

Before: origin/main's src/index.ts and deferred wrapper, with only the test code moved to .run(), on interface-database 0.4.0 and mongodb 1.8.0. 112 passing, 108 failing:

     12 Field Listable
     10 Query.List deferred joined self-resolution
      9 Field Joined
      8 Partial edit
      7 Field Computed
      6 Integration tests
      5 Routes
      5 Field Access Control
      4 Modifier key with foreign fields
      4 List route - filter comparisons
      4 Foreign relation with @Joined target label
      4 Field Mandatory
      3 List route - a field named like an Object.prototype member
      3 List getters per pluck mode
      3 Get loaded-model guard
      3 Foreign multi references
      3 Foreign and Computed fields on the same key
      3 Field Validator parsed value
      3 Derived data controllers
      2 Per-Action Access Control
      2 Localized sort
      2 Field Validator
      2 Edit with the index option
      1 New route - a field named like an Object.prototype member

The messages are mostly expected 500 to equal 200, plus list failed (500): object is not iterable and expected undefined to equal 'Alice Carter' (joined fields lost after cast).

After, on this head with interface-database 0.4.0 and mongodb 1.8.0: pnpm run checks 11 passed, 0 failed, with 220 tests. pnpm exec tsc -p docs/tsconfig.json passes.

0.3: the same head with interface-database 0.3.3 and mongodb 1.7.0 gives 220 passing.

verify-interface on this head (interface-database 0.4.0, mongodb 1.8.0), all 13 features: 55 of 55 journeys pass.

Declarations, origin/main built with its own lockfile against HEAD: no .d.ts differs. Runtime exports of index, metadata and components (names and typeof): identical, 27 names.

@Upd4ting
Upd4ting merged commit 2def09c into main Nov 13, 2026
10 checks passed
@Upd4ting
Upd4ting deleted the fix/run-database-queries branch November 13, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant