-
Notifications
You must be signed in to change notification settings - Fork 6
docs: Add map format examples to defineStack() documentation #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ This guide covers the most common patterns you will use when building applicatio | |
|
|
||
| Define a basic object with common fields for create, read, update, and delete operations. | ||
|
|
||
| <Tabs items={['Array Format', 'Map Format']}> | ||
| <Tab value="Array Format"> | ||
| ```typescript | ||
| import { defineStack } from '@objectstack/spec'; | ||
|
|
||
|
|
@@ -42,6 +44,34 @@ export default defineStack({ | |
| ] | ||
| }); | ||
| ``` | ||
| </Tab> | ||
| <Tab value="Map Format"> | ||
| ```typescript | ||
| import { defineStack } from '@objectstack/spec'; | ||
|
|
||
| export default defineStack({ | ||
| objects: { | ||
| project: { | ||
| label: 'Project', | ||
| 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' } }, | ||
| }, | ||
|
Comment on lines
+56
to
+68
|
||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| --- | ||
|
|
||
|
|
@@ -403,6 +433,8 @@ Restrict field visibility and editability based on user profiles. | |
|
|
||
| Combine these patterns into a complete `defineStack()` configuration: | ||
|
|
||
| <Tabs items={['Array Format', 'Map Format']}> | ||
| <Tab value="Array Format"> | ||
| ```typescript | ||
| import { defineStack } from '@objectstack/spec'; | ||
|
|
||
|
|
@@ -429,6 +461,32 @@ export default defineStack({ | |
| ] | ||
| }); | ||
| ``` | ||
| </Tab> | ||
| <Tab value="Map Format"> | ||
| ```typescript | ||
| import { defineStack } from '@objectstack/spec'; | ||
|
|
||
| export default defineStack({ | ||
| objects: { | ||
| // Pattern 1: CRUD objects | ||
| project: { label: 'Project', fields: {/* ... */} }, | ||
| // Pattern 2: Master-detail | ||
| task: { label: 'Task', fields: {/* ... */} }, | ||
|
Comment on lines
+472
to
+474
|
||
| }, | ||
| apps: { | ||
| // Pattern 5: Navigation | ||
| }, | ||
| flows: { | ||
| // Pattern 6: Automations | ||
| // Pattern 7: Approval workflows | ||
| }, | ||
| agents: { | ||
| // Pattern 8: AI agents | ||
| }, | ||
| }); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <Callout type="tip"> | ||
| **Next Steps:** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 thefieldsproperty within objects ONLY accepts map format (Record), never array format. The existing "Array Format" tab above (lines 41-42) incorrectly showsfieldsas an array, which contradicts the ObjectSchema definition where fields is defined asz.record(z.string().regex(...), FieldSchema). This should be corrected to avoid misleading developers into thinking fields can be either format.