Repository navigation
Commit 7193160
fix(objectql): a data driver receives the declared driver options and nothing else (#30151)
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么:** 引擎交给数据驱动的选项,现在只含 `DriverOptionsSchema` 声明的键(从 schema
读出,去掉退役墓碑 `timeout`)。`buildDriverOptions`
返回的就是这组键;find、findOne、count、aggregate、insert、update、delete(按 id 与多行)以及原始
`execute` 都把它交给驱动。hook 读到的 `input.options` 不变,仍是调用方的选项袋加上驱动选项(加法视图)。
- **为什么改:** 维护者裁决(选项 A):引擎交给驱动的只有声明的驱动选项,别无其他。沿用 #4400
把引擎选项袋做成封闭契约的做法,往下推一跳到驱动。
- **风险与回滚:**
声明键(`transaction`、`tenantId`、`tenantIds`、`timezone`、`preserveAudit`、`bypassTenantAudit`)原样到达,有对照测试;仓内驱动都只读声明键。若有第三方驱动读未声明的键,它将读不到(仓内没有)。`@objectstack/objectql`
patch,spec 只改两处注释。回滚 = revert 本 PR。
- **先看:** ① `packages/objectql/src/engine-driver-options.ts` 的
`pickDeclaredDriverOptions`、`mergeDriverOptionsIntoHookView` 和
`buildDriverOptions` 早返回那几行;② `engine.ts` 里 find / findOne / insert /
update / delete 把 `driverOptions` 交给驱动、把合并视图留给 hook 的位置。
- **两分钟验证:** `pnpm --filter @objectstack/objectql exec vitest run
--project local src/engine-driver-options.test.ts`,预期 `8 passed`;把
`buildDriverOptions` 里的 `pickDeclaredDriverOptions(base)` 换回 `{ ...base
}` 再跑,第二个用例转红。
- **需要你做的:** 无,席位落地。
## What changes
The engine → driver hop is now a closed contract, one hop below the
engine option bags #4400 closed: a data driver receives the keys
`DriverOptionsSchema` declares and nothing else.
- `packages/objectql/src/engine-driver-options.ts`
- `declaredDriverOptionKeys()` reads the key set off
`DriverOptionsSchema.shape` on first use, minus any member that admits
only absence (a `retiredKey()` tombstone, today `timeout`). It is never
restated, so a key the spec declares reaches drivers with no edit here.
- `pickDeclaredDriverOptions(bag)` cuts a bag to that set (own
enumerable keys, values untouched).
- `buildDriverOptions` starts from the declared keys of `base` instead
of a copy of the whole bag, so every bag it returns is declared-only. A
caller's explicit `tenantId` / `transaction` / `bypassTenantAudit` still
wins, exactly as before.
- `mergeDriverOptionsIntoHookView(callerBag, driverOptions)` builds the
`after*` view of `input.options`: the caller's bag with the driver
options merged on, additive as the hook PHASE contract states; the
caller's own object when nothing is added; and a copy of the driver
options when there is no caller bag, so the hooks' view and the driver's
bag are never one object.
- `packages/objectql/src/engine.ts`: `find`, `findOne`, `insert`,
`update` and `delete` keep the built options in a local `driverOptions`,
hand THAT to every driver call (including the reads and writes the verb
makes along the way), and assign the merged view to `input.options` for
hooks.
- `packages/objectql/src/engine-execute-transactions.ts`: the raw
`execute` door hands its driver the declared keys of its bag.
- `packages/objectql/src/engine-top-level.ts`: comment-only. The
pass-through keys docblock now says the bag's declared keys are the base
of the driver options.
- `packages/spec/src/data/hook.zod.ts`,
`packages/spec/src/data/driver.zod.ts`: comment-only. The hook PHASE
paragraph said the `after*` handler and the driver read one view; it now
says the merged view is the hooks' and a driver is handed the declared
keys, and it names both `buildDriverOptions` (which produces the
driver's set) and `mergeDriverOptionsIntoHookView` (which merges that
set into the hook view). `DriverOptionsSchema`'s doc states the hop
rule.
- `.changeset/driver-options-declared-keys-only.md`:
`@objectstack/objectql` patch.
## Tests
`packages/objectql/src/engine-driver-options.test.ts` (new, 8 cases), on
a recording driver double that captures the options argument as the
driver receives it:
- `a data driver receives the declared driver options and nothing else`
- the hop key set is `DriverOptionsSchema`'s declared keys, and every
shape key it leaves out refuses every probe value (a tombstone);
- `find`, `findOne`, `insert`, `update` and `delete` (by id and
multi-row; `count`, `updateMany`, `deleteMany` asserted reached too)
hand the driver only declared option keys;
- the raw `execute` door hands the driver only declared option keys.
- `control: the declared keys the engine threads still reach the
driver`: `transaction`, `tenantId` and `timezone` arrive on every verb;
`preserveAudit` and a caller's explicit `bypassTenantAudit` arrive
unchanged.
- `the after* hook view of input.options stays additive`: an `afterFind`
hook still reads the caller's own keys beside the driver options; an
`afterUpdate` hook still reads a key the caller passed; the merge helper
answers the caller's own bag when it adds nothing, and a copy, never the
driver's bag itself, when there is no caller bag.
`packages/objectql/src/engine.test.ts`: four expansion sub-read cases
hold the driver's received option keys to a subset of
`declaredDriverOptionKeys()`; the file-reference case reads the
expansion marker at the middleware seam.
## Acceptance notes
- **Why `Clause-②: no`, no arm, `Metadata-protocol: none`, `patch`.** No
accept set moves: every engine door accepts the option bags it accepted,
and `DriverOptionsSchema` is unchanged apart from its doc comment. The
keys that stop reaching a driver were never declared on the driver
contract (the `DriverOptions` type carries none of them, so a typed
driver could not read one without a cast), and no driver in this
repository reads one. What a metadata author can write does not change.
- **Why the cut is not inside the hook view.** `buildDriverOptions`'s
result used to be both the driver's options and the `after*` hook view
of `input.options`. Hooks in this repository read caller keys from that
view after the merge (an `afterInsert` / `afterUpdate` handler reads one
there), and the hook PHASE contract states the merge is additive. So the
declared set is what the driver is handed, and hooks keep the additive
view; the third test block pins that.
- **Undeclared keys are dropped without a sound**, as ruled: the
caller's bag was already judged at the engine's own door (#4400), so
nothing dropped at the hop is a caller's mistake. A dev-mode warning was
considered and not added; the contract review decided against one.
- **Bulk `after*` per-row dispatches** read the same merged view as
before.
- **Which doors admit the schema's other declared keys.** `insert` and
the raw `execute` door hand them on when a caller sets them; `find`,
`findOne`, `update` and `delete` admit only the six threaded keys at
their own door (`ENGINE_DRIVER_PASSTHROUGH_KEYS`), unchanged by this PR.
- **Contract review.** PASS with no must-fix; the should-fix items are
done at 6aaa035 (see Verification).
## Verification
Head: 6aaa035 (the contract-review should-fix round). Every reading
below is against that tree.
<details><summary>Tests, typecheck, full suite, and the one-shot
ablation of the no-bag copy</summary>
```
head 6aaa035, one verify-lock hold (VERDICT command-exit 0)
$ pnpm exec turbo run build --filter='@objectstack/objectql...' --concurrency=2 BUILD_EXIT=0
$ pnpm --filter @objectstack/objectql exec vitest run --project local --maxWorkers=2 \
src/engine-driver-options.test.ts src/engine.test.ts src/hook-input-shape-contract.test.ts
Test Files 3 passed (3)
Tests 160 passed (160)
$ pnpm --filter @objectstack/objectql typecheck TYPECHECK_EXIT=0
check:test-typecheck: OK — 39 file(s) / 233 error(s) / 64 pinned signature(s) held
$ pnpm --filter @objectstack/objectql test TEST_EXIT=0
Test Files 548 passed (548)
Tests 10844 passed (10844)
One-shot ablation of the new behaviour (scripts/ablation-replace.mjs, wrap mode):
anchor "if (callerBag === null || typeof callerBag !== 'object') return { ...driverOptions };" x1 -> x0
replace "if (callerBag === null || typeof callerBag !== 'object') return driverOptions;" x0 -> x1
blob 08ffacb -> 6a9047dba9d2 (packages/objectql/src/engine-driver-options.ts)
× merging adds the driver options, answers the caller's own bag when nothing is added, and never answers the driver's bag itself
Test Files 1 failed (1)
Tests 1 failed | 7 passed (8)
restored: blob == HEAD (08ffacb) and `git diff HEAD` is empty
Direction: red, as predicted, on the merge case only.
The declared-keys rule itself was ablated once at 7319d7c (replacing the pick
with a spread of the whole bag reddens the rule case only, 1 failed | 7 passed),
and that line is unchanged since.
```
</details>
<details><summary>Derived gate families</summary>
```
head 6aaa035
$ node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack
84 command(s) derived (9 paths vs merge base 1f13eb3; check:stack-collection-maps is new, for engine-top-level.ts)
every one run, exit code captured before any pipe:
82 x exit 0
2 x exit 3 (PREREQUISITE NOT MET => NOT MEASURED locally; CI runs both)
- pnpm check:dual-build-cjs-loads (needs every workspace package's dist/)
- pnpm check:type-check-debt (its own closure build never got the verify lock)
$ node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran RAN_FILE
Run reconciliation — 84 derived, 82 run, 2 NOT-MEASURED, 0 UNRUN.
Repo-wide scans (pnpm lint and the full farm) are CI's.
```
</details>
<!-- signed: security#1 · os-justin · session_01QSeKYn5CmmdShCJifm6WYj
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent eca7cd2 commit 7193160
9 files changed
Lines changed: 471 additions & 40 deletions
File tree
- .changeset
- packages
- objectql/src
- spec/src/data
| 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 | + | |
| 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 | + | |
0 commit comments