|
| 1 | +--- |
| 2 | +"@objectstack/spec": major |
| 3 | +"@objectstack/driver-sql": major |
| 4 | +"@objectstack/driver-memory": major |
| 5 | +"@objectstack/driver-mongodb": major |
| 6 | +--- |
| 7 | + |
| 8 | +refactor(spec,drivers)!: retire `IDataDriver.findStream` — a required method with no caller, whose two main implementations did the opposite of what it promised (#4484, ADR-0049 enforce-or-remove) |
| 9 | + |
| 10 | +`findStream` was a **required** method on the driver contract — every driver and |
| 11 | +every test double had to implement it — documented as the read |
| 12 | + |
| 13 | +> Optimized for large datasets to avoid memory overflow. |
| 14 | +
|
| 15 | +Three things were true about it at once, and each is worse in the light of the |
| 16 | +others. |
| 17 | + |
| 18 | +**Nothing called it.** Not the query engine (there is no `stream` entry on it), |
| 19 | +not REST export, not import, not any bulk-read path. Repo-wide, outside the |
| 20 | +contract declaration and the three driver implementations, every single hit was |
| 21 | +a test double — and roughly twenty of those satisfied the required method like |
| 22 | +this: |
| 23 | + |
| 24 | +```ts |
| 25 | +findStream() { throw new Error('not implemented'); } |
| 26 | +``` |
| 27 | + |
| 28 | +Twenty stubs that throw, across four packages, for years, and no test ever went |
| 29 | +red. That is not an anecdote about test hygiene; it is the proof of absence. A |
| 30 | +method whose every double throws is a method nothing reaches. |
| 31 | + |
| 32 | +**Two of the three implementations inverted its one guarantee.** `SqlDriver` and |
| 33 | +`InMemoryDriver` both did this: |
| 34 | + |
| 35 | +```ts |
| 36 | +const results = await this.find(object, query, options); // ← the entire result set |
| 37 | +for (const row of results) yield row; |
| 38 | +``` |
| 39 | + |
| 40 | +The whole table is resident in memory before the first `yield`. A caller who |
| 41 | +believed the doc comment and reached for `findStream` precisely because a result |
| 42 | +set was too large would have hit the overflow it existed to prevent, at exactly |
| 43 | +the scale where it mattered. `SqlDriver` carried a `TODO: Use Knex .stream()` |
| 44 | +admitting it. |
| 45 | + |
| 46 | +**The one real implementation dropped a parameter.** `MongoDBDriver._findStream` |
| 47 | +did walk a cursor — but it was the only read in that driver never routed through |
| 48 | +`buildFindOptions`, so it hardcoded `projection: { _id: 0 }` and silently |
| 49 | +discarded `query.fields`. (#4459 unified `find`/`findOne` onto `buildFindOptions` |
| 50 | +and recorded in its TSDoc that `_findStream` was left out. This removal subsumes |
| 51 | +that divergence rather than fixing it — there is nothing left to fix it for.) |
| 52 | + |
| 53 | +Rather than manufacture a caller to justify three implementations, the method is |
| 54 | +retired. If a cursor-based read is wanted, it should arrive **with** the caller |
| 55 | +that needs it, so the contract can be shaped by a real requirement instead of |
| 56 | +being reverse-engineered from a doc comment nobody could test. |
| 57 | + |
| 58 | +**Migration.** |
| 59 | + |
| 60 | +| Wrote | Write instead | |
| 61 | +| --- | --- | |
| 62 | +| `for await (const row of driver.findStream(obj, q)) { … }` | page `driver.find(obj, { ...q, limit, offset })` in a loop | |
| 63 | +| `findStream(…) { … }` on your own driver | delete the method (see below) | |
| 64 | +| `findStream() { throw new Error('ni'); }` in a test double | delete the line | |
| 65 | + |
| 66 | +Paging `find()` is not a downgrade from what `findStream` actually did: on SQL |
| 67 | +and memory it is strictly better (bounded pages instead of one full |
| 68 | +materialisation), and the paged read is the one with an **enforced** guarantee — |
| 69 | +`IDataDriver.find` requires a total order across the whole walk, checked by the |
| 70 | +shared `PAGINATION_CASES` / `PAGINATION_UNORDERED_CASES` fixtures in |
| 71 | +`data/pagination-conformance.ts`. `findStream` never had a conformance case at |
| 72 | +all. |
| 73 | + |
| 74 | +**Driver authors: nothing breaks on you.** An implementation left in place still |
| 75 | +compiles — an extra method is not an error on a class or a widened object — it is |
| 76 | +simply never reached, so deleting it is cleanup you can do whenever. The break is |
| 77 | +on the **caller** side: `driver.findStream(...)` no longer type-checks, and there |
| 78 | +were no callers. |
| 79 | + |
| 80 | +**No tombstone, deliberately.** The other v17 retirements tombstone their key so |
| 81 | +authoring it fails loudly with a prescription. That would be noise here. |
| 82 | +`DriverInterfaceSchema` describes a contract that code *implements*; nothing in |
| 83 | +either repository ever ran a driver object through `.parse()`, so a |
| 84 | +`retiredKey()` there would carry its prescription to no one. The channel that can |
| 85 | +carry it is `tsc`, and `tsc` reports it where it is actionable — at a call site. |
| 86 | +The key is removed from the schema and from `IDataDriver`, and the retirement is |
| 87 | +registered as the `data-driver-find-stream-retired` semantic entry in the |
| 88 | +protocol-17 chain step (ADR-0087 D3), so `spec-changes.json`, the generated |
| 89 | +upgrade guide and the `spec_changes` MCP tool all carry it. There is no |
| 90 | +`os migrate meta` step: a driver is code, never stack metadata, so the chain has |
| 91 | +no source to rewrite. |
| 92 | + |
| 93 | +**Left standing on purpose:** `DriverCapabilities.streaming`, the capability flag |
| 94 | +whose only referent was this method. It has no readers either (and the values |
| 95 | +written into it were already wrong — `SqlDriver` declared `streaming: false` |
| 96 | +while implementing `findStream`, `InMemoryDriver` declared `true` for the |
| 97 | +copy-everything version), but removing a key from the capabilities literal breaks |
| 98 | +every driver that writes it, third-party included, and the same audit should |
| 99 | +cover the other ~30 flags in one pass rather than one at a time. Tracked as |
| 100 | +#4634. |
0 commit comments