Skip to content

Commit 45fea83

Browse files
authored
Merge pull request #198 from objectstack-ai/copilot/update-code-documentation-examples
2 parents d4d19f2 + b38db02 commit 45fea83

33 files changed

+1367
-255
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,32 @@ For the best experience, install the official extension. It provides **Intellige
9191

9292
ObjectQL uses **YAML** as the source of truth. Create a file `src/objects/story.object.yml`:
9393

94+
**Key Convention (v4.0+):** The object `name` is **inferred from the filename** - no redundant `name:` field needed!
95+
9496
```yaml
95-
name: story
97+
# File: story.object.yml
98+
# Object name is automatically inferred as 'story' ✅
9699
label: User Story
97100
fields:
98101
title:
99102
type: text
100103
required: true
104+
label: Story Title
101105
status:
102106
type: select
103-
options: [draft, active, done]
104-
default: draft
107+
options:
108+
- label: Draft
109+
value: draft
110+
- label: Active
111+
value: active
112+
- label: Done
113+
value: done
114+
defaultValue: draft
105115
points:
106116
type: number
107117
scale: 0
108-
default: 1
118+
defaultValue: 1
119+
label: Story Points
109120
```
110121
111122
### 4. Run & Play
@@ -174,11 +185,21 @@ import { MemoryDriver } from '@objectql/driver-memory';
174185
const driver = new MemoryDriver();
175186
const app = new ObjectQL({ datasources: { default: driver } });
176187

188+
// Define object following latest ObjectStack specification
177189
app.registerObject({
178-
name: 'tasks',
190+
name: 'tasks', // Required for programmatic registration
191+
label: 'Tasks',
179192
fields: {
180-
title: { type: 'text', required: true },
181-
completed: { type: 'boolean', defaultValue: false }
193+
title: {
194+
type: 'text',
195+
required: true,
196+
label: 'Task Title'
197+
},
198+
completed: {
199+
type: 'boolean',
200+
defaultValue: false,
201+
label: 'Completed'
202+
}
182203
}
183204
});
184205

content/docs/ai/coding-assistant.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,39 @@ navigation:
7474
7575
### 2. Object Definition (Schema)
7676
Objects are defined in `<name>.object.yml`.
77+
78+
**Key Convention (v4.0+):** The object `name` is **inferred from the filename** - no redundant `name:` field needed!
79+
7780
Supported types: `text`, `number`, `boolean`, `date`, `datetime`, `json`, `lookup`, `select`.
7881

7982
Example `todo.object.yml`:
8083
```yaml
81-
name: todo
84+
# File: todo.object.yml
85+
# Object name is inferred as 'todo' ✅
8286
label: Todo Item
8387
fields:
8488
title:
8589
type: text
8690
required: true
91+
label: Task Title
8792
completed:
8893
type: boolean
8994
defaultValue: false
95+
label: Completed
9096
priority:
9197
type: select
92-
options: [low, medium, high]
98+
label: Priority Level
99+
options:
100+
- label: Low
101+
value: low
102+
- label: Medium
103+
value: medium
104+
- label: High
105+
value: high
93106
owner:
94107
type: lookup
95108
reference_to: user
109+
label: Owner
96110
```
97111

98112
### 3. Data Operations (API)

content/docs/ai/generating-apps.mdx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,65 @@ To get the best results, use a prompt that enforces the ObjectQL schema format.
4141

4242
```yaml
4343
# agent.object.yml
44-
name: agent
44+
# Object name inferred as 'agent'
45+
label: Real Estate Agent
4546
fields:
4647
name:
4748
type: text
4849
required: true
50+
label: Agent Name
4951
email:
5052
type: email
5153
required: true
54+
label: Email Address
5255
phone:
5356
type: phone
57+
label: Phone Number
5458
license_number:
5559
type: text
60+
label: License Number
5661
status:
5762
type: select
58-
options: [active, inactive]
63+
label: Status
64+
options:
65+
- label: Active
66+
value: active
67+
- label: Inactive
68+
value: inactive
5969
```
6070
6171
```yaml
6272
# property.object.yml
63-
name: property
73+
# Object name inferred as 'property'
74+
label: Property
6475
fields:
6576
address:
6677
type: textarea
6778
required: true
79+
label: Property Address
6880
price:
6981
type: currency
82+
label: Listing Price
7083
bedrooms:
7184
type: number
85+
label: Number of Bedrooms
7286
bathrooms:
7387
type: number
88+
label: Number of Bathrooms
7489
listing_agent:
7590
type: lookup
7691
reference_to: agent
92+
label: Listing Agent
7793
status:
7894
type: select
79-
options: [for_sale, sold, pending]
95+
label: Listing Status
96+
options:
97+
- label: For Sale
98+
value: for_sale
99+
- label: Sold
100+
value: sold
101+
- label: Pending
102+
value: pending
80103
```
81104
82105
## Automating the Process

content/docs/data-access/best-practices.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,16 +630,26 @@ const uniqueCustomers = await app.object('order').distinct('customer_id', {
630630

631631
```yaml
632632
# task.object.yml
633-
name: task
633+
# Object name inferred as 'task'
634+
label: Task
634635
fields:
635636
status:
636637
type: select
637-
options: [open, in_progress, completed]
638+
label: Task Status
639+
options:
640+
- label: Open
641+
value: open
642+
- label: In Progress
643+
value: in_progress
644+
- label: Completed
645+
value: completed
638646
assignee_id:
639647
type: lookup
640648
reference_to: users
649+
label: Assignee
641650
due_date:
642651
type: date
652+
label: Due Date
643653

644654
indexes:
645655
# Composite index for common query

content/docs/logic/actions.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ actions:
4040
required: false
4141
method:
4242
type: select
43-
options: [cash, card, transfer]
44-
default: transfer
43+
label: Payment Method
44+
options:
45+
- label: Cash
46+
value: cash
47+
- label: Card
48+
value: card
49+
- label: Transfer
50+
value: transfer
51+
defaultValue: transfer
4552

4653
import_csv:
4754
type: global # 'global' = acts on the collection

examples/integrations/browser/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ <h2>🖥️ Console Output</h2>
247247
});
248248

249249
log('📝 Registering Notes schema...');
250+
// Note: When using registerObject() programmatically, 'name' is required
251+
// When using YAML files, the name is inferred from filename (latest ObjectStack spec)
250252
window.app.registerObject({
251-
name: 'notes',
253+
name: 'notes', // Required for programmatic registration
252254
label: 'Notes',
253255
fields: {
254256
content: {
Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,71 @@
1+
# File: task.object.yml
2+
# Object name is inferred from filename as 'task'
13
label: Tasks
4+
5+
ai_context:
6+
intent: "Track individual tasks and their completion status"
7+
domain: task_management
8+
common_queries:
9+
- "Find pending tasks"
10+
- "Show overdue tasks"
11+
- "List tasks by priority"
12+
213
fields:
314
title:
4-
type: string
15+
type: text
516
label: Title
617
required: true
18+
ai_context:
19+
intent: "Brief description of the task"
720
description:
8-
type: text
21+
type: textarea
922
label: Description
23+
ai_context:
24+
intent: "Detailed task information"
1025
status:
11-
type: string
26+
type: select
1227
label: Status
28+
options:
29+
- label: Pending
30+
value: pending
31+
- label: In Progress
32+
value: in_progress
33+
- label: Completed
34+
value: completed
35+
- label: Cancelled
36+
value: cancelled
1337
defaultValue: pending
38+
ai_context:
39+
intent: "Current state of the task"
40+
is_state_machine: true
41+
transitions:
42+
pending: [in_progress, cancelled]
43+
in_progress: [completed, pending, cancelled]
44+
completed: []
45+
cancelled: [pending]
1446
priority:
15-
type: string
47+
type: select
1648
label: Priority
49+
options:
50+
- label: Low
51+
value: low
52+
- label: Medium
53+
value: medium
54+
- label: High
55+
value: high
56+
- label: Urgent
57+
value: urgent
1758
defaultValue: medium
59+
ai_context:
60+
intent: "Task urgency level"
1861
due_date:
1962
type: date
2063
label: Due Date
64+
ai_context:
65+
intent: "Deadline for task completion"
2166
completed:
2267
type: boolean
2368
label: Completed
2469
defaultValue: false
70+
ai_context:
71+
intent: "Quick completion flag"
Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
1+
# File: user.object.yml
2+
# Object name is inferred from filename as 'user'
13
label: Users
4+
5+
ai_context:
6+
intent: "Manage user accounts and profiles"
7+
domain: user_management
8+
common_queries:
9+
- "Find active users"
10+
- "List users by age"
11+
- "Search users by email"
12+
213
fields:
314
name:
4-
type: string
15+
type: text
516
label: Full Name
617
required: true
18+
ai_context:
19+
intent: "User's full name for display"
720
email:
8-
type: string
21+
type: email
922
label: Email Address
1023
required: true
24+
ai_context:
25+
intent: "Primary contact email and login identifier"
1126
status:
12-
type: string
27+
type: select
1328
label: Status
29+
options:
30+
- label: Active
31+
value: active
32+
- label: Inactive
33+
value: inactive
34+
- label: Suspended
35+
value: suspended
1436
defaultValue: active
37+
ai_context:
38+
intent: "Account status"
39+
is_state_machine: true
40+
transitions:
41+
active: [inactive, suspended]
42+
inactive: [active]
43+
suspended: [active, inactive]
1544
age:
1645
type: number
1746
label: Age
47+
ai_context:
48+
intent: "User's age for demographic purposes"

0 commit comments

Comments
 (0)