Repository navigation
Commit 898145b
fix(service-datasource): fields of an object drafted from a datasource table carry a readable label (#30530)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgPnWQ3Q5ty932xxY9RSUuZ3)_
domain:server#6 · os-bill · session_01Utp6CXCS98uhsFQYk64epE
Refs #30469 (item 1)
Clause-②: no
Metadata-protocol: none
Skills-docs: none — `git grep -n -i -E "datasource (table
)?(sync|import)|external object|import_object|generateObjectDraft|object
draft" -- skills` on `aad627fd` answers 1 line,
`skills/objectstack-data/SKILL.md:47` (the catalog entry for the
datasources rule), and `skills/objectstack-data/rules/datasources.md`
names no introspect, draft, import or field label; no published sentence
describes the draft's field shape.
## 维护者速读
- 改了什么:从外部数据源同步(导入)表生成的对象,每个字段现在都带可读的显示名,例如列 `part_no` → `Part
No`、`part_name` → `Part Name`;对象自己的名称不变。
- 为什么改:同步后新建记录表单直接显示数据库列名(`part_no`),而列表里读作人话,每个打开表单的成员都会看到原始列名。
- 风险与回滚:只改生成草稿这一处,复用对象名称已在用的同一个转换函数;已导入的对象不回写,重新导入或手改才变。回滚即 revert 本 PR。
-
先看:`packages/services/service-datasource/src/external-datasource-service.ts`(列循环里的
`label: toLabel(fieldName)`、lookup 保留原 label、源码渲染行),再看
`src/__tests__/external-datasource-service.test.ts` 新增的 `generated field
labels`。
- 两分钟验证:`pnpm --filter @objectstack/service-datasource exec vitest run
src/__tests__/external-datasource-service.test.ts -t "generated field
labels"`,预期 3 条通过。
- 需要你做的:无,席位落地。第 2 项(同步对象该住哪个包、是否随导出走)实测结果见下,ADR-0146 没有直接定论,由席位另立决策卡。
## What changes
- `draftObject` gives every generated field a `label`, derived by
`toLabel` from the field name it is saved under, the same snake_case →
Title Case function that already labels the object
(`toLabel(shortName)`). No second derivation. The label follows the
field name after `rename` and after the numbering of a taken name
(`PartNo` beside `part_no` → `part_no_2` → `Part No 2`), never the raw
remote spelling.
- A navigation that becomes a `lookup` keeps the label of the scalar
column it replaces.
- The rendered `*.object.ts` source writes the label on each field line
(`part_no: { type: 'text', label: 'Part No' },`), quoted with the file's
existing `quoteTs`.
- `importObject` reuses the draft, so the persisted object carries the
same labels. The object label is unchanged (control pin).
- `DraftField` gains `label: string`.
## Tests
- New top-level `describe('generated field labels')` in the package's
shared harness file `external-datasource-service.test.ts`: a
`spare_parts` table (`id`, `part_no`, `part_name`, `PartNo`) yields
`Id`, `Part No`, `Part Name`, `Part No 2`; the object label stays `Spare
Parts`; a renamed column is labelled from its new name; the import
persists the same labels.
- Red on the merge base `0c7e95aff`: 3 failed (`expected { type:
'number' } to deeply equal { type: 'number', label: 'Id' }`, `expected
undefined to be 'Catalogue Number'`, `expected undefined to be 'Part
No'`).
- Eight existing pins asserted the old field shape exactly (`toEqual({
type })`, `Object.keys(record) == ['type']`, rendered field lines). They
now name the label too; the primary-key pins still fail on any extra
key, so the unauthorable `primaryKey` stays out.
- Ablation (once, `scripts/ablation-replace.mjs`, anchor hit ×1, blob
restored to HEAD, `git diff HEAD` empty): with the field written as `{
type }` again, the 3 new pins go red.
- On a booted showcase (scratch dogfood file, not committed): `POST
/datasources/showcase_external/external/tables/customers/import` → 201,
and `GET /api/v1/meta/object/showcase_customers` serves `name: Name`,
`email: Email`, `region: Region`, `lifetime_value: Lifetime Value`.
## Acceptance notes
### Item 2: where a synced object lives, and whether it exports
(measured, not built)
Reading on a booted showcase at `fc8cea50` (this branch before the main
merge; the incoming commits touch `ui/**` and one script only), after
importing `customers` from the showcase's code-declared external
datasource:
- `GET /api/v1/meta/object` lists `showcase_customers` with `_packageId:
"sys_metadata"`, no `_packageVersion`. Control: `showcase_task` lists
`_packageId: "com.example.showcase"`, `_packageVersion: "0.1.0"`. This
matches the `#30328` reading for a datasource added in Setup.
- `GET /api/v1/packages/export` (what `os package export` reads) answers
`{"success":true,"data":{"packages":[]}}`. The object is not in it. `GET
/api/v1/packages/com.example.showcase/export` answers 200 and does not
contain the object either.
- Why: the import saves through the metadata door with no `packageId`
(`plugin.ts` `persistObject`, `writeFace: 'external-import'`), so the
row is a package-less `sys_metadata` row.
What ADR-0146 says about it:
- D11 (Migrate): "A package-less row for an item **no** package ships is
environment metadata, not an overlay, and is not touched." A synced
object is an item no package ships, so today's placement is that class.
Context item 3 states such a row "does not travel": no package export
carries it.
- D2 / D3 (ADR-0070 D1): "an item the customer adds 'to HotCRM' lives in
a writable package", the base's `BASE.custom`. An import over a
datasource a package declares takes that package's namespace prefix
(`showcase_customers`), which reads as an item added to that package.
The ADR does not say whether such an import is a customization of the
base.
So the ADR does not settle it. For a datasource added in Setup (no
package, no namespace), today's package-less placement matches D11 and
the object does not export. For a datasource a package declares, D2 can
be read as asking for `BASE.custom`. Nothing is moved here. This is
recorded as an out-of-scope finding for the seat to take to a decision.
That is why this PR says `Refs`, not a closing keyword.
## Verification
<details><summary>Package suite and typecheck (final head)</summary>
`pnpm --filter @objectstack/service-datasource run typecheck` (tsc
--noEmit, lists all 12 `external-*` test files) and `vitest run
--maxWorkers=2`: Test Files 71 passed (71), Tests 1172 passed (1172).
</details>
<details><summary>Derived gates</summary>
Head `aad627fdb` (after the `origin/main` merge). `node
scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 61 commands; each was run with its
exit code recorded before any pipe, and `--ran` reconciles: 61 derived,
60 run, 1 NOT-MEASURED, 0 UNRUN.
- 59 exit 0 on the first run.
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: exit 3 on
the shallow checkout (it asks for history), exit 0 after `git fetch
origin 621a487…` (48 cases pass).
- `pnpm check:dual-build-cjs-loads`: exit 3, PREREQUISITE NOT MET (it
needs every package's `dist`, and only this card's closure was built).
NOT MEASURED here; CI's `Lint & Repo Gates` runs it.
- `pnpm lint` (outside the derivation): exit 0.
- Per-file `eslint --no-inline-config` on the six changed TypeScript
files: exit 0.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZyxdo9F9Zo2bX81CM)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4ccd790 commit 898145b
7 files changed
Lines changed: 118 additions & 28 deletions
File tree
- .changeset
- packages/services/service-datasource/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
224 | 224 | | |
225 | 225 | | |
226 | 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 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
227 | 301 | | |
228 | 302 | | |
229 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
194 | | - | |
| 193 | + | |
| 194 | + | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
415 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
416 | 420 | | |
417 | 421 | | |
418 | 422 | | |
| |||
915 | 919 | | |
916 | 920 | | |
917 | 921 | | |
918 | | - | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
919 | 925 | | |
920 | 926 | | |
921 | 927 | | |
| |||
1067 | 1073 | | |
1068 | 1074 | | |
1069 | 1075 | | |
1070 | | - | |
| 1076 | + | |
1071 | 1077 | | |
1072 | 1078 | | |
1073 | 1079 | | |
| |||
1527 | 1533 | | |
1528 | 1534 | | |
1529 | 1535 | | |
1530 | | - | |
| 1536 | + | |
1531 | 1537 | | |
1532 | 1538 | | |
1533 | 1539 | | |
| |||
0 commit comments