Skip to content

Commit a41bce5

Browse files
committed
fix(data-objectstack): createView sends no top-level data on a ViewItem envelope
The view write door now refuses a key the envelope does not declare, and data is declared only inside config there. A flat list view keeps its default data. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufziYCUHZQE3MXucvWe9
1 parent a44242e commit a41bce5

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/data-objectstack': patch
3+
---
4+
5+
`ObjectStackAdapter.createView` no longer adds a top-level `data` to a ViewItem envelope (`{ name, object, viewKind, config }`). `data` belongs inside `config` there, and the platform's `view` write door now refuses a top-level key the envelope does not declare (objectstack#26711), so such a create was refused naming `data`. Before, the door dropped the key and the view saved. A flat list view still gets its default `data`, where that shape declares it. The console's own create flow writes through `createRuntimeMetadata` and was not affected.
6+
7+
Clause-②: no
8+
Metadata-protocol: none
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#26711 — the platform's `view` write door refuses a top-level key
11+
* the body's shape does not declare. `createView` defaulted a top-level `data`
12+
* onto every spec it sent. On a flat list view `data` is declared; on a
13+
* ViewItem envelope (`{ name, object, viewKind, config }`) it is declared only
14+
* inside `config`, so the save was refused with `unrecognized_keys` naming
15+
* `data` (before, the door dropped it unread). Each body the adapter sends is
16+
* judged here by the platform's own `ViewMetadataSchema`.
17+
*/
18+
19+
import { describe, it, expect, vi } from 'vitest';
20+
import { ViewMetadataSchema } from '@objectstack/spec/ui';
21+
import { ObjectStackAdapter } from './index';
22+
23+
function makeDS() {
24+
const saveItem = vi.fn(async (_type: string, _name: string, item: any) => ({ success: true, item }));
25+
const ds: any = new ObjectStackAdapter({
26+
baseUrl: 'http://test.local',
27+
fetch: vi.fn(async () =>
28+
new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
29+
status: 200,
30+
headers: { 'Content-Type': 'application/json' },
31+
})),
32+
});
33+
ds.connected = true;
34+
ds.connectionState = 'connected';
35+
ds.client = { meta: { saveItem } };
36+
return { ds, saveItem };
37+
}
38+
39+
const sent = (saveItem: ReturnType<typeof vi.fn>) => saveItem.mock.calls[0]![2] as Record<string, unknown>;
40+
41+
describe('createView sends a body the view write door accepts (objectstack#26711)', () => {
42+
it('a ViewItem envelope is sent without a top-level `data`, and the write door accepts it', async () => {
43+
const { ds, saveItem } = makeDS();
44+
await ds.createView('crm_lead', {
45+
name: 'crm_lead.probe',
46+
object: 'crm_lead',
47+
viewKind: 'list',
48+
label: 'Probe',
49+
config: { type: 'grid', data: { provider: 'object', object: 'crm_lead' }, columns: ['name'] },
50+
});
51+
const body = sent(saveItem);
52+
expect(body).not.toHaveProperty('data');
53+
const parsed = ViewMetadataSchema.safeParse(body);
54+
expect(parsed.success, JSON.stringify(parsed.success ? null : parsed.error.issues)).toBe(true);
55+
});
56+
57+
it('CONTROL: the envelope WITH the old top-level `data` is refused, naming the key', () => {
58+
const parsed = ViewMetadataSchema.safeParse({
59+
name: 'crm_lead.probe',
60+
object: 'crm_lead',
61+
viewKind: 'list',
62+
label: 'Probe',
63+
config: { type: 'grid', data: { provider: 'object', object: 'crm_lead' }, columns: ['name'] },
64+
data: { provider: 'object', object: 'crm_lead' },
65+
});
66+
expect(parsed.success).toBe(false);
67+
expect(JSON.stringify(parsed.success ? [] : parsed.error.issues)).toContain('"keys":["data"]');
68+
});
69+
70+
it('a flat list view still gets its default `data`, where the flat shape declares it', async () => {
71+
const { ds, saveItem } = makeDS();
72+
await ds.createView('crm_lead', { name: 'crm_lead.custom', viewKind: 'list', label: 'Custom', type: 'grid', columns: ['name'] });
73+
const body = sent(saveItem);
74+
expect(body.data).toEqual({ provider: 'object', object: 'crm_lead' });
75+
const parsed = ViewMetadataSchema.safeParse(body);
76+
expect(parsed.success, JSON.stringify(parsed.success ? null : parsed.error.issues)).toBe(true);
77+
});
78+
});

‎ui/packages/data-objectstack/src/index.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6035,11 +6035,17 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
60356035
const suffix = Date.now().toString(36);
60366036
name = `${base}_${suffix}`;
60376037
}
6038+
// `data` is a list view key. A flat spec declares it at the top level; a
6039+
// ViewItem envelope (`{ name, object, viewKind, config }`) declares it only
6040+
// inside `config`, and the platform's `view` write door refuses a key the
6041+
// envelope does not declare (objectstack#26711), so an envelope is sent
6042+
// without one.
6043+
const isEnvelope = spec?.config !== undefined && spec?.config !== null;
60386044
const fullSpec = {
60396045
...spec,
60406046
name,
60416047
object: spec?.object || objectName,
6042-
data: spec?.data || { provider: 'object', object: objectName },
6048+
...(isEnvelope ? {} : { data: spec?.data || { provider: 'object', object: objectName } }),
60436049
};
60446050
const result: any = await this.client.meta.saveItem('view', name, fullSpec);
60456051
// `saveItem` is an UPSERT: an explicit `spec.name` that already exists

0 commit comments

Comments
 (0)