Repository navigation
Commit f229dfd
feat(objectql, spec): a number or boolean comparand on a text- or option-family field compares as its stored string (#33518)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D4Jsmd91BqTVB7dSii9uJMV)_
Fixes #29486
Clause-②: yes (widening) — a filter that compares a text-family or
option-family field with a number or a boolean now matches the rows the
write door stored for that value (`String(value)`); before, it matched
none on every driver, with no error.
Metadata-protocol: semantic
Skills-docs: `content/docs/deployment/cli.mdx` (`os migrate
text-scalars`, `os migrate option-codes`) now says a filter on the
number reads as the string; no `skills/**` page teaches how a filter
reads a comparand on a text or option field.
## 维护者速读
-
**改了什么**:在文本类字段(text/email/phone/code…)和选项类字段(select/radio/multiselect…)上,用数字或布尔值做过滤条件时,引擎在交给驱动之前把它转成字符串(`42`
→ `"42"`,`true` → `"true"`),与写入时存储的形式一致。
- **为什么改**:写入侧早已把 `42` 存成 `"42"`,但过滤 `{ code: 42 }`
在所有驱动上都静默返回空列表、不报错;按维护者裁决 A 统一为字符串比较。
- **风险与回滚**:属于放宽(以前匹配不到的现在能匹配到);范围条件(`$gt`/`$between` 等)在这类字段上变为字符串比较(`{
code: { $gt: 9 } }` 不匹配 `"10"`),已在 changeset
中声明;唯一变窄的是未迁移的旧数据(driver-memory 持久化里的原始数字 `42` 以前能被 `{ code: 42 }`
匹配,现在不能,需跑 `os migrate text-scalars` / `option-codes`,#29643 跟踪)。回滚即回退本
PR。
-
**先看**:`packages/objectql/src/number-comparand-declared-type-door.ts`(walk
里新增的第三个 arm,风险 hunk 在 `walkCondition` 的 else 分支与
`declaredFactsOf`);`packages/spec/src/data/filter-string-stored-comparand-declared-type.ts`(判定函数与字段族);`packages/spec/src/data/filter-comparand-type-conformance.ts`(跨驱动用例表)。
- **两分钟验证**:`pnpm --filter @objectstack/rest exec vitest run
src/rest-data-option-scalar-value.test.ts`,预期全部通过,其中 `{ stage: 3 }`
返回写入为 `3` 和 `"3"` 的两行。
- **需要你做的**:无,席位落地。
## What changes
- **Contract (lane 1), `@objectstack/spec/data`** — new
`filter-string-stored-comparand-declared-type.ts`: the judged families
are the write side's three sets by identity
(`BOUNDED_STRING_FIELD_TYPES`, `SINGLE_OPTION_TYPES`,
`MULTI_OPTION_TYPES`), the positions are the number door's operator
lists by identity (`$eq $ne $gt $gte $lt $lte`, members of `$in $nin
$between`), and the pure verdict `stringStoredComparandDoorVerdict`
narrows a number or boolean to `String(value)` (a bigint within ±2^53 as
the number it names) and passes everything else. It never refuses.
`null` stays the null test.
- **Door (lane 2), `@objectstack/objectql`** — a third arm of the one
field-aware filter walk (`number-comparand-declared-type-door.ts`),
asked where neither the number nor the boolean arm judges (the classes
are disjoint). Every engine site that already runs the walk inherits it:
`where` on both spellings for find / findOne / count / aggregate /
update / delete, the per-aggregation `filter`, `having`, and
`judgeFilter`. No driver-local change.
- **Ranges are string ranges** — a `$gt` / `$gte` / `$lt` / `$lte` bound
and each `$between` member is narrowed like any comparand, so a range on
a text or option field compares strings in the column's order: `{ code:
{ $gt: 9 } }` does not match `"10"` (`"10"` < `"9"` as strings), and `{
code: { $between: [1, 10] } }` does not match `"5"`. Before,
InMemoryDriver and MongoDB matched no row for a number bound (they do
not order a number against a string), and SQLite compared by column
affinity: measured on a text column holding `"10"`, `"5"`, `"42"`,
`"alpha"`, `{ $gt: 9 }` matched `"alpha"`, `{ $between: [1, 10] }`
matched `"10"`, and `{ $gt: 4, $lt: 5 }` matched `"5"` and `"42"`, where
it now matches `"42"` alone. Declared in the changeset's "What answers
differently" and in the spec module header's measured table; pinned by
three range cases in the cross-driver table (single-digit bounds, which
every collation orders the same way).
- **Cross-driver table** — `FILTER_STRING_STORED_COMPARAND_CASES` in
`filter-comparand-type-conformance.ts`: each case carries the filter as
written and the filter the engine door hands every driver, plus the ids
it matches over `FILTER_STRING_STORED_COMPARAND_ROWS`. Classified in
`scripts/check-driver-conformance.mjs`'s `CASE_SETS`; every driver runs
it (memory, sql matrix, mongodb server-free, sqlite-wasm, turso local,
odata through the real engine).
- **Pin flip** —
`packages/rest/src/rest-data-option-scalar-value.test.ts`: `{ stage: 3
}` FROM no row TO both rows written `3` / `"3"`, plus `true`, mixed
`$in`, `$ne`, and the `POST …/query` door.
- **Docs** — `content/docs/deployment/cli.mdx`: the two migrate sections
say a filter on the number now reads as the string, so it also misses
unmigrated rows.
- **Changeset** — `@objectstack/spec` minor, `@objectstack/objectql`
patch.
## Tests
<details><summary>Premise, measured before any edit (base-equivalent
built tree, InMemoryDriver and SQLite through engine.insert /
engine.find)</summary>
Measured on a built tree at `8fd19455f`, whose `packages/objectql/src`,
`packages/spec/src/data`, `packages/drivers/driver-sql/src` and
`packages/drivers/driver-memory/src` differ from base `9499dcc53` only
in `recycle-bin/restore*`:
```
memory {"title":42} -> (none)
memory {"title":"42"} -> n,s
memory {"title":{"$in":[42,true]}} -> (none)
memory {"title":{"$ne":42}} -> b,n,s
memory {"stage":3} -> (none)
memory {"stage":{"$eq":true}} -> (none)
memory {"tags":3} -> ERR INVALID_FILTER 400
sqlite {"title":42} -> (none)
sqlite {"title":"42"} -> n,s
sqlite {"title":{"$in":[42,true]}} -> (none)
sqlite {"stage":3} -> (none)
sqlite {"tags":3} -> ERR INVALID_FILTER 400
```
</details>
<details><summary>Suites at the merged head (after `git merge
origin/main`)</summary>
- `pnpm --filter @objectstack/objectql test` — Test Files 595 passed
(595), Tests 13005 passed (13005)
- `pnpm --filter @objectstack/spec test` — Test Files 841 passed (841),
Tests 26877 passed, 1 todo
- driver-memory `memory-comparand-type-conformance.test.ts` 36 passed;
driver-sql `sql-driver-comparand-type-conformance.test.ts` 58 passed, 2
skipped (unprovisioned live cells); driver-mongodb
`mongodb-comparand-type-conformance.test.ts` 33 passed
- rest `rest-data-option-scalar-value.test.ts` +
`rest-data-text-scalar-value.test.ts` — 19 passed
- driver-sqlite-wasm 34 passed, driver-turso 34 passed, driver-odata
`odata-driver.conformance.test.ts` 718 passed
- typecheck: objectql, spec, driver-memory, driver-sql, driver-mongodb,
rest, driver-sqlite-wasm, driver-turso, driver-odata — all exit 0 (lock
VERDICT command-exit 0)
</details>
<details><summary>Round 2 (review#2 S1), head `63e03db212`: the range
cases, every touched suite</summary>
- spec `filter-string-stored-comparand-declared-type.test.ts` 12 passed;
objectql `engine-boolean-comparand-declared-type-door.test.ts` 43 passed
- driver-memory 39 passed; driver-sql 61 passed, 2 skipped
(unprovisioned live cells); driver-mongodb 36 passed; driver-sqlite-wasm
37 passed; driver-turso 37 passed; driver-odata 730 passed (each driver
+3 range cases; odata ×4 version/collation cells)
- lock VERDICT command-exit 0; `pnpm check:driver-conformance` exit 0
(`OK — 72 covered cell(s), 6 in the DEBT ledger, 0 exempt`); `node
scripts/check-changeset-no-major.mjs --base origin/main` exit 0 (no
`major`; the level axis reads the PR body in CI)
- The range "before" cells were measured at the driver on the as-written
filter (InMemoryDriver, SqlDriver over better-sqlite3), which is what
each received before the arm: no earlier engine door touches a comparand
on a text field.
</details>
<details><summary>Ablation (one-time, not kept)</summary>
`node scripts/ablation-replace.mjs` replaced the arm's `judged =
judgeFieldSpec(stringStoredArm(stringMeta), key, value, here);` with
`continue;` (anchor 1 → 0, blob `acdfa13031d8` → `e4c81394a2b4`).
`engine-boolean-comparand-declared-type-door.test.ts`: Tests 7 failed |
36 passed (43). Restored: blob == HEAD (`acdfa13031d8`), `git diff HEAD`
empty. The test imports the engine from `src/`, so no `dist/` leg
applies.
</details>
## Acceptance notes
- **Multi-value option fields** (`multiselect`, `checkboxes`, `tags`, a
`multiple: true` select): the arm narrows a scalar comparand there too,
as the write side reads each element, but both measured drivers refuse
any scalar comparison against such a field (`INVALID_FILTER`, "use
`$contains`") before and after, so nothing observable moves. Kept as the
drivers answer it; no new semantics.
- **A number code on an option field** is reachable only where the field
declares no `options` (an object registered in code, as the write door's
own pins do) or from a row written before the rule: a declared code is a
system identifier, so `"3"` is never one and the write door refuses `3`
on a select that declares its codes. `"true"` / `"false"` are legal
codes anywhere. The table's select fixture declares none for that
reason; its spec test pins that `FieldSchema` refuses it.
- **Legacy rows** (raw `42` on driver-memory with persistence, `"42.0"`
on SQLite) are not migrated here, per the ruling (#29643). A raw `42`
matched `{ code: 42 }` before and no longer does.
- **`Metadata-protocol: semantic`, not the claim's `none`**: the ruling
sets spec at minor, and `check-changeset-no-major.mjs`'s level axis
grades a declared `none` patch-only; a filter a view or flow already
stores changes meaning, which is the `semantic` row.
- Not measured locally (exit 3, prerequisite: a whole-workspace build):
`check:skill-examples`, `check:dual-build-cjs-loads`,
`check:type-check-debt`. CI runs them.
## Verification
- Round 1 head: `b67f2b81f6`. Local derived gate families (`node
scripts/pm/dispatch-gates.mjs --commands`): 106 exit 0;
`check:driver-conformance` red on its first run (the new case set
unclassified), then fixed in this PR and re-run: `OK — 72 covered
cell(s), 6 in the DEBT ledger, 0 exempt`. The families derived from the
gate-script edit are run separately (see the report comment).
- No open PR touches the same files (62 open PRs' file lists checked).
- Round 2 head: `63e03db212` — the touched suites,
`check:driver-conformance`, `check:changeset-no-major`,
`check:spec-docblock-symbol-anchors`, `check:nul-bytes`,
`check:issue-citations` and `check:doc-authoring`, all exit 0.
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC
<!-- signed: domain:server#5 · os-elon-musk ·
session_016WV4cw787kMeaX7oyz7DDC -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8f9eb3d commit f229dfd
18 files changed
Lines changed: 1035 additions & 24 deletions
File tree
- .changeset
- content/docs/deployment
- packages
- drivers
- driver-memory/src
- driver-mongodb/src
- driver-odata/src
- driver-sqlite-wasm/src
- driver-sql/src
- driver-turso/src
- objectql/src
- rest/src
- spec
- api-surface
- export-origins
- src/data
- 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 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1732 | 1732 | | |
1733 | 1733 | | |
1734 | 1734 | | |
1735 | | - | |
1736 | | - | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
1737 | 1738 | | |
1738 | 1739 | | |
1739 | 1740 | | |
| |||
1758 | 1759 | | |
1759 | 1760 | | |
1760 | 1761 | | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
1764 | 1766 | | |
1765 | 1767 | | |
1766 | 1768 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
101 | 104 | | |
102 | 105 | | |
103 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| |||
106 | 109 | | |
107 | 110 | | |
108 | 111 | | |
109 | | - | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| |||
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
204 | 206 | | |
205 | 207 | | |
206 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
207 | 228 | | |
208 | 229 | | |
209 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
109 | 111 | | |
110 | 112 | | |
111 | 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 | + | |
112 | 163 | | |
113 | 164 | | |
114 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
84 | 86 | | |
85 | 87 | | |
86 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
88 | 90 | | |
89 | 91 | | |
90 | 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 | + | |
0 commit comments