Skip to content

Commit de640e1

Browse files
committed
feat: update object schemas to include btree indexing and enhance field options
1 parent 554b221 commit de640e1

File tree

14 files changed

+296
-93
lines changed

14 files changed

+296
-93
lines changed

examples/app-crm/src/objects/account.object.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ export const Account = ObjectSchema.create({
122122

123123
// Database indexes for performance
124124
indexes: [
125-
{ fields: ['name'], unique: false },
126-
{ fields: ['owner'], unique: false },
127-
{ fields: ['type', 'is_active'], unique: false },
125+
{ fields: ['name'], type: 'btree' },
126+
{ fields: ['owner'], type: 'btree' },
127+
{ fields: ['type', 'is_active'], type: 'btree' },
128128
],
129129

130130
// Enable advanced features

examples/app-crm/src/objects/campaign.object.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ export const Campaign = ObjectSchema.create({
189189

190190
// Database indexes
191191
indexes: [
192-
{ fields: ['name'], unique: false },
193-
{ fields: ['type'], unique: false },
194-
{ fields: ['status'], unique: false },
195-
{ fields: ['start_date'], unique: false },
196-
{ fields: ['owner'], unique: false },
192+
{ fields: ['name'], type: 'btree' },
193+
{ fields: ['type'], type: 'btree' },
194+
{ fields: ['status'], type: 'btree' },
195+
{ fields: ['start_date'], type: 'btree' },
196+
{ fields: ['owner'], type: 'btree' },
197197
],
198198

199199
// Enable advanced features

examples/app-crm/src/objects/case.object.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,25 @@ export const Case = ObjectSchema.create({
6565
]
6666
}),
6767

68-
type: Field.select(['Question', 'Problem', 'Feature Request', 'Bug'], {
68+
type: Field.select({
6969
label: 'Case Type',
70+
options: [
71+
{ label: 'Question', value: 'question' },
72+
{ label: 'Problem', value: 'problem' },
73+
{ label: 'Feature Request', value: 'feature_request' },
74+
{ label: 'Bug', value: 'bug' },
75+
]
7076
}),
7177

72-
origin: Field.select(['Email', 'Phone', 'Web', 'Chat', 'Social Media'], {
78+
origin: Field.select({
7379
label: 'Case Origin',
80+
options: [
81+
{ label: 'Email', value: 'email' },
82+
{ label: 'Phone', value: 'phone' },
83+
{ label: 'Web', value: 'web' },
84+
{ label: 'Chat', value: 'chat' },
85+
{ label: 'Social Media', value: 'social_media' },
86+
]
7487
}),
7588

7689
// Assignment
@@ -164,11 +177,11 @@ export const Case = ObjectSchema.create({
164177

165178
// Database indexes for performance
166179
indexes: [
167-
{ fields: ['case_number'], unique: true },
168-
{ fields: ['account'], unique: false },
169-
{ fields: ['owner'], unique: false },
170-
{ fields: ['status'], unique: false },
171-
{ fields: ['priority'], unique: false },
180+
{ fields: ['case_number'], type: 'btree', unique: true },
181+
{ fields: ['account'], type: 'btree' },
182+
{ fields: ['owner'], type: 'btree' },
183+
{ fields: ['status'], type: 'btree' },
184+
{ fields: ['priority'], type: 'btree' },
172185
],
173186

174187
enable: {

examples/app-crm/src/objects/contact.object.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ export const Contact = ObjectSchema.create({
1111

1212
fields: {
1313
// Name fields
14-
salutation: Field.select(['Mr.', 'Ms.', 'Mrs.', 'Dr.', 'Prof.'], {
14+
salutation: Field.select({
1515
label: 'Salutation',
16+
options: [
17+
{ label: 'Mr.', value: 'mr' },
18+
{ label: 'Ms.', value: 'ms' },
19+
{ label: 'Mrs.', value: 'mrs' },
20+
{ label: 'Dr.', value: 'dr' },
21+
{ label: 'Prof.', value: 'prof' },
22+
]
1623
}),
1724
first_name: Field.text({
1825
label: 'First Name',
@@ -61,8 +68,18 @@ export const Contact = ObjectSchema.create({
6168
label: 'Job Title',
6269
}),
6370

64-
department: Field.select(['Executive', 'Sales', 'Marketing', 'Engineering', 'Support', 'Finance', 'HR', 'Operations'], {
71+
department: Field.select({
6572
label: 'Department',
73+
options: [
74+
{ label: 'Executive', value: 'executive' },
75+
{ label: 'Sales', value: 'sales' },
76+
{ label: 'Marketing', value: 'marketing' },
77+
{ label: 'Engineering', value: 'engineering' },
78+
{ label: 'Support', value: 'support' },
79+
{ label: 'Finance', value: 'finance' },
80+
{ label: 'HR', value: 'hr' },
81+
{ label: 'Operations', value: 'operations' },
82+
]
6683
}),
6784

6885
// Relationship fields
@@ -88,8 +105,15 @@ export const Contact = ObjectSchema.create({
88105
label: 'Birthdate',
89106
}),
90107

91-
lead_source: Field.select(['Web', 'Referral', 'Event', 'Partner', 'Advertisement'], {
108+
lead_source: Field.select({
92109
label: 'Lead Source',
110+
options: [
111+
{ label: 'Web', value: 'web' },
112+
{ label: 'Referral', value: 'referral' },
113+
{ label: 'Event', value: 'event' },
114+
{ label: 'Partner', value: 'partner' },
115+
{ label: 'Advertisement', value: 'advertisement' },
116+
]
93117
}),
94118

95119
description: Field.markdown({
@@ -131,6 +155,14 @@ export const Contact = ObjectSchema.create({
131155
mru: true, // Track Most Recently Used
132156
},
133157

158+
// Database indexes for performance
159+
indexes: [
160+
{ fields: ['account'], type: 'btree' },
161+
{ fields: ['email'], type: 'btree', unique: true },
162+
{ fields: ['owner'], type: 'btree' },
163+
{ fields: ['last_name', 'first_name'], type: 'btree' },
164+
],
165+
134166
// Display configuration
135167
titleFormat: '{full_name}',
136168
compactLayout: ['full_name', 'email', 'account', 'phone'],

examples/app-crm/src/objects/contract.object.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ export const Contract = ObjectSchema.create({
162162

163163
// Database indexes
164164
indexes: [
165-
{ fields: ['account'], unique: false },
166-
{ fields: ['status'], unique: false },
167-
{ fields: ['start_date'], unique: false },
168-
{ fields: ['end_date'], unique: false },
169-
{ fields: ['owner'], unique: false },
165+
{ fields: ['account'], type: 'btree' },
166+
{ fields: ['status'], type: 'btree' },
167+
{ fields: ['start_date'], type: 'btree' },
168+
{ fields: ['end_date'], type: 'btree' },
169+
{ fields: ['owner'], type: 'btree' },
170170
],
171171

172172
// Enable advanced features

examples/app-crm/src/objects/lead.object.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ export const Lead = ObjectSchema.create({
1212

1313
fields: {
1414
// Personal Information
15-
salutation: Field.select(['Mr.', 'Ms.', 'Mrs.', 'Dr.'], {
15+
salutation: Field.select({
1616
label: 'Salutation',
17+
options: [
18+
{ label: 'Mr.', value: 'mr' },
19+
{ label: 'Ms.', value: 'ms' },
20+
{ label: 'Mrs.', value: 'mrs' },
21+
{ label: 'Dr.', value: 'dr' },
22+
]
1723
}),
1824

1925
first_name: Field.text({
@@ -44,8 +50,16 @@ export const Lead = ObjectSchema.create({
4450
label: 'Job Title',
4551
}),
4652

47-
industry: Field.select(['Technology', 'Finance', 'Healthcare', 'Retail', 'Manufacturing', 'Education'], {
53+
industry: Field.select({
4854
label: 'Industry',
55+
options: [
56+
{ label: 'Technology', value: 'technology' },
57+
{ label: 'Finance', value: 'finance' },
58+
{ label: 'Healthcare', value: 'healthcare' },
59+
{ label: 'Retail', value: 'retail' },
60+
{ label: 'Manufacturing', value: 'manufacturing' },
61+
{ label: 'Education', value: 'education' },
62+
]
4963
}),
5064

5165
// Contact Information
@@ -88,8 +102,16 @@ export const Lead = ObjectSchema.create({
88102
allowHalf: true,
89103
}),
90104

91-
lead_source: Field.select(['Web', 'Referral', 'Event', 'Partner', 'Advertisement', 'Cold Call'], {
105+
lead_source: Field.select({
92106
label: 'Lead Source',
107+
options: [
108+
{ label: 'Web', value: 'web' },
109+
{ label: 'Referral', value: 'referral' },
110+
{ label: 'Event', value: 'event' },
111+
{ label: 'Partner', value: 'partner' },
112+
{ label: 'Advertisement', value: 'advertisement' },
113+
{ label: 'Cold Call', value: 'cold_call' },
114+
]
93115
}),
94116

95117
// Assignment
@@ -173,10 +195,10 @@ export const Lead = ObjectSchema.create({
173195

174196
// Database indexes for performance
175197
indexes: [
176-
{ fields: ['email'], unique: true },
177-
{ fields: ['owner'], unique: false },
178-
{ fields: ['status'], unique: false },
179-
{ fields: ['company'], unique: false },
198+
{ fields: ['email'], type: 'btree', unique: true },
199+
{ fields: ['owner'], type: 'btree' },
200+
{ fields: ['status'], type: 'btree' },
201+
{ fields: ['company'], type: 'btree' },
180202
],
181203

182204
enable: {

examples/app-crm/src/objects/opportunity.object.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { ObjectSchema, Field } from '@objectstack/spec/data';
4+
import { OpportunityStateMachine } from './opportunity.state';
45

56
export const Opportunity = ObjectSchema.create({
67
name: 'opportunity',
@@ -83,18 +84,37 @@ export const Opportunity = ObjectSchema.create({
8384
}),
8485

8586
// Additional Classification
86-
type: Field.select(['New Business', 'Existing Customer - Upgrade', 'Existing Customer - Renewal', 'Existing Customer - Expansion'], {
87+
type: Field.select({
8788
label: 'Opportunity Type',
89+
options: [
90+
{ label: 'New Business', value: 'new_business' },
91+
{ label: 'Existing Customer - Upgrade', value: 'existing_upgrade' },
92+
{ label: 'Existing Customer - Renewal', value: 'existing_renewal' },
93+
{ label: 'Existing Customer - Expansion', value: 'existing_expansion' },
94+
]
8895
}),
8996

90-
lead_source: Field.select(['Web', 'Referral', 'Event', 'Partner', 'Advertisement', 'Cold Call'], {
97+
lead_source: Field.select({
9198
label: 'Lead Source',
99+
options: [
100+
{ label: 'Web', value: 'web' },
101+
{ label: 'Referral', value: 'referral' },
102+
{ label: 'Event', value: 'event' },
103+
{ label: 'Partner', value: 'partner' },
104+
{ label: 'Advertisement', value: 'advertisement' },
105+
{ label: 'Cold Call', value: 'cold_call' },
106+
]
92107
}),
93108

94109
// Competitor Analysis
95-
competitors: Field.select(['Competitor A', 'Competitor B', 'Competitor C'], {
110+
competitors: Field.select({
96111
label: 'Competitors',
97112
multiple: true,
113+
options: [
114+
{ label: 'Competitor A', value: 'competitor_a' },
115+
{ label: 'Competitor B', value: 'competitor_b' },
116+
{ label: 'Competitor C', value: 'competitor_c' },
117+
]
98118
}),
99119

100120
// Campaign tracking
@@ -124,18 +144,25 @@ export const Opportunity = ObjectSchema.create({
124144
defaultValue: false,
125145
}),
126146

127-
forecast_category: Field.select(['Pipeline', 'Best Case', 'Commit', 'Omitted', 'Closed'], {
147+
forecast_category: Field.select({
128148
label: 'Forecast Category',
149+
options: [
150+
{ label: 'Pipeline', value: 'pipeline' },
151+
{ label: 'Best Case', value: 'best_case' },
152+
{ label: 'Commit', value: 'commit' },
153+
{ label: 'Omitted', value: 'omitted' },
154+
{ label: 'Closed', value: 'closed' },
155+
]
129156
}),
130157
},
131158

132159
// Database indexes for performance
133160
indexes: [
134-
{ fields: ['name'], unique: false },
135-
{ fields: ['account'], unique: false },
136-
{ fields: ['owner'], unique: false },
137-
{ fields: ['stage'], unique: false },
138-
{ fields: ['close_date'], unique: false },
161+
{ fields: ['name'], type: 'btree' },
162+
{ fields: ['account'], type: 'btree' },
163+
{ fields: ['owner'], type: 'btree' },
164+
{ fields: ['stage'], type: 'btree' },
165+
{ fields: ['close_date'], type: 'btree' },
139166
],
140167

141168
// Enable advanced features
@@ -153,6 +180,11 @@ export const Opportunity = ObjectSchema.create({
153180

154181
// Removed: list_views and form_views belong in UI configuration, not object definition
155182

183+
// Lifecycle State Machine(s)
184+
stateMachines: {
185+
lifecycle: OpportunityStateMachine,
186+
},
187+
156188
// Validation Rules
157189
validations: [
158190
{
@@ -169,22 +201,6 @@ export const Opportunity = ObjectSchema.create({
169201
message: 'Amount must be greater than zero',
170202
condition: 'amount <= 0',
171203
},
172-
{
173-
name: 'stage_progression',
174-
type: 'state_machine',
175-
severity: 'error',
176-
message: 'Invalid stage transition',
177-
field: 'stage',
178-
transitions: {
179-
'prospecting': ['qualification', 'closed_lost'],
180-
'qualification': ['needs_analysis', 'closed_lost'],
181-
'needs_analysis': ['proposal', 'closed_lost'],
182-
'proposal': ['negotiation', 'closed_lost'],
183-
'negotiation': ['closed_won', 'closed_lost'],
184-
'closed_won': [], // Terminal state
185-
'closed_lost': [] // Terminal state
186-
}
187-
},
188204
],
189205

190206
// Workflow Rules

0 commit comments

Comments
 (0)