Repository navigation
Commit 86d2360
fix(rest): export boolean cells follow the caller's language (#24998)
Fixes #24945
Clause-②: no
## What changes
`GET /api/v1/data/:object/export` wrote every boolean or toggle cell as
the literal `是` / `否`. The header row of the same file follows the
caller's locale, so an `Accept-Language: en-US` caller got "Converted"
and "Do Not Call" over Chinese cells. The cell now follows the same
locale as the header.
- `packages/rest/src/export-format.ts`
- `formatCellValue`, `formatRowCells` and `formatRowForJson` take
`booleanWords` beside `timezone`. The boolean / toggle branch writes
`booleanWords[0]` / `booleanWords[1]`.
- The words have one source: `templateText(locale).booleanWords` in
`import-template.ts`, the table the import template already uses (`yes`
/ `no`, or `是` / `否` for a `zh*` locale). The new `ExportBooleanWords`
type is that table's own field type. No second table.
- Without words, the formatter writes the pair `templateText(undefined)`
answers (`yes` / `no`). That is the same answer the import template
gives a request with no locale.
- `packages/rest/src/data-action-routes.ts`, the export route
- It resolves the request's i18n service once (`resolveI18nService`,
then `extractLocale(req, i18n)`). That is the same read
`answerImportTemplate` uses. It computes the words once per export from
that locale.
- It hands the same i18n service to `translateMetaItem` (its existing
optional fifth argument). So the header translation and the words read
one locale, from one service: `Accept-Language`, then `?locale=`, then
the service's default locale.
- csv, xlsx and json all pass the words through.
- `packages/rest/src/rest-server.ts`. This file is outside the claimed
file surface. See Deviations.
- The `DataActionRouteHost` literal gains `resolveI18nService` and
`extractLocale`. The route had no locale in hand: the header's locale
was resolved inside `translateMetaItem` and never left it.
- `rowsToCsv`, the csv arm's serializer, lives here. It takes
`booleanWords` after `timezone` and passes them to `formatRowCells`.
- `packages/rest/src/import-template.ts`: one import line.
`buildFieldMetaMap` / `ExportFieldMeta` now come from
`@objectstack/core`, where they are defined, and no longer through
`export-format.ts`'s re-export. `export-format.ts` now imports
`templateText` from here, and this keeps the two modules from importing
each other.
- No key, query parameter, accept set, header, column set or payload
shape moves. Only the text of a boolean cell changes. The public
declaration file gains nothing: in the built `dist/index.d.ts`,
`booleanWords`, `ExportBooleanWords`, `templateText` and `rowsToCsv`
each count 0 hits, and the control `ExportFieldMeta` counts 3.
## Readings on the mechanism assumptions
All readings come from the real export and import routes, on a real
ObjectQL engine and protocol with a sqlite `:memory:` driver
(`export-boolean-locale.test.ts`).
1. **Main writes `是` / `否` to an English caller, in every format.** At
base `78ab6474ca`, an `en-US` csv export reads header `ID,Full
Name,Converted,Do Not Call`, then row `1,Wren Halvorsen,是,否`. xlsx gives
the same cells. json gives `"是"` / `"否"` as strings: the json arm runs
the same branch through `formatRowForJson`, so it never kept raw `true`
/ `false`. With this PR, json writes the caller's words as strings. It
does not switch to raw booleans, because that would move a payload
shape.
2. **zh-CN and no locale.**
- A `zh-CN` caller keeps `是` / `否`, under the Chinese header.
- `templateText(undefined)` answers the English table, so a request with
no locale gets `yes` / `no`.
- The header with no locale is the authored label, untranslated. It
agrees with the cells only when the labels are authored in English (the
pinned fixture). A deployment whose i18n service declares a default
locale resolves a header-less request to that default for both halves.
This is pinned for a `zh-CN` default and for an `en` default.
3. **Re-import, both languages.** The importer
(`IMPORT_BOOLEAN_TRUE_TOKENS` / `IMPORT_BOOLEAN_FALSE_TOKENS` in
`packages/spec`) reads `yes` / `no` and `是` / `否`. Each language's csv
and xlsx export, posted to `POST /api/v1/data/:object/import` into a
fresh store, reads back as `[true, false]` / `[false, true]`. All four
pins are green.
4. **#2481 and #2916.** #2481 (the feature that added the formatter)
lists "boolean: `是` / `否`" in its plan. It was written before the export
resolved any locale, it has no comments, and its author is a
contributor. #2916 made export and import follow the caller's language
and does not mention booleans. Neither is a maintainer ruling that
booleans are `是` / `否` for every locale.
## Evidence
- **Red on main.** At `d913467d6e`, which is the new test file alone on
base `78ab6474ca`: `Tests 5 failed | 6 passed (11)`. The red pins are en
csv, the xlsx pair, the json pair, the default-locale pin (its `en`
half) and the no-i18n pin. The 6 green ones are the zh csv control,
`?locale=zh-CN`, and the four re-import pins: main's `是` / `否` file
re-imports.
- **Green.** `export-boolean-locale.test.ts`: `Tests 11 passed (11)`.
The 11 affected export / import files: `Tests 620 passed (620)`.
- **Ablation A: the locale handed to the words.** It replaced
`templateText(this.extractLocale(req, i18n)).booleanWords` with
`templateText(undefined).booleanWords` through
`scripts/ablation-replace.mjs`, on `data-action-routes.ts` (anchor 1 →
0, blob `53f7b7e9` → `5c3ec476`).
- Result: `Tests 5 failed | 6 passed (11)`. Every zh pin went red: csv,
the xlsx and json pairs, `?locale=`, and the default-locale pin.
- The en pin stayed green. That is the direction the code predicts: with
the locale dropped, the cells fall to `templateText(undefined)`, which
is the English pair. So the en pin's red reading is the main-red above,
not this ablation.
- Restored: blob == HEAD `53f7b7e9`, and `git diff HEAD` is empty.
- **Ablation B: one i18n service for both halves.** It replaced
`this.extractLocale(req, i18n)` with `this.extractLocale(req,
undefined)` (blob `53f7b7e9` → `8299404a`).
- Result: `Tests 1 failed | 10 passed (11)`. The red pin is the
default-locale one: a `zh-CN`-default deployment wrote the header
`编号,姓名,已转化,请勿致电` over `yes` / `no` cells.
- Restored: blob == HEAD `53f7b7e9`, and `git diff HEAD` is empty.
- Both ablations exercise this package's own `src/`, reached by relative
import from the test. No `dist/` rebuild was needed.
## Fixture triage
The existing pins on `是` / `否` named no locale. Each was triaged by its
fixture's language, so its header and cells keep one language:
- **Chinese fixtures now name a `zh-CN` caller.** These are
`export-integration.test.ts`, `rest.test.ts`'s mocked export suite, and
`import-template-route.test.ts`'s `exportOnce`.
- The last of these holds the recorded export bytes (csv, json, xlsx by
sha256), and it stays byte-identical with that caller.
- So a Chinese caller's file is exactly what it was before this PR.
- **English fixture.** `export-json-fields.test.ts` (labels `ID` /
`Title`, no locale) now expects `yes` / `no`.
## Gates (final head `3d3bafba28`)
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 68 commands. All 68 exited 0.
- The 10 families under "Declared WIDE population" also exited 0. These
are `check:init-service-contract`, `live-db-isolation`,
`meta-type-normalized`, `optional-error-sink`,
`resume-authority-declared`, `runner-env-posture`,
`settings-bind-window`, `startup-registry-verdict`, `verify-stand-in`
and `wildcard-fallthrough`.
- The `--ran` reconciliation: `✓ dispatch-gates --ran: 68 derived
famil(ies) accounted for — 68 run, 0 NOT-MEASURED (a DERIVED zero — all
68 recorded an exit code and none of them is 3).`
- `pnpm lint` (`eslint . --no-inline-config`): exit 0, no findings
printed.
- `pnpm --filter @objectstack/rest exec vitest run --project local`:
`Test Files 307 passed (307)`, `Tests 6165 passed | 326 skipped (6491)`.
- `pnpm --filter @objectstack/rest typecheck`: exit 0. The test layer
compiles the new file: `--listFiles` counts
`export-boolean-locale.test.ts` once.
- An earlier head red `check:query-options-erasure` (test surface 236 →
238). The cause was two `as any` casts on the re-import pins'
`engine.find` options. They are typed now, and the gate is green at the
final head.
## Deviations
- **File surface.** The claim's surface did not list
`packages/rest/src/rest-server.ts`. The fix needs it twice: once for the
host wiring, because the route had no locale, and once for `rowsToCsv`,
because the csv serializer lives there. The edits come to two host
entries, one import name and the `rowsToCsv` parameter with its doc.
## Acceptance notes
- **No i18n service and no locale.** The cells read `yes` / `no` while
the header shows the authored labels. A deployment with Chinese-authored
labels, no i18n service and a header-less caller would show a Chinese
header over English words. The import template behaves the same way in
that case (`templateText(undefined)`). A deployment that registers the
i18n service gets its default locale for both halves.
- **json carries strings.** json boolean cells are display strings
(`"yes"` / `"是"`), as they were (`"是"`) before this PR. That is the
formatting layer's existing design, unchanged here.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01LmjU2x1faLZ39DVTFyVca6)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent fbb42d9 commit 86d2360
10 files changed
Lines changed: 367 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
| |||
884 | 886 | | |
885 | 887 | | |
886 | 888 | | |
887 | | - | |
888 | | - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
889 | 898 | | |
890 | 899 | | |
891 | 900 | | |
| |||
1084 | 1093 | | |
1085 | 1094 | | |
1086 | 1095 | | |
1087 | | - | |
| 1096 | + | |
1088 | 1097 | | |
1089 | 1098 | | |
1090 | 1099 | | |
| |||
1111 | 1120 | | |
1112 | 1121 | | |
1113 | 1122 | | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
1114 | 1133 | | |
1115 | 1134 | | |
1116 | 1135 | | |
1117 | 1136 | | |
1118 | 1137 | | |
1119 | 1138 | | |
1120 | | - | |
| 1139 | + | |
1121 | 1140 | | |
1122 | 1141 | | |
1123 | 1142 | | |
| |||
1291 | 1310 | | |
1292 | 1311 | | |
1293 | 1312 | | |
1294 | | - | |
| 1313 | + | |
1295 | 1314 | | |
1296 | 1315 | | |
1297 | 1316 | | |
1298 | 1317 | | |
1299 | 1318 | | |
1300 | 1319 | | |
1301 | 1320 | | |
1302 | | - | |
| 1321 | + | |
1303 | 1322 | | |
1304 | 1323 | | |
1305 | 1324 | | |
| |||
1320 | 1339 | | |
1321 | 1340 | | |
1322 | 1341 | | |
1323 | | - | |
| 1342 | + | |
1324 | 1343 | | |
1325 | 1344 | | |
1326 | 1345 | | |
| |||
| 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 | + | |
0 commit comments