Skip to content

Commit a26fc82

Browse files
Copilothotlong
andcommitted
docs: add map format examples to defineStack() documentation
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>
1 parent 1562cf6 commit a26fc82

6 files changed

Lines changed: 94 additions & 3 deletions

File tree

content/docs/getting-started/core-concepts.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ When a business requirement changes, you must update code in **three or four pla
2828

2929
ObjectStack centralizes the "Intent" into a **single Protocol Definition**:
3030

31+
<Tabs items={['Array Format', 'Map Format']}>
32+
<Tab value="Array Format">
3133
```typescript
3234
// ONE definition — everything else derives from it
3335
import { defineStack } from '@objectstack/spec';
@@ -42,6 +44,29 @@ export default defineStack({
4244
}],
4345
});
4446
```
47+
</Tab>
48+
<Tab value="Map Format">
49+
```typescript
50+
// Map keys become the `name` field automatically
51+
import { defineStack } from '@objectstack/spec';
52+
53+
export default defineStack({
54+
objects: {
55+
user: {
56+
label: 'User',
57+
fields: {
58+
phone: { label: 'Phone Number', type: 'phone', required: true },
59+
},
60+
},
61+
},
62+
});
63+
```
64+
</Tab>
65+
</Tabs>
66+
67+
<Callout type="info">
68+
**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.
69+
</Callout>
4570

4671
From this single definition, ObjectStack automatically:
4772

content/docs/guides/cheatsheets/backward-compatibility.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ObjectStack follows [Semantic Versioning 2.0.0](https://semver.org/) (`MAJOR.MIN
2828
- **Zod schemas** are part of the public API surface. Adding optional properties is a MINOR change; removing or renaming properties is a MAJOR change.
2929
- **TypeScript types** inferred from Zod (`z.infer<typeof Schema>`) follow the same guarantees as their source schemas.
3030
- **Helper functions** (e.g., `defineStack`, `defineStudioPlugin`) maintain their call signatures within a MAJOR version.
31+
- **Input formats**`defineStack()` accepts both array and map (Record) format for all named metadata collections. Both formats are guaranteed stable within a MAJOR version.
3132
- **Enum values** are append-only within a MAJOR version. Existing values are never removed or renamed in MINOR/PATCH releases.
3233
- **Default values** in schemas are not changed in MINOR/PATCH releases unless fixing a documented bug.
3334

content/docs/guides/cheatsheets/protocol-diagram.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ flowchart LR
253253

254254
| Stage | Description |
255255
|:---|:---|
256-
| `defineStack()` | Developer declares objects, fields, views in `objectstack.config.ts` |
256+
| `defineStack()` | Developer declares objects, fields, views in `objectstack.config.ts` (array or map format) |
257257
| Manifest | Compiled configuration package with all metadata |
258258
| Schema Registry | In-memory registry of all object and field definitions |
259259
| JSON Schema | Generated JSON Schema files for IDE validation |

content/docs/guides/common-patterns.mdx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This guide covers the most common patterns you will use when building applicatio
1717

1818
Define a basic object with common fields for create, read, update, and delete operations.
1919

20+
<Tabs items={['Array Format', 'Map Format']}>
21+
<Tab value="Array Format">
2022
```typescript
2123
import { defineStack } from '@objectstack/spec';
2224

@@ -42,6 +44,34 @@ export default defineStack({
4244
]
4345
});
4446
```
47+
</Tab>
48+
<Tab value="Map Format">
49+
```typescript
50+
import { defineStack } from '@objectstack/spec';
51+
52+
export default defineStack({
53+
objects: {
54+
project: {
55+
label: 'Project',
56+
fields: {
57+
title: { label: 'Title', type: 'text', required: true, maxLength: 200 },
58+
description: { label: 'Description', type: 'textarea' },
59+
status: { label: 'Status', type: 'select', options: [
60+
{ label: 'Planning', value: 'planning', default: true },
61+
{ label: 'Active', value: 'active' },
62+
{ label: 'Complete', value: 'complete' },
63+
{ label: 'Archived', value: 'archived' }
64+
]},
65+
owner: { label: 'Owner', type: 'lookup', reference: 'user' },
66+
due_date: { label: 'Due Date', type: 'date' },
67+
budget: { label: 'Budget', type: 'currency', currencyConfig: { precision: 2, defaultCurrency: 'USD' } },
68+
},
69+
},
70+
},
71+
});
72+
```
73+
</Tab>
74+
</Tabs>
4575

4676
---
4777

@@ -403,6 +433,8 @@ Restrict field visibility and editability based on user profiles.
403433

404434
Combine these patterns into a complete `defineStack()` configuration:
405435

436+
<Tabs items={['Array Format', 'Map Format']}>
437+
<Tab value="Array Format">
406438
```typescript
407439
import { defineStack } from '@objectstack/spec';
408440

@@ -429,6 +461,32 @@ export default defineStack({
429461
]
430462
});
431463
```
464+
</Tab>
465+
<Tab value="Map Format">
466+
```typescript
467+
import { defineStack } from '@objectstack/spec';
468+
469+
export default defineStack({
470+
objects: {
471+
// Pattern 1: CRUD objects
472+
project: { label: 'Project', fields: {/* ... */} },
473+
// Pattern 2: Master-detail
474+
task: { label: 'Task', fields: {/* ... */} },
475+
},
476+
apps: {
477+
// Pattern 5: Navigation
478+
},
479+
flows: {
480+
// Pattern 6: Automations
481+
// Pattern 7: Approval workflows
482+
},
483+
agents: {
484+
// Pattern 8: AI agents
485+
},
486+
});
487+
```
488+
</Tab>
489+
</Tabs>
432490

433491
<Callout type="tip">
434492
**Next Steps:**

content/docs/guides/data-flow.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ sequenceDiagram
5151

5252
| Stage | What Happens |
5353
|:---|:---|
54-
| `defineStack()` | Developer declares objects, fields, views, flows in TypeScript |
54+
| `defineStack()` | Developer declares objects, fields, views, flows in TypeScript (array or map format) |
5555
| Compile | CLI validates all definitions against Zod schemas |
5656
| Manifest | Compiled metadata package containing all configuration |
5757
| Kernel Boot | Kernel loads the manifest and initializes the plugin graph |

content/docs/guides/troubleshooting.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,20 @@ Common mistakes:
164164

165165
**Fix:**
166166
```typescript
167-
// Ensure the object is included in the stack
167+
// Ensure the object is included in the stack (array format)
168168
export default defineStack({
169169
objects: [
170170
{ name: 'project_task', /* ... */ }
171171
]
172172
});
173173

174+
// Or use map format (key becomes the name)
175+
export default defineStack({
176+
objects: {
177+
project_task: { /* ... */ }
178+
}
179+
});
180+
174181
// Use the exact same name when querying
175182
client.records.find('project_task', { /* query */ });
176183
```

0 commit comments

Comments
 (0)