You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/introduction/metadata-driven.mdx
+246-5Lines changed: 246 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,8 +66,13 @@ ObjectStack centralizes the "Intent" into a **single Protocol Definition**. The
66
66
67
67
```typescript
68
68
// ONE definition (in objectstack.config.ts)
69
-
export const User = Object({
69
+
import { ObjectSchema, Field } from '@objectstack/spec/data';
70
+
71
+
export const User = ObjectSchema.create({
70
72
name: 'user',
73
+
label: 'User',
74
+
icon: 'user',
75
+
71
76
fields: {
72
77
phone: Field.phone({
73
78
label: 'Phone Number',
@@ -77,6 +82,8 @@ export const User = Object({
77
82
});
78
83
```
79
84
85
+
> **📘 Syntax Rules**: Always use `ObjectSchema.create()` with `Field.*` helpers for strict TypeScript validation and runtime checking. See [Object Definition Rules](#object-definition-rules) below.
86
+
80
87
From this single definition, ObjectStack automatically:
81
88
82
89
✅ Generates database schema
@@ -188,14 +195,31 @@ React Flutter
188
195
189
196
```typescript
190
197
// All you need:
191
-
export const Task = Object({
198
+
import { ObjectSchema, Field } from '@objectstack/spec/data';
199
+
200
+
export const Task = ObjectSchema.create({
192
201
name: 'task',
202
+
label: 'Task',
203
+
icon: 'check-square',
204
+
193
205
fields: {
194
-
title: Field.text({ required: true }),
206
+
title: Field.text({
207
+
label: 'Title',
208
+
required: true,
209
+
}),
210
+
195
211
status: Field.select({
196
-
options: ['todo', 'in_progress', 'done'],
212
+
label: 'Status',
213
+
options: [
214
+
{ label: 'To Do', value: 'todo', default: true },
215
+
{ label: 'In Progress', value: 'in_progress' },
216
+
{ label: 'Done', value: 'done' },
217
+
],
218
+
}),
219
+
220
+
assignee: Field.lookup('user', {
221
+
label: 'Assignee',
197
222
}),
198
-
assignee: Field.lookup({ object: 'user' }),
199
223
},
200
224
});
201
225
@@ -246,6 +270,223 @@ You specify **exactly how** to draw each pixel.
246
270
|**Flexibility**| Locked to tech stack | Technology agnostic |
247
271
|**Boilerplate**| High (300+ lines) | Low (30 lines) |
248
272
273
+
## Object Definition Rules
274
+
275
+
When defining objects and metadata in ObjectStack, follow these strict rules and principles:
276
+
277
+
### 1. Always Use `ObjectSchema.create()` with `Field.*` Helpers
278
+
279
+
**✅ Correct:**
280
+
```typescript
281
+
import { ObjectSchema, Field } from'@objectstack/spec/data';
282
+
283
+
exportconst Account =ObjectSchema.create({
284
+
name: 'account',
285
+
label: 'Account',
286
+
fields: {
287
+
name: Field.text({ required: true }),
288
+
industry: Field.select({
289
+
options: [
290
+
{ label: 'Technology', value: 'technology' },
291
+
{ label: 'Finance', value: 'finance' },
292
+
],
293
+
}),
294
+
},
295
+
});
296
+
```
297
+
298
+
**❌ Deprecated:**
299
+
```typescript
300
+
// Old pattern - no runtime validation
301
+
const Account:ServiceObject= {
302
+
name: 'account',
303
+
fields: {
304
+
name: { type: 'text', required: true }
305
+
}
306
+
};
307
+
```
308
+
309
+
**Why?**
310
+
- ✅ **Type Safety**: Compile-time type checking via `z.input<typeof ObjectSchemaBase>`
311
+
- ✅ **Runtime Validation**: Zod validates structure at runtime
312
+
- ✅ **IDE Autocomplete**: Field helpers provide intelligent code completion
313
+
- ✅ **Error Prevention**: Catches typos and invalid configurations immediately
314
+
315
+
### 2. Naming Conventions
316
+
317
+
Follow these strict naming conventions for consistency:
0 commit comments