From 1e34fc99a9a85bcc7d7ecd17ff60362813816aaa Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 04:47:34 +0000 Subject: [PATCH] fix(cli): os init -t app places its item fields through the group's fields list The app template's item object wrote a field group with no fields list and `group: 'details'` on each field, while `os g object` and the create-objectstack starter list a group's fields in the group itself, after the field map. The item now does the same, so a new project meets one placement style. Both spellings mean the same placement. A pin renders the template and asserts no per-field `group`, and that the details group lists every declared field. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L9qibypsynz3Cc6Yp3SXFZ --- .changeset/37615-init-item-field-placement.md | 10 +++++ packages/cli/src/commands/init.ts | 28 ++++++------ .../test/init-item-field-placement.test.ts | 45 +++++++++++++++++++ 3 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 .changeset/37615-init-item-field-placement.md create mode 100644 packages/cli/test/init-item-field-placement.test.ts diff --git a/.changeset/37615-init-item-field-placement.md b/.changeset/37615-init-item-field-placement.md new file mode 100644 index 00000000000..192df3e4df4 --- /dev/null +++ b/.changeset/37615-init-item-field-placement.md @@ -0,0 +1,10 @@ +--- +'@objectstack/cli': patch +--- + +fix(cli): `objectstack init -t app` places the item's fields through the group's `fields` list, as `objectstack generate object` does + +Clause-②: no +Metadata-protocol: none + +The item object of the `app` template now writes `fieldGroups: [{ key: 'details', label: 'Details', fields: ['name', 'description', 'status'] }]` after the field map, and its fields no longer carry `group: 'details'`. That is how `objectstack generate object` and the `npm create objectstack` starter place fields, so a new project meets one style. Both spellings mean the same placement: the form and detail page show the same Details section, and `objectstack validate` and `objectstack lint` report nothing new. A project scaffolded by an earlier release keeps working unchanged. When you add a field to the item, list its name in the group's `fields` too. diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 60040251a25..e775d8bccf0 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -1060,28 +1060,15 @@ ${starterObjectExportsNote(['src/apps/main.app.ts', `src/views/${namespace}_item export const ${toCamelCase(namespace)}Item = ObjectSchema.create({ name: '${namespace}_item', label: '${toTitleCase(namespace)} Item', - // Field groups: the sections an item's form and detail page draw, top to - // bottom in this order. A field joins one by naming its \`key\` in \`group\`. - // That placement is what displays \`description\` and \`status\`. - // \`objectstack validate\` and \`objectstack lint\` report a field that - // nothing displays or reads (\`field-no-consumers\`) once the project holds - // a view, flow, dashboard or anything else that could read it, so give each - // field you add a \`group\` as well. Field groups versus a view's own form - // sections: https://objectstack.ai/docs/ui/field-grouping-and-order - fieldGroups: [ - { key: 'details', label: 'Details' }, - ], fields: { // Each field through a \`Field.*\` builder (Field.textarea, Field.select, // Field.lookup, …), the way \`objectstack generate object\` writes them. name: Field.text({ label: 'Name', required: true, - group: 'details', }), description: Field.textarea({ label: 'Description', - group: 'details', }), status: Field.select({ label: 'Status', @@ -1091,9 +1078,22 @@ export const ${toCamelCase(namespace)}Item = ObjectSchema.create({ { label: 'Archived', value: 'archived' }, ], defaultValue: 'draft', - group: 'details', }), }, + + // Field groups: the Details sections of an item's record page and of its + // create and edit form, top to bottom in this order; a section's \`fields\` + // list names its fields in display order. That placement is what displays + // \`description\` and \`status\`. \`objectstack validate\` and + // \`objectstack lint\` report a field that nothing displays or reads + // (\`field-no-consumers\`) once the project holds a view, flow, dashboard or + // anything else that could read it, so list each field you add in a section + // too. Field groups versus a view's own form sections: + // https://objectstack.ai/docs/ui/field-grouping-and-order + fieldGroups: [ + { key: 'details', label: 'Details', fields: ['name', 'description', 'status'] }, + ], + // Org-wide default (OWD): who can see records they don't own. 'private' is // owner-only until access is widened by a permission grant or a sharing // rule. Declaring it is required, deliberately: \`objectstack build\` diff --git a/packages/cli/test/init-item-field-placement.test.ts b/packages/cli/test/init-item-field-placement.test.ts new file mode 100644 index 00000000000..6abce890f9e --- /dev/null +++ b/packages/cli/test/init-item-field-placement.test.ts @@ -0,0 +1,45 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * PIN (#37615) — `os init -t app` places its item's fields the way + * `os g object` and the `npm create objectstack` starter do: through the + * `details` group's own `fields` list, after the field map, and never through + * a per-field `group`. + * + * #32153 promised a newcomer one field-placement dialect. After `os g object` + * moved to the group's `fields` list, the `app` template's item object still + * wrote `fieldGroups: [{ key: 'details', label: 'Details' }]` and + * `group: 'details'` on each field, so the CLI wrote two dialects. Both + * spellings mean the same placement; this file pins the one the scaffolds + * teach. + */ + +import { describe, it, expect } from 'vitest'; +import { TEMPLATES } from '../src/commands/init'; + +const ITEM_OBJECT = 'src/objects/__name___item.object.ts'; + +function renderItemObject(): string { + const render = TEMPLATES.app.srcFiles[ITEM_OBJECT]; + expect(render, `the app template renders ${ITEM_OBJECT}`).toBeTypeOf('function'); + return render('my-app', 'my_app'); +} + +describe('[#37615] `os init -t app` item object field placement', () => { + it('writes no per-field `group`', () => { + expect(renderItemObject()).not.toMatch(/^ +group: '/m); + }); + + it("lists every declared field in the details group's `fields`, after the field map", () => { + const source = renderItemObject(); + const declared = [...source.matchAll(/^ {4}([a-z_][a-z0-9_]*): Field\./gm)].map((m) => m[1]); + expect(declared).toEqual(['name', 'description', 'status']); + + const group = source.match(/\{ key: 'details', label: 'Details', fields: \[([^\]]*)\] \}/); + expect(group, 'the details group carries a `fields` list').not.toBeNull(); + const listed = [...group![1].matchAll(/'([^']+)'/g)].map((m) => m[1]); + expect(listed).toEqual(declared); + + expect(source.indexOf('fieldGroups:')).toBeGreaterThan(source.indexOf('fields: {')); + }); +});