Skip to content

Commit f229dfd

Browse files
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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/objectql': patch
4+
---
5+
6+
feat(objectql, spec): a number or boolean comparand on a text- or option-family field compares as its string, the form the write door stores (#29486)
7+
8+
Clause-②: yes (widening) — a filter that compares a text-family field (`text`, `textarea`, `email`, `url`, `phone`, `password`, `markdown`, `html`, `richtext`, `code`, `signature`, `qrcode`) or an option-family field (`select`, `radio`, `multiselect`, `checkboxes`, `tags`) with a number or a boolean now matches the rows the write door stored for that value; before, it matched none on every driver, with no error.
9+
Metadata-protocol: semantic
10+
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.
11+
12+
Maintainer ruling A on #29486: a number or boolean comparand on a text- or option-family field compares as `String(value)`, the form the write side stores since #29241 (text) and #29562 (options).
13+
14+
**What answers differently.**
15+
16+
- `{ code: 42 }`, `{ code: { $in: [42, true] } }` and `{ stage: 3 }` against a `text` / `select` field written `42` / `3`: FROM no row (InMemoryDriver and SQLite measured) TO the rows written `42` or `"42"` (`3` or `"3"`). `$ne` / `$nin` FROM every row TO every row but those. `true` / `false` read as `"true"` / `"false"`, and a `bigint` within ±2^53 as the number it names.
17+
- A range is now a STRING range. `$gt` / `$gte` / `$lt` / `$lte` bounds and `$between` members are 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"` (`"5"` > `"10"`). Before, InMemoryDriver and MongoDB matched no row for a number bound (they do not order a number against a string), and SQLite compared by the column's affinity: measured, `{ $gt: 9 }` matched `"alpha"` and `{ $gt: 4, $lt: 5 }` matched `"5"` and `"42"`, where it now matches `"42"` alone. To range over numbers, declare the field as a number.
18+
- Every engine verb that collects a filter (`find`, `findOne`, `count`, `aggregate`, `update`, `delete`), both spellings of `where` (the object form and the `FilterArray` sugar), the per-aggregation `filter` and `having`, and every REST door that reaches them. The comparand is narrowed at the engine's field-aware filter seam, beside the number and boolean doors, so every driver receives the string.
19+
- Unchanged: a string comparand, `null` (the null test, never `"null"`), a `Date`, the text operators (`$contains: 42` is still refused), and every other field type. A scalar comparison on a multi-value option field is still refused by the drivers ("use `$contains`"); only the comparand they are handed changes.
20+
- Rows written before #29241 / #29562 and not yet migrated: a raw `42` on driver-memory with persistence matched `{ code: 42 }` and no longer does, as `{ code: "42" }` never did. Run `os migrate text-scalars --apply` and `os migrate option-codes --apply` (tracked in #29643).
21+
22+
**In-process APIs.** `@objectstack/spec/data` exports `stringStoredComparandDoorVerdict`, `stringStoredComparandFieldVerdict`, `STRING_STORED_COMPARAND_DOOR_FAMILIES`, `STRING_STORED_COMPARAND_DOOR_SCALAR_OPERATORS`, `STRING_STORED_COMPARAND_DOOR_LIST_OPERATORS`, the type `StringStoredComparandDoorFieldMeta` / `StringStoredComparandDoorVerdict`, and the cross-driver conformance table `FILTER_STRING_STORED_COMPARAND_CASES` with its fixture (`FILTER_STRING_STORED_COMPARAND_FIELDS`, `FILTER_STRING_STORED_COMPARAND_ROWS`, `StringStoredComparandRow`, `StringStoredComparandCase`). All additive.

‎content/docs/deployment/cli.mdx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,8 +1732,9 @@ by: `3` as `"3"`, `true` as `"true"`. Rows written before that rule keep the
17321732
form the database stored: the raw number or boolean on driver-memory with
17331733
persistence, the text `"3.0"`, `"1.0"` or `"0.0"` on SQLite, and raw elements
17341734
inside a multi-value array on every driver. A filter on `"3"` does not find
1735-
those rows, a read hands back the old form, and a unique field admits a new
1736-
`"3"` beside an old `"3.0"`.
1735+
those rows, nor does a filter on `3`, which a filter reads as `"3"` (a number or
1736+
boolean compared with an option field compares as its string); a read hands
1737+
back the old form, and a unique field admits a new `"3"` beside an old `"3.0"`.
17371738
17381739
```bash
17391740
os migrate option-codes # Dry run: counts per object and field, writes no rows
@@ -1758,9 +1759,10 @@ A number or a boolean written to a text field (`text`, `textarea`, `email`,
17581759
`signature`, `qrcode`) is stored as its string: `42` as `"42"`, `true` as
17591760
`"true"`. Rows written before that rule keep the form the database stored: the
17601761
raw number or boolean on driver-memory with persistence, the text `"42.0"`,
1761-
`"1.0"` or `"0.0"` on SQLite. A filter on `"42"` does not find those rows, a
1762-
read hands back the old form, and a unique field admits a new `"42"` beside an
1763-
old `42` or `"42.0"`.
1762+
`"1.0"` or `"0.0"` on SQLite. A filter on `"42"` does not find those rows, nor
1763+
does a filter on `42`, which a filter reads as `"42"` (a number or boolean
1764+
compared with a text field compares as its string); a read hands back the old
1765+
form, and a unique field admits a new `"42"` beside an old `42` or `"42.0"`.
17641766
17651767
```bash
17661768
os migrate text-scalars # Dry run: counts per object and field, writes no rows

‎packages/drivers/driver-memory/src/memory-comparand-type-conformance.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { describe, it, expect, beforeAll } from 'vitest';
2424
import {
2525
FILTER_COMPARAND_TYPE_CASES,
2626
FILTER_COMPARAND_TYPE_ROWS,
27+
FILTER_STRING_STORED_COMPARAND_CASES,
28+
FILTER_STRING_STORED_COMPARAND_FIELDS,
29+
FILTER_STRING_STORED_COMPARAND_ROWS,
2730
parseFilterAST,
2831
type FilterCondition,
2932
} from '@objectstack/spec/data';
@@ -101,3 +104,45 @@ describe('[#7872] InMemoryDriver.find — comparand-type conformance (behind the
101104
).rejects.toThrow(/BigInt/);
102105
});
103106
});
107+
108+
/**
109+
* [#29486] `FILTER_STRING_STORED_COMPARAND_CASES`, the driver's half: a number
110+
* or boolean comparand on a text- or option-family field reaches mingo already
111+
* narrowed to the string the write door stored (the engine's declared-type
112+
* door, pinned in `@objectstack/objectql`), so each case's `stored()` filter
113+
* must select exactly its rows here — and the as-written filter, handed to the
114+
* driver directly, still selects none of them: mingo compares `42` with `"42"`
115+
* strictly, which is the cell the door stands in front of.
116+
*/
117+
describe('[#29486] InMemoryDriver.find — a number or boolean comparand on a string-stored field, as the door hands it', () => {
118+
const STRING_TABLE = 'string_stored_conformance';
119+
let driver: InMemoryDriver;
120+
121+
beforeAll(async () => {
122+
driver = new InMemoryDriver({ persistence: false });
123+
await driver.connect();
124+
await driver.syncSchema(STRING_TABLE, { fields: FILTER_STRING_STORED_COMPARAND_FIELDS as never });
125+
for (const row of FILTER_STRING_STORED_COMPARAND_ROWS) await driver.create(STRING_TABLE, { ...row });
126+
});
127+
128+
const ids = async (where: FilterCondition | undefined): Promise<string[]> => {
129+
const rows = await driver.find(STRING_TABLE, { fields: ['id'], where });
130+
return (rows as Array<Record<string, unknown>>)
131+
.map((r) => String(r.id))
132+
.sort((x, y) => x.localeCompare(y));
133+
};
134+
135+
it('the fixture really is every row', async () => {
136+
expect(await ids(undefined)).toEqual(FILTER_STRING_STORED_COMPARAND_ROWS.map((r) => r.id));
137+
});
138+
139+
for (const c of FILTER_STRING_STORED_COMPARAND_CASES) {
140+
it(c.name, async () => {
141+
expect(await ids(parseFilterAST(c.stored())), c.note).toEqual([...c.expected]);
142+
});
143+
}
144+
145+
it('the strict cell still exists on the direct path — { code: 42 } handed to mingo matches no row', async () => {
146+
expect(await ids(parseFilterAST({ code: 42 }))).toEqual([]);
147+
});
148+
});

‎packages/drivers/driver-mongodb/src/mongodb-comparand-type-conformance.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ import { BSON } from 'mongodb';
3535
import {
3636
FILTER_COMPARAND_TYPE_CASES,
3737
FILTER_COMPARAND_TYPE_ROWS,
38+
FILTER_STRING_STORED_COMPARAND_CASES,
39+
FILTER_STRING_STORED_COMPARAND_ROWS,
3840
parseFilterAST,
3941
type ComparandTypeRow,
42+
type StringStoredComparandRow,
4043
type FilterCondition,
4144
} from '@objectstack/spec/data';
4245
import { translateFilter } from './mongodb-filter.js';
@@ -106,7 +109,7 @@ function matchField(value: unknown, cond: unknown): boolean {
106109
return value === cond;
107110
}
108111

109-
function matchDoc(row: ComparandTypeRow, doc: Record<string, unknown>): boolean {
112+
function matchDoc(row: ComparandTypeRow | StringStoredComparandRow, doc: Record<string, unknown>): boolean {
110113
for (const [key, value] of Object.entries(doc)) {
111114
switch (key) {
112115
case '$and':
@@ -189,3 +192,24 @@ describe('[#7872] driver-mongodb — comparand-type conformance (server-free, be
189192
.toEqual(['1', '2']);
190193
});
191194
});
195+
196+
/**
197+
* [#29486] `FILTER_STRING_STORED_COMPARAND_CASES`, the driver's half: a number
198+
* or boolean comparand on a text- or option-family field reaches
199+
* `translateFilter` already narrowed to the string the write door stored (the
200+
* engine's declared-type door, pinned in `@objectstack/objectql`), so each
201+
* case's `stored()` filter, translated and wire-round-tripped, must select
202+
* exactly its rows — judged by the same strict reader as the table above.
203+
*/
204+
describe('[#29486] driver-mongodb — a number or boolean comparand on a string-stored field, as the door hands it', () => {
205+
for (const c of FILTER_STRING_STORED_COMPARAND_CASES) {
206+
it(c.name, () => {
207+
const doc = translateFilter(parseFilterAST(c.stored()) as FilterCondition) as Record<string, unknown>;
208+
const wire = BSON.deserialize(BSON.serialize(doc)) as Record<string, unknown>;
209+
const selected = FILTER_STRING_STORED_COMPARAND_ROWS.filter((row) => matchDoc(row, wire))
210+
.map((row) => row.id)
211+
.sort((x, y) => x.localeCompare(y));
212+
expect(selected, c.note).toEqual([...c.expected]);
213+
});
214+
}
215+
});

‎packages/drivers/driver-odata/src/odata-driver.conformance.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {
4545
FILTER_COMPARAND_TYPE_ROWS,
4646
FILTER_LOGIC_CASES,
4747
FILTER_LOGIC_ROWS,
48+
FILTER_STRING_STORED_COMPARAND_CASES,
49+
FILTER_STRING_STORED_COMPARAND_ROWS,
4850
FILTER_TEXT_CASES,
4951
FILTER_TEXT_ROWS,
5052
PAGINATION_ALL_IDS,
@@ -204,6 +206,25 @@ for (const version of VERSIONS) {
204206
}
205207
});
206208

209+
// [#29486] Through the engine, as written: the engine's declared-type door narrows a number
210+
// or boolean comparand on the text and select fields to the stored string before the
211+
// OData filter is built, so the as-written filter answers the case's rows end to end.
212+
describe('FILTER_STRING_STORED_COMPARAND_CASES', () => {
213+
const setup = () => boot({
214+
version,
215+
collation,
216+
properties: [STRING('id', false), STRING('code'), STRING('stage')],
217+
rows: FILTER_STRING_STORED_COMPARAND_ROWS,
218+
fields: { code: text, stage: { type: 'select' } },
219+
});
220+
for (const c of FILTER_STRING_STORED_COMPARAND_CASES) {
221+
it(c.name, async () => {
222+
const { engine } = await setup();
223+
expect(sortedIds(await engine.find(OBJECT, { where: c.filter(), ...SYSTEM } as never)), c.note).toEqual([...c.expected]);
224+
});
225+
}
226+
});
227+
207228
// Not a shared case-set: the shared filter rows negate text, which the driver never pushes
208229
// down. A negation on a number is pushed down, under `not`, to a service whose parser reads
209230
// OData's precedence (`not` binds tighter than `eq`) and refuses a non-Boolean operand.

‎packages/drivers/driver-sql/src/sql-driver-comparand-type-conformance.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ import type { Knex } from 'knex';
7777
import {
7878
FILTER_COMPARAND_TYPE_CASES,
7979
FILTER_COMPARAND_TYPE_ROWS,
80+
FILTER_STRING_STORED_COMPARAND_CASES,
81+
FILTER_STRING_STORED_COMPARAND_ROWS,
8082
parseFilterAST,
8183
type FilterCondition,
8284
} from '@objectstack/spec/data';
@@ -109,6 +111,55 @@ for (const cell of DIALECT_CELLS) {
109111
continue;
110112
}
111113
declareComparandTypeSweep(cell);
114+
declareStringStoredSweep(cell);
115+
}
116+
117+
/**
118+
* [#29486] `FILTER_STRING_STORED_COMPARAND_CASES`, the driver's half: a number
119+
* or boolean comparand on a text- or option-family field reaches this driver
120+
* already narrowed to the string the write door stored (the engine's
121+
* declared-type door, pinned in `@objectstack/objectql`), so each case's
122+
* `stored()` filter must select exactly its rows here. The columns are the
123+
* ones `syncSchema` gives a `text` and a `select` field: strings.
124+
*/
125+
function declareStringStoredSweep(cell: DialectCell): void {
126+
describe(`[#29486] SqlDriver — a number or boolean comparand on a string-stored field, as the door hands it (${cell.label})`, () => {
127+
const STRING_TABLE = 'os29486_string_stored';
128+
let driver: SqlDriver;
129+
let knexInstance: Knex;
130+
131+
beforeAll(async () => {
132+
driver = new SqlDriver(cell.config());
133+
knexInstance = driver.getKnex();
134+
await knexInstance.schema.dropTableIfExists(STRING_TABLE);
135+
await knexInstance.schema.createTable(STRING_TABLE, (t: Knex.TableBuilder) => {
136+
t.string('id').primary();
137+
t.string('code');
138+
t.string('stage');
139+
});
140+
await knexInstance(STRING_TABLE).insert(FILTER_STRING_STORED_COMPARAND_ROWS.map((r) => ({ ...r })));
141+
});
142+
143+
afterAll(async () => {
144+
await knexInstance?.schema.dropTableIfExists(STRING_TABLE).catch(() => {});
145+
await driver?.disconnect?.();
146+
});
147+
148+
const ids = async (where: FilterCondition | undefined): Promise<string[]> => {
149+
const rows = await driver.find(STRING_TABLE, { fields: ['id'], where });
150+
return rows.map((r: any) => String(r.id)).sort((x, y) => x.localeCompare(y));
151+
};
152+
153+
it('the fixture really is every row', async () => {
154+
expect(await ids(undefined)).toEqual(FILTER_STRING_STORED_COMPARAND_ROWS.map((r) => r.id));
155+
});
156+
157+
for (const c of FILTER_STRING_STORED_COMPARAND_CASES) {
158+
it(c.name, async () => {
159+
expect(await ids(parseFilterAST(c.stored())), c.note).toEqual([...c.expected]);
160+
});
161+
}
162+
});
112163
}
113164

114165
function declareComparandTypeSweep(cell: DialectCell): void {

‎packages/drivers/driver-sqlite-wasm/src/sqlite-wasm-comparand-type-conformance.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1616
import {
1717
FILTER_COMPARAND_TYPE_CASES,
1818
FILTER_COMPARAND_TYPE_ROWS,
19+
FILTER_STRING_STORED_COMPARAND_CASES,
20+
FILTER_STRING_STORED_COMPARAND_ROWS,
1921
parseFilterAST,
2022
type FilterCondition,
2123
} from '@objectstack/spec/data';
@@ -84,3 +86,46 @@ describe('[#7872] SqliteWasmDriver — comparand-type conformance (behind the do
8486
expect(await ids(undefined)).toEqual(['1', '2']);
8587
});
8688
});
89+
90+
/**
91+
* [#29486] `FILTER_STRING_STORED_COMPARAND_CASES`, the driver's half: a number
92+
* or boolean comparand on a text- or option-family field reaches this driver
93+
* already narrowed to the string the write door stored (the engine's
94+
* declared-type door, pinned in `@objectstack/objectql`), so each case's
95+
* `stored()` filter must select exactly its rows here.
96+
*/
97+
describe('[#29486] SqliteWasmDriver — a number or boolean comparand on a string-stored field, as the door hands it', () => {
98+
const STRING_TABLE = 'string_stored_conformance';
99+
let driver: SqliteWasmDriver;
100+
101+
beforeAll(async () => {
102+
driver = new SqliteWasmDriver({ filename: ':memory:' });
103+
await driver.initObjects([
104+
{ name: STRING_TABLE, fields: { code: { type: 'string' }, stage: { type: 'string' } } },
105+
]);
106+
for (const row of FILTER_STRING_STORED_COMPARAND_ROWS) {
107+
await driver.create(STRING_TABLE, { ...row }, { bypassTenantAudit: true });
108+
}
109+
});
110+
111+
afterAll(async () => {
112+
await driver.disconnect();
113+
});
114+
115+
const ids = async (where: FilterCondition | undefined): Promise<string[]> => {
116+
const rows = await driver.find(STRING_TABLE, { fields: ['id'], where });
117+
return (rows as Array<Record<string, unknown>>)
118+
.map((r) => String(r.id))
119+
.sort((x, y) => x.localeCompare(y));
120+
};
121+
122+
it('the fixture really is every row', async () => {
123+
expect(await ids(undefined)).toEqual(FILTER_STRING_STORED_COMPARAND_ROWS.map((r) => r.id));
124+
});
125+
126+
for (const c of FILTER_STRING_STORED_COMPARAND_CASES) {
127+
it(c.name, async () => {
128+
expect(await ids(parseFilterAST(c.stored())), c.note).toEqual([...c.expected]);
129+
});
130+
}
131+
});

‎packages/drivers/driver-turso/src/turso-comparand-type-conformance.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1919
import {
2020
FILTER_COMPARAND_TYPE_CASES,
2121
FILTER_COMPARAND_TYPE_ROWS,
22+
FILTER_STRING_STORED_COMPARAND_CASES,
23+
FILTER_STRING_STORED_COMPARAND_ROWS,
2224
parseFilterAST,
2325
type FilterCondition,
2426
} from '@objectstack/spec/data';
@@ -88,3 +90,46 @@ describe('[#7872] TursoDriver — comparand-type conformance (local mode, behind
8890
expect(await ids(undefined)).toEqual(['1', '2']);
8991
});
9092
});
93+
94+
/**
95+
* [#29486] `FILTER_STRING_STORED_COMPARAND_CASES`, the driver's half: a number
96+
* or boolean comparand on a text- or option-family field reaches this driver
97+
* already narrowed to the string the write door stored (the engine's
98+
* declared-type door, pinned in `@objectstack/objectql`), so each case's
99+
* `stored()` filter must select exactly its rows here.
100+
*/
101+
describe('[#29486] TursoDriver — a number or boolean comparand on a string-stored field, as the door hands it', () => {
102+
const STRING_TABLE = 'string_stored_conformance';
103+
let driver: TursoDriver;
104+
105+
beforeAll(async () => {
106+
driver = new TursoDriver({ url: ':memory:' });
107+
await driver.initObjects([
108+
{ name: STRING_TABLE, fields: { code: { type: 'string' }, stage: { type: 'string' } } },
109+
]);
110+
for (const row of FILTER_STRING_STORED_COMPARAND_ROWS) {
111+
await driver.create(STRING_TABLE, { ...row }, { bypassTenantAudit: true });
112+
}
113+
});
114+
115+
afterAll(async () => {
116+
await driver.disconnect();
117+
});
118+
119+
const ids = async (where: FilterCondition | undefined): Promise<string[]> => {
120+
const rows = await driver.find(STRING_TABLE, { fields: ['id'], where });
121+
return (rows as Array<Record<string, unknown>>)
122+
.map((r) => String(r.id))
123+
.sort((x, y) => x.localeCompare(y));
124+
};
125+
126+
it('the fixture really is every row', async () => {
127+
expect(await ids(undefined)).toEqual(FILTER_STRING_STORED_COMPARAND_ROWS.map((r) => r.id));
128+
});
129+
130+
for (const c of FILTER_STRING_STORED_COMPARAND_CASES) {
131+
it(c.name, async () => {
132+
expect(await ids(parseFilterAST(c.stored())), c.note).toEqual([...c.expected]);
133+
});
134+
}
135+
});

0 commit comments

Comments
 (0)