Repository navigation
Commit e72f2aa
feat(spec,objectql,service-analytics): IObjectQLEngine.fixedReadLeafClassOf, wired into the analytics native path (ADR-0155 D4) (#35954)
Fixes #35946
Clause-②: yes
Metadata-protocol: none
Stacked on #35945 (ADR-0155 step 5). This pull request's base is
`claude/project-thread-thptm0`, at `74cac04849` since the round-1
rebase, so its diff is only this card's change. GitHub retargets it to
`main` when #35945 merges. Round 1 (head `e117d86d44`) answers the L2
record 7053241461: S1, N1 and N2.
## 维护者速读
- 用户能看到什么变化:用户无感。分析服务在走原生 SQL
之前,先问数据引擎这条共享过滤条件能不能直接编译。引擎说可以,就走原生路径;否则交给引擎路径。
- 为什么做:属于“共享记录权限下沉到引擎”这条工作线(ADR-0155 第 5 步的收尾)。按你选的方案
A,在引擎接口上加一个可选方法,供分析服务提问。
-
出错会怎样:只影响带共享过滤条件的分析查询走哪条路径。引擎没回答、回答不合约定或出错时,一律交给引擎路径,结果始终正确,最多是变慢;可以直接撤回。
- 要你做什么:无。
## What changes
- **Contract** (`packages/spec/src/contracts/objectql-engine.ts`). A new
OPTIONAL member `IObjectQLEngine.fixedReadLeafClassOf(leaf)`, typed
`(leaf: FixedReadLeaf) => EngineFixedReadLeafClass | null`. It is the
engine seam's ADR-0155 D4 class recognition for a `SharedRecordIds`
leaf. It answers `'other-datasource'` or `'registration-by-name'` with
what names it, and **`null` when neither class applies**. It throws
`TypeError` on a value that is not a fixed-read leaf
(`fixedInnerReadOf`), and its one consumer reads a throw as a decline.
Because "neither" is `null` and never `undefined`,
`engine.fixedReadLeafClassOf?.(leaf)` carries the consumer's whole
three-state answer: a class means decline, `null` means compile, and
`undefined` from an engine without the member means it cannot say, so
decline. The answer type `EngineFixedReadLeafClass` restates objectql's
`FixedReadLeafClass`. Its docblock says `ObjectQL implements
IObjectQLEngine` checks one direction only: the seam's answer must be
assignable to the contract's type. The header's list of members optional
by ruling now names it (ruling 7051956587).
- **Engine** (`packages/objectql/src/engine.ts`).
`ObjectQL.fixedReadLeafClassOf(leaf)` is a one-line forward to
`fixedReadLeafClassAnswerOf(this, leaf)`. `IObjectQLEngine` is imported
from `@objectstack/spec/contracts` instead of through
`@objectstack/core`'s re-export, and that import line also names
`EngineFixedReadLeafClass`. The reason was measured. objectql is
CommonJS and core is ESM. Through core, the contract's branded
`FixedReadLeaf` resolved to spec's `.d.mts` chunk, while engine.ts's own
import resolved to the `.d.ts` chunk. The tsup DTS build then failed the
`implements` check with TS2416.
- **New file `packages/objectql/src/fixed-read-leaf-engine-answer.ts`**.
`fixedReadLeafClassAnswerOf(engine, leaf)` returns
`fixedReadLeafClassOfEngine(engine, leaf) ?? null`. It is the seam's own
recognition, with "neither" spelled `null`. It lives outside engine.ts
because the facade gate allows only a one-line forwarding call there,
and `?? null` is an operator. `fixed-read-leaf-seam.ts`, which is
#35945's file, is untouched.
- **Analytics plugin**
(`packages/services/service-analytics/src/plugin.ts`). It wires
`AnalyticsServiceConfig.fixedReadLeafClassOf`, which #35945 left
unwired. It resolves the engine from the `"data"` service on each call,
as it does for `hasObjectMiddleware`, and returns
`svc.fixedReadLeafClassOf?.(leaf)` as the engine gave it. This plain
optional call is **fail-closed by construction**. When there is no
engine or `getService` throws, the hook answers `undefined`. An engine
without the member also answers `undefined`, and the plugin says so once
at `warn`. `NativeSQLStrategy` declines every answer except `null`, so
it also declines a class, a throw, and a member that does not keep the
contract (one that answers `undefined` for neither). `DataEngineLike`'s
`Pick` now includes the member. Neither D4 class is restated in
analytics.
- **Facade ceiling** (`scripts/facade-delegation-registry.json`, the
engine.ts row). Before: `baseLines 6754 @ 63db724, maxLines 6854,
ruling 6897467376`. After: `baseLines 6853 @ 170ca48 (origin/main,
measured), maxLines 6857, ruling 7051956587`. engine.ts goes from 6853
to 6856 lines, and round 1 added no line to it. The raise is **3**,
inside the ruled 3–5. #35773 has since merged to `main` (+1 net). A
merge-tree of this head with `origin/main` 7de1bad gives engine.ts
6857 lines, which is at the ceiling with 0 left. The row needs no change
for that merge.
- **Generated files**: `packages/spec/api-surface/contracts.json` and
`packages/spec/export-origins/contracts.json` (the new type export).
- **Changeset**: `.changeset/35946-fixed-read-leaf-engine-member.md`,
`patch` for `@objectstack/spec`, `@objectstack/objectql` and
`@objectstack/service-analytics`. It states the round-1 semantics.
## Why
Maintainer ruling A on #35946 (comment 7051956587) has analytics ask the
engine seam's D4 recognition through an optional `IObjectQLEngine`
member, with no new package dependency on objectql. ADR-0155 D4 says the
recognition lives once, in the seam, and that the analytics native
compiler "restates none". Without the wiring, once step 6 (#33787)
starts writing the leaf, every sharing-scoped analytics query would
leave native SQL. Round 1 (S1) makes "neither" `null`, so that an absent
member and an answered "neither" can no longer be confused.
## Tests
The pin is a `describe` named `[#35946] AnalyticsServicePlugin asks the
data engine's fixedReadLeafClassOf`. It sits in the leaf's existing
live-SQLite harness `fixed-read-leaf-native-compile.test.ts`, because a
new pin for a component with a shared harness goes into that file. The
`"data"` engine is a plain object over the live engine's members, so the
pin tests the plugin's structural wiring and the engine's own answers.
- **(a)** Member present, object in neither class.
`engine.fixedReadLeafClassOf(leaf)` is `null`. The raw-SQL seam runs
once, the statement carries `IN (SELECT "record_id" FROM
"sys_record_share"`, and the rows equal the case set's expected rows.
- **(b)** Member present, object in a D4 class (a `beforeFind` hook
registered for `sys_record_share`). The engine answers `{ class:
'registration-by-name', table: 'sys_record_share' }`. The raw-SQL seam
is never called, and the engine's seam refuses with `INTERNAL_ERROR` /
500.
- **(c)** Member absent. The raw-SQL seam is never called, the engine
path answers the expected rows, and the plugin warns once.
- **(d)** A member that answers `undefined` instead of the contract's
`null`. The raw-SQL seam is never called, the engine path answers the
expected rows, and nothing warns.
Ablations, round 1, at `99ebe34bbd`, all through
`scripts/ablation-replace.mjs`. The service-analytics vitest config
aliases `@objectstack/objectql` to its source, so no `dist/` sits in the
path. Every restore was verified as blob == HEAD with `git diff HEAD`
empty. The rebase onto `74cac04849` touched none of the mutated files,
and the pins were re-run green after it.
```text
A1 wiring removed (the plugin config's fixedReadLeafClassOf line commented out) blob cfbe857 -> af53e0d322c9
x (a) AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times
x (c) AssertionError: expected [] to have a length of 1 but got +0
Tests 2 failed | 2 passed | 31 skipped (35)
A2 fail-open mutant: return svc.fixedReadLeafClassOf?.(leaf); -> return svc.fixedReadLeafClassOf?.(leaf) ?? null;
blob cfbe857 -> 58076b1ce810
x (c) AssertionError: expected "vi.fn()" to not be called at all, but actually been called 2 times (line 384)
x (d) AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times (line 393)
Tests 2 failed | 2 passed | 31 skipped (35)
A3 the engine's null mapping removed (fixed-read-leaf-engine-answer.ts: "?? null" dropped) blob f10e025 -> b6a1d16c5757
x (a) AssertionError: expected undefined to be null
Tests 1 failed | 3 passed | 31 skipped (35)
```
A2 is the ruling's original spelling. On the shipped plain `?.()`, pins
(c) and (d) prove the wiring fails closed. Round 0's fail-open record
(comment 7052875195) used the same mutant against the round-0 code.
Package runs, all under `scripts/pm/os-verify-lock.sh`:
- The pin file passed 35 of 35 at `99ebe34bbd`, and again at
`e117d86d44` after rebuilding the dependency closure.
- typecheck for `@objectstack/spec`, `@objectstack/objectql` and
`@objectstack/service-analytics` exits 0 at `99ebe34bbd`;
service-analytics exits 0 again at `e117d86d44`.
- eslint `--no-inline-config` on the five edited source files exits 0 at
`e117d86d44`.
- The full suites last ran at round 0's `e5dff0f186`: service-analytics
had 221 of 221 test files pass (5646 tests passed, 345 skipped);
objectql had 625 of 625 files and 14183 of 14183 tests pass. They were
not re-run in round 1, and CI runs them.
## Acceptance notes
- **Resolved by S1: the earlier deviation from the ruling's spelling.**
Round 0 kept "neither" as `undefined` and had the plugin probe with
`typeof` before applying `?? null`. With "neither" now `null`, the plain
`engine.fixedReadLeafClassOf?.(leaf)` is the hook's whole answer, and it
fails closed with no probe. The ruling's original `?? null` survives
only as ablation A2, which shows it would fail open.
- **Closed: #35945's changeset sentence.**
`.changeset/35874-fixed-read-leaf-census-rest.md` had said
`AnalyticsServicePlugin` wires no answer in this release. #35945
reworded that clause at `74cac04849` ("the analytics hook ships unwired
until its wiring lands, whichever release that is"). That wording holds
whichever release this pull request lands in.
- **Stacked form.** AGENTS.md multi-agent §2 marks a stacked series as
unsupported. This pull request is stacked because the dispatch claim
(comment 7052034983) orders it.
- **Two declarations.** objectql's `FixedReadLeafClass` and spec's
`EngineFixedReadLeafClass` are separate declarations, checked in one
direction by `implements` (N1). Aliasing the objectql type to the spec
one would remove the second declaration. That edit is in
`fixed-read-leaf-seam.ts`, which is #35945's file.
- **Docs page.** `content/docs/kernel/contracts/data-engine.mdx` does
not list `IObjectQLEngine`'s members one by one; its only reference is
`IObjectQLEngine.transaction(cb)`. So no member line was added there.
## Verification
Files to read first, by risk:
1. `packages/services/service-analytics/src/plugin.ts`: the
`fixedReadLeafClassOf` bridge, a plain optional call that must stay
fail-closed.
2. `packages/objectql/src/fixed-read-leaf-engine-answer.ts` together
with the member in `packages/spec/src/contracts/objectql-engine.ts`: the
`null` for "neither".
3. `scripts/facade-delegation-registry.json`: the engine.ts ceiling row.
Two-minute check: run `pnpm --filter @objectstack/service-analytics exec
vitest run --maxWorkers=2
src/__tests__/fixed-read-leaf-native-compile.test.ts -t 35946` and
expect 4 passed.
Local gates at `99ebe34bbd`, each exiting 0:
- facade and repo checks: `check:facade-delegation-only` (engine.ts 6856
of 6857), `check:engine-double-contract`, `check:nul-bytes`,
`check:doc-authoring`, `check:test-source-alias`,
`check:cross-package-test-inputs`, `check:adr-anchors`,
`check:issue-citations`, `check:closed-ceremony-text`;
- runtime checks: `check:startup-registry-verdict`,
`check:durability-log-level`, `check:optional-error-sink`,
`check:logger-receiver-detach`, `check:undeclared-dep-imports`,
`check:spec-docblock-symbol-anchors`, `check:scripts-symbol-anchors`,
`check:slot-lookup`, `check:init-service-contract`;
- changeset checks: `check-empty-changeset`, `check-changeset-no-major`,
`check-adr-0087-registration`, `check:changeset-gate-self-tests`;
- spec checks: `check:api-surface`, `check:export-origins`,
`check:dual-source-exports`, `check:exported-any`,
`check:entry-nameability`, and `check:generated` ("All 14 generated
artifacts are up to date");
- build and docs checks: `check:dts-closure`, `check:published-files`,
and the docs-audit `check-drift-comment` and `check-affected-docs`.
Re-run at `e117d86d44`, each exiting 0: `check:facade-delegation-only`,
`check:nul-bytes`, spec `check:api-surface` and `check:export-origins`,
`check:test-source-alias`, `check:engine-double-contract` and
`check-empty-changeset`.
overlap-check reports VERDICT clean (exit 0) against `74cac04849` and
against `origin/main` 7de1bad. The local runs are a declared
narrowing: `dispatch-gates --commands` derives 115 families against
`origin/main`, including #35945's files, and CI runs the full set.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [ ] 4. One issue, one branch off an up-to-date `main`, one pull
request. (Stacked on #35945 by the dispatch claim; see Acceptance
notes.)
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_
<!-- signed: repo:objectstack#7 · os-tesla ·
session_01L9qibwJEh7hMPPvagWM1g7 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9ed18a5 commit e72f2aa
9 files changed
Lines changed: 252 additions & 14 deletions
File tree
- .changeset
- packages
- objectql/src
- services/service-analytics/src
- __tests__
- spec
- api-surface
- export-origins
- src/contracts
- scripts
| 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 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
1916 | 1916 | | |
1917 | 1917 | | |
1918 | 1918 | | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
1919 | 1922 | | |
1920 | 1923 | | |
1921 | 1924 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
297 | 298 | | |
298 | 299 | | |
299 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
300 | 398 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | | - | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
1531 | 1532 | | |
1532 | 1533 | | |
1533 | 1534 | | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
1534 | 1573 | | |
1535 | 1574 | | |
1536 | 1575 | | |
| |||
1657 | 1696 | | |
1658 | 1697 | | |
1659 | 1698 | | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
1660 | 1702 | | |
1661 | 1703 | | |
1662 | 1704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
0 commit comments