docs: Add map format examples to defineStack() documentation#680
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Update P0 docs (core-concepts, common-patterns) with tabbed Array/Map format examples. Update P1 docs (troubleshooting, backward-compatibility, data-flow, protocol-diagram) with map format mentions. Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds documentation for the map (Record) format support in defineStack(), complementing the existing array format examples. The changes demonstrate that top-level metadata collections (objects, apps, flows, etc.) can use either array or map format, with map keys automatically injected as the name field.
Changes:
- Added Tabs components to core learning paths showing both array and map format examples side-by-side
- Updated architecture documentation tables to note "(array or map format)" support
- Added SemVer guarantee that both input formats remain stable within major versions
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| content/docs/getting-started/core-concepts.mdx | Added Tabs with Array/Map format examples and explanatory Callout for first defineStack() encounter |
| content/docs/guides/common-patterns.mdx | Added Tabs for CRUD pattern and "Putting It All Together" section comparing both formats |
| content/docs/guides/troubleshooting.mdx | Updated "Object not found" troubleshooting to show both registration patterns |
| content/docs/guides/cheatsheets/backward-compatibility.mdx | Added guarantee that both array and map formats are SemVer-stable |
| content/docs/guides/data-flow.mdx | Added note "(array or map format)" to configuration flow table |
| content/docs/guides/cheatsheets/protocol-diagram.mdx | Added note "(array or map format)" to metadata resolution table |
| <Callout type="info"> | ||
| **Array or Map?** `defineStack()` accepts both formats for all named metadata collections (`objects`, `apps`, `flows`, etc.). Map keys are injected as the `name` field — pick whichever style you prefer. | ||
| </Callout> |
There was a problem hiding this comment.
This callout states that map/array formats apply to "all named metadata collections (objects, apps, flows, etc.)", which is correct. However, it's important to clarify that the fields property within objects ONLY accepts map format (Record), never array format. The existing "Array Format" tab above (lines 41-42) incorrectly shows fields as an array, which contradicts the ObjectSchema definition where fields is defined as z.record(z.string().regex(...), FieldSchema). This should be corrected to avoid misleading developers into thinking fields can be either format.
| fields: { | ||
| title: { label: 'Title', type: 'text', required: true, maxLength: 200 }, | ||
| description: { label: 'Description', type: 'textarea' }, | ||
| status: { label: 'Status', type: 'select', options: [ | ||
| { label: 'Planning', value: 'planning', default: true }, | ||
| { label: 'Active', value: 'active' }, | ||
| { label: 'Complete', value: 'complete' }, | ||
| { label: 'Archived', value: 'archived' } | ||
| ]}, | ||
| owner: { label: 'Owner', type: 'lookup', reference: 'user' }, | ||
| due_date: { label: 'Due Date', type: 'date' }, | ||
| budget: { label: 'Budget', type: 'currency', currencyConfig: { precision: 2, defaultCurrency: 'USD' } }, | ||
| }, |
There was a problem hiding this comment.
The Map Format tab correctly shows fields as a Record/map (lines 56-68). However, the Array Format tab above (lines 30-42, not in the changed region) incorrectly shows fields as an array, which is invalid according to ObjectSchema where fields is defined as z.record(z.string().regex(...), FieldSchema). This creates confusion by implying fields can be either format. The Array Format example should be corrected to also use map syntax for fields - only the top-level objects should differ between the two tabs.
| project: { label: 'Project', fields: {/* ... */} }, | ||
| // Pattern 2: Master-detail | ||
| task: { label: 'Task', fields: {/* ... */} }, |
There was a problem hiding this comment.
Good - the Map Format tab correctly shows fields: {/* ... */} (map syntax) as placeholders on lines 472 and 474. However, the Array Format tab above (lines 444, 446) shows fields: [/* ... */] which implies fields can be an array. This is incorrect - according to ObjectSchema, fields must always be a map/Record. The Array Format examples should also use fields: {/* ... */} placeholders.
defineStack()now accepts both array and map (Record) format for all named metadata collections, but docs only showed the array pattern. Updates the primary learning paths and reference docs to showcase both formats.P0 — Primary learning paths
defineStack()example now uses<Tabs>for Array/Map format with a callout explaining the feature<Tabs>with both variantsP1 — Error/compatibility/architecture docs
Example (core-concepts.mdx)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.