Repository navigation
Commit 0abd4f9
fix(app-shell): the External Datasource panel unwraps the
Fixes #11628
Clause-②: no
## What changed
`packages/app-shell/src/views/metadata-admin/external/api.ts` read the
External Datasource routes as if they answered bare payloads. Every
`/datasources/:name/external/*` route answers through the shared
`sendOk`, so the payload sits under `data`. The client read `tables`,
`draft`, `catalog` and `{ ok, results }` from the top of the body. As a
result the panel listed no remote tables (`tables ?? []` turned the miss
into an empty list), showed no catalog timestamp, crashed Validation on
`results.length`, and the import dialog could not be reached.
- A new `readExternalData` unwraps `data` once, for all four
`/external/*` calls. Each caller then reads its own payload key from
`data`. A 2xx body without the `{ success: true, data }` envelope is now
an error that names the route, instead of being read as an empty answer.
- The same reader's failure arm called `String(body.error)` on the
ADR-0112 nested envelope, so every refusal read `[object Object]`. The
503 arm compared that same string with `external_service_unavailable`, a
code the server no longer sends, so the "federation not enabled" hint
could never show. Refusals now go through app-shell's existing
`readEnvelopeFailureText`. The 503 is now recognised by the envelope's
own `code`, `SERVICE_UNAVAILABLE`. This is the PM's mechanism assumption
2: measured below, it was the same envelope in the same function, so it
is fixed in this PR.
- `importObjectDraft` keeps its own reader, because it calls the `/meta`
door, not an `/external/*` route. That door's success body is the save
result, with no `data`. Its refusals come in two dialects, both
measured: nested `{ error: { code, message } }` from the capability
gate, and flat `{ error: 'SENTENCE', code }` from spec validation. The
old reader handled only the flat one, and printed a non-admin's 403 as
`[object Object]`. It now reads both.
- `api.test.ts` uses the measured wire shapes. It covers all five calls,
the 503 arm on each of the four routes, and both `/meta` refusal
dialects.
- No panel component changed. With the client fixed, the four consumers
(`SchemaBrowser`, `ExternalDatasourcePanel`, `ValidationPanel`,
`ImportObjectDialog`) render correctly as they are.
## Wire shapes, measured live (objectstack `main` at `0a348031`, stock
showcase, `--fresh`)
| Call | Route | Success body on the wire | Refusal body on the wire |
Old client read |
|---|---|---|---|---|
| `listRemoteTables` | `GET /external/tables` |
`{success:true,data:{tables:[customers,orders]}}` |
`{success:false,error:{code,message}}` (401 `UNAUTHENTICATED`, 403
`PERMISSION_DENIED`) | `body.tables`, missing, so `[]` |
| `generateObjectDraft` | `POST /external/tables/:remote/draft` |
`{success:true,data:{draft:{...}}}` | 400 `EXTERNAL_DATASOURCE_ERROR`
nested | `body.draft`, so `undefined` |
| `refreshCatalog` | `POST /external/refresh-catalog` |
`{success:true,data:{catalog:{snapshotAt,...}}}` | 400
`EXTERNAL_DATASOURCE_ERROR` nested | `body.catalog`, so `undefined` |
| `validateDatasource` | `POST /external/validate` |
`{success:true,data:{ok:true,results:[2 rows]}}` | 403
`PERMISSION_DENIED` nested | the whole envelope as `{ok,results}`, so
`results` was `undefined` |
| `importObjectDraft` | `PUT /meta/object/:name` |
`{success:true,version,seq,state,message}` (no `data`, not read) | 403
`{error:{code:'FORBIDDEN',message}}` nested; 422 `INVALID_METADATA` and
400 `VALIDATION_ERROR` flat `{error:'SENTENCE',code}` |
`String(body.error)`: right for flat, `[object Object]` for nested |
The 503 `SERVICE_UNAVAILABLE` arm cannot be reached on the showcase,
because it wires the `external-datasource` service. Its shape comes from
the server's `unavailable` writer in `registerExternalDatasourceRoutes`
(`sendError(res, 503, 'SERVICE_UNAVAILABLE', …)`) and is covered by the
unit test. Live: NOT MEASURED.
## Live panel, before and after (same backend, console from this
worktree)
The console ran from this worktree under `vite`, proxied to the backend,
at `/apps/setup/metadata/datasource/showcase_external`. "Before" is
`api.ts` temporarily restored to the base `1c2e2c4` from the committed
fix; restoring HEAD was confirmed by blob hash. Both runs blocked the
dev-only `/api/v1/dev/metadata-events` stream; see Acceptance notes.
| Step | Before (`1c2e2c4`) | After (this branch) |
|---|---|---|
| Tables tab | 0 rows, "No remote tables found (check the datasource's
allowedSchemas)." | 2 rows: `customers` 7, `orders` 7 |
| Refresh catalog | 200 with `data.catalog.snapshotAt`; no timestamp
rendered | `snapshot 10/5/2026, 2:51:36 AM` rendered |
| Import dialog, up to the draft read | unreachable (no row) | opens;
`POST …/tables/customers/draft` 200; shows object name `customers` and
the generated source |
| Validation, Run validation | "Preview failed to render", `Cannot read
properties of undefined (reading 'length')` | "All 2 objects match the
remote schema." with `showcase_ext_customer` and `showcase_ext_order` |
The real `api.ts` was also called inside the page against the same
backend, as the admin and as the non-admin `auditor.demo@example.com`
persona:
| Call | Before | After |
|---|---|---|
| admin `generateObjectDraft(showcase_external, no_such_table)` |
`Error: [object Object]` | `Remote table 'no_such_table' not found on
datasource 'showcase_external'. (EXTERNAL_DATASOURCE_ERROR)` |
| admin `refreshCatalog(no_such_ds)` | `Error: [object Object]` |
`[ObjectQL] Datasource 'no_such_ds' has no registered driver to
introspect. (EXTERNAL_DATASOURCE_ERROR)` |
| auditor `listRemoteTables` / `validateDatasource` | `Error: [object
Object]` | `Introspecting an external datasource requires the
manage_platform_settings capability. (PERMISSION_DENIED)` (the server
wraps the capability name in backticks; dropped here) |
| auditor `importObjectDraft` | `Error: [object Object]` | `Saving a
metadata item requires the manage_metadata capability. (FORBIDDEN)` |
| admin `importObjectDraft` (name mismatch, flat 400) | the server's
sentence | the same sentence (unchanged) |
## PM mechanism assumptions
1. Confirmed, and extended to the fifth call. The table above lists
every call in the file and the shape each one read.
2. Confirmed as a misread, live. Every refusal on these routes printed
`[object Object]`, and the 503 hint never fired. The fix is in this PR,
in the same reader.
3. For refusals there was already a helper, and this PR reuses it:
`readEnvelopeFailureText`
(`packages/app-shell/src/utils/apiErrorEnvelope.ts`, same package, no
new export). For success bodies app-shell has no shared unwrap helper.
`@object-ui/data-objectstack`'s `unwrapDispatcherEnvelope` is
module-private. It is also deliberately lenient (it returns the body
as-is when there is no `data`), and that is the tolerance this card's
defect hid behind. Reusing it would need a new package export, which the
Clause-② fence rules out. So the strict unwrap lives in this module.
4. The backend ran from this worker's own objectstack worktree at `main`
`0a348031`, built with `OS_SKIP_DTS=1` under the verify lock. The shared
checkout was not touched.
## Tests
All gates below ran on the merged head `4779053`: this branch plus one
merge of `origin/main` at `22ddcd5`. Each exit code was written to a
file as it ran.
- **Unit tests for this module, red before and green after.** `pnpm exec
vitest run
packages/app-shell/src/views/metadata-admin/external/api.test.ts`
- Fix committed (`790b3b1`), then `api.ts` restored to base `1c2e2c4`:
`Tests 12 failed | 4 passed (16)`, exit 1. The failures were `expected
[] to deeply equal [customers, orders]`, `Cannot read properties of
undefined (reading 'name')`, `expected undefined to deeply equal` the
catalog, the envelope returned as `{ok,results}`, `Error: [object
Object]` where `ExternalServiceUnavailableError` was expected, and
`'[object Object]'` in the message.
- `git checkout HEAD -- api.ts` put the fix back; the blob hash matched
HEAD and `git diff HEAD` was empty. Re-run: `Tests 16 passed (16)`, exit
0.
- The four tests that pass on the old client are the `?schema`
passthrough, the HTTP-status fallback, the `/meta` 2xx, and the flat
`/meta` refusal. The old client already handled each of these.
- **`pnpm exec vitest run packages/app-shell/ --maxWorkers=2`** (root
form, under the verify lock): `Test Files 1000 passed | 1 skipped
(1001)`, `Tests 9940 passed | 9 skipped (9949)`, exit 0.
- **`pnpm --filter @object-ui/app-shell type-check`** (`tsc --noEmit &&
tsc -p tsconfig.test.json`; the second config includes
`src/**/*.test.ts`), after `turbo run build
--filter='@object-ui/app-shell^...'`: exit 0.
- **`pnpm --filter @object-ui/app-shell lint`**: exit 0, `0 errors`. The
warnings are pre-existing, and none is in `external/api.ts` or
`api.test.ts`.
- **Root checks whose subject this diff touches:** all exit 0.
- `check:metadata-write-doors` reads `importObjectDraft` as a raw-PUT
door and prints `OK 17 metadata write door(s) derived (3 raw PUT, 14
SDK) … 3 reach assertObjectMetadataWritable`.
- `check:new-line-citations` prints `0 new citation(s)`.
- The rest: `check:control-bytes`, `check:test-path-roots`,
`check:vi-mock-specifiers`, `check:vi-mock-inherit`,
`check:vi-mock-override-shape`, `check:changeset-claims`,
`check:pending-changeset-literals`, `check:self-import`,
`check:esm-specifiers`, `check:shell-escape-residue`,
`check:unreferenced-sources`, `check:phantom-deps`, `check:unused-deps`,
`check:comment-mask-corpus`, `scripts/check-changeset-presence.mjs` and
`scripts/check-changeset-no-major.mjs`.
- `node scripts/check-governed-queue-guard.mjs --test` on the three
paths reports `NOT GOVERNED`.
- The repo-wide `pnpm lint` and the full test farm are left to CI.
## Acceptance notes
- **Dev-only reload after "Refresh catalog" (observation, not filed).**
With the console under `vite` dev and the backend under `objectstack
dev`, "Refresh catalog" writes the catalog snapshot. The backend then
emits a `metadata-change` event on `/api/v1/dev/metadata-events`, and
`apps/console`'s `MetadataHmrReloader` reloads the page about 0.6 s
later. That wipes the panel state, timestamp included. The reloader is
enabled by `import.meta.env.DEV`, so by its own default the published
console (`/_console`) does not run it (read from source; not measured on
`/_console`). The live measurement blocked that stream to see the panel
as the published console behaves. Owner: none.
- `listRemoteTables` no longer applies `?? []`. With the envelope
checked first, that fallback could only hide a `data` without `tables`,
and the server always sends `tables`.
- objectui's import dialog saves through `PUT /meta/object/:name`, not
the server's `POST /external/tables/:remote/import`.
objectstack-ai/objectstack#21788 (the server-side twin) is about that
POST route and stays open; this PR does not touch it.
- Behaviour change in `importObjectDraft`: a 2xx no longer parses the
body, because nothing reads it. A 2xx with an unparseable body used to
reject.
---
_Generated by [Claude
Code](https://claude.ai/code/session_015W8GBu6sBiqus2L2xjMsAL)_
---------
Co-authored-by: Claude <noreply@anthropic.com>{ success, data } envelope its routes answer (objectui#11628) (#11640)1 parent c4c506b commit 0abd4f9
3 files changed
Lines changed: 315 additions & 77 deletions
File tree
- .changeset
- packages/app-shell/src/views/metadata-admin/external
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 196 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
35 | 52 | | |
36 | 53 | | |
37 | 54 | | |
| |||
46 | 63 | | |
47 | 64 | | |
48 | 65 | | |
49 | | - | |
| 66 | + | |
50 | 67 | | |
51 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
52 | 76 | | |
53 | | - | |
54 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
55 | 82 | | |
56 | | - | |
| 83 | + | |
57 | 84 | | |
58 | 85 | | |
59 | 86 | | |
60 | | - | |
61 | | - | |
| 87 | + | |
| 88 | + | |
62 | 89 | | |
63 | 90 | | |
64 | 91 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 92 | + | |
78 | 93 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
82 | 99 | | |
83 | 100 | | |
84 | 101 | | |
| 102 | + | |
85 | 103 | | |
86 | 104 | | |
87 | 105 | | |
88 | 106 | | |
89 | 107 | | |
90 | 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 | + | |
91 | 209 | | |
92 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
93 | 214 | | |
94 | 215 | | |
95 | 216 | | |
| |||
103 | 224 | | |
104 | 225 | | |
105 | 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 | + | |
106 | 277 | | |
0 commit comments