Repository navigation
Commit 49982f7
Stop hand-editing the @bb/db data export list (#7554)
## Human comments
## What was wrong
`packages/db/src/data/index.ts` re-exported every public data function,
type, and constant by name: 582 lines, 512 names across 38 modules.
Adding or renaming any data function meant editing that list, and 82
commits touched it in the last 60 days, so two open PRs that each add a
data function usually conflicted there. The list also served as the
public/private filter for `@bb/db`. It hid 11 helper modules entirely
and, inconsistently, about 20 helpers in otherwise-public modules. Only
one of those hidden groups was deliberate: the environment-lifecycle
writers, which `apps/server` reaches through
`@bb/db/internal-environment-lifecycle`.
## What changed
- `packages/db/src/data/index.ts` is now one `export * from
"./<module>.js"` line per public module (38 lines). A module is public
if and only if it is listed there; unlisted modules stay
package-private. Adding, renaming, or deleting a function in a public
module no longer touches a shared file. Only a new public module adds
one line. That happened in 9 of the 82 commits, and a sorted
one-line-per-module list conflicts only on adjacent insertions.
- The deliberately internal environment writers moved out of
`environments.ts` into a new private module,
`packages/db/src/data/environment-lifecycle.ts`:
`applyEnvironmentLifecycleEvent`,
`applyEnvironmentLifecycleEventInTransaction`,
`recordProvisionedEnvironmentWorkspace`, and the shared
`updateEnvironmentMetadataRecord`. So the root `@bb/db` still does not
expose them. `updateEnvironmentMetadata` and
`recordEnvironmentCurrentBranch` share the private record writer, and
every writer reads through `getEnvironment`, so those three live in that
module too. `environments.ts` imports and re-exports them, so they stay
public. The private module imports nothing from `environments.ts`, so
the dependency runs one way and the data modules still have no
value-import cycles, as on main. `@bb/db/internal-environment-lifecycle`
now re-exports from the new module and exports the same 4 values and 2
types as before.
- `CreateProjectSourceInput` was declared, with different shapes, in
both `projects.ts` and `project-sources.ts`. Star exports reject that
(TS2308), and no code outside the two files used either alias, so both
aliases are deleted and their one use each now names the underlying
type.
- The old barrel also re-exported `COMPLETED_EVENT_OUTPUT_RETENTION_MS`
and `RETAINED_EVENT_OUTPUT_TARGETS` from `src/retained-event-output.ts`
(not a data module). That re-export moved to `src/index.ts`.
- Query-cost cases for the six moved functions are now keyed
`packages/db/src/data/environment-lifecycle.ts#…`, because
`listQueryFunctions` keys functions by their declaring file. Relative
imports in `environments.test.ts`, `environment-lifecycle.test.ts`, and
`hosts-environments-cases.ts` point at the new file.
Export surface change (computed with the TypeScript checker over
`src/index.ts` and `src/internal-environment-lifecycle.ts`, before vs
after):
- Removed: none. Every existing `@bb/db` and
`@bb/db/internal-environment-lifecycle` import keeps working, so no
caller changed.
- Added to `@bb/db`: 230 types and 20 values that their modules already
exported but the list left out. Most of the types already appear in
public signatures, for example `CreateThreadInput` and
`ListThreadsOptions`. The values: `ACTIVE_PENDING_INTERACTION_STATUSES`,
`ACTIVE_THREAD_STATUSES`, `appendStoredThreadEventInTransaction`,
`bumpThreadEventRewriteGeneration`, `copyRetainedEventOutputs`,
`getContextWindowUsagePruningBoundarySequence`,
`listActiveVisiblePinnedThreadRoots`, `markHostSeen`,
`MAX_COMPLETED_EVENT_OUTPUT_MIGRATION_EVENT_DATA_BYTES`,
`NON_TERMINAL_SESSION_STATUSES`,
`prepareLegacyImageGenerationOutputData`, `PRUNABLE_THREAD_EVENT_TYPES`,
`pruneContextWindowUsageEventsInTransaction`,
`pruneTokenUsageEventsInTransaction`, `resolveStoredProviderSessions`,
`THREAD_PRUNING_ADVANCE_WORK_BUDGET_MS`,
`ThreadLifecycleEventNotAppliedError`, `toProjectSource`,
`upsertThreadSearchSegmentBatch`, `upsertThreadSearchSegments`. Each is
a sibling of names that were already public (for example, the plural
`appendStoredThreadEventsInTransaction` and `getStoredProviderSession`
were public), so hiding them was incidental, not a boundary.
Alternatives rejected:
- Delete the barrel and use a `@bb/db/data/*` subpath: this would
rewrite imports in 451 files, conflict with every open PR, and expose
the private helper modules.
- Generate the barrel: this would add a Turbo task and a gitignored
artifact to produce the same thing `export *` already gives.
- Keep named exports but split them per module: the central-list
conflicts would remain.
No wire, CLI, or plugin-API change.
## How you verified
- Export-surface diff before vs after with the TypeScript checker, over
`src/index.ts` and `src/internal-environment-lifecycle.ts`: 0 names
removed; the additions are listed above.
- Import cycles: a scan of value imports among
`packages/db/src/data/*.ts` finds none on main and none on this branch.
- Collision safety: temporarily re-adding a duplicate type name made
`tsrs --noEmit` fail with `TS2308: Module "./project-sources.js" has
already exported a member named ...`, so a future clash fails typecheck
instead of silently dropping a name.
- `pnpm exec turbo run typecheck --filter='...@bb/db'` passed (`@bb/db`,
`@bb/server`, `@bb/host-daemon`, `@bb/scripts`,
`@bb/integration-tests`).
- `vitest run` on `test/data/environments`, `environment-lifecycle`,
`projects`, `project-sources`, and `prompt-history`: 50/50 passed.
- Query-cost coverage (`listQueryFunctions` vs `QUERY_COST_CASES`): no
missing cases, no stale cases.
- `oxlint` on the changed files: clean. `lint:type-aware
--filter=@bb/db`: passed.
- CI runs the full suites.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
> AGENT GENERATED
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>1 parent f266dc1 commit 49982f7
10 files changed
Lines changed: 335 additions & 852 deletions
File tree
- packages/db
- scripts/query-costs
- src
- data
- test/data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | | - | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| 126 | + | |
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
| |||
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
183 | | - | |
| 186 | + | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
191 | | - | |
| 194 | + | |
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
| |||
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
201 | | - | |
| 204 | + | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
| |||
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
221 | | - | |
| 224 | + | |
222 | 225 | | |
223 | 226 | | |
224 | 227 | | |
| |||
249 | 252 | | |
250 | 253 | | |
251 | 254 | | |
252 | | - | |
| 255 | + | |
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| |||
298 | 301 | | |
299 | 302 | | |
300 | 303 | | |
301 | | - | |
| 304 | + | |
302 | 305 | | |
303 | 306 | | |
304 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
0 commit comments