Skip to content

Commit b072842

Browse files
Copilothuangyiirene
andcommitted
Fix TypeScript build errors in CRM example
- Add phone field type helper to Field factory - Update Field.select/multiselect to support both array and object signatures - Add factory methods (Action.create, Dashboard.create, Report.create) - Use z.input and parse for factory methods to support default values Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent e5d98bf commit b072842

9 files changed

Lines changed: 67 additions & 12 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"title": "AI Protocol"
2+
"title": "AI Protocol",
3+
"root": true
34
}

content/docs/references/data/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"title": "Data Protocol",
3+
"root": true,
34
"pages": [
45
"core",
56
"logic",

content/docs/references/meta.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"label": "Protocol Reference",
3-
"root": true,
43
"order": 100,
54
"pages": [
65
"data",

content/docs/references/system/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"title": "System Protocol",
3+
"root": true,
34
"pages": [
45
"identity",
56
"integration",

content/docs/references/ui/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"title": "UI Protocol",
3+
"root": true,
34
"pages": [
45
"app",
56
"views",

packages/spec/src/data/field.zod.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const Field = {
111111
percent: (config: FieldInput = {}) => ({ type: 'percent', ...config } as const),
112112
url: (config: FieldInput = {}) => ({ type: 'url', ...config } as const),
113113
email: (config: FieldInput = {}) => ({ type: 'email', ...config } as const),
114+
phone: (config: FieldInput = {}) => ({ type: 'phone', ...config } as const),
114115
image: (config: FieldInput = {}) => ({ type: 'image', ...config } as const),
115116
file: (config: FieldInput = {}) => ({ type: 'file', ...config } as const),
116117
avatar: (config: FieldInput = {}) => ({ type: 'avatar', ...config } as const),
@@ -121,17 +122,43 @@ export const Field = {
121122
html: (config: FieldInput = {}) => ({ type: 'html', ...config } as const),
122123
password: (config: FieldInput = {}) => ({ type: 'password', ...config } as const),
123124

124-
select: (options: string[], config: FieldInput = {}) => ({
125-
type: 'select',
126-
options: options.map(o => ({ label: o, value: o })),
127-
...config
128-
} as const),
125+
select: (optionsOrConfig: SelectOption[] | string[] | FieldInput & { options: SelectOption[] | string[] }, config?: FieldInput) => {
126+
// Support both old and new signatures:
127+
// Old: Field.select(['a', 'b'], { label: 'X' })
128+
// New: Field.select({ options: [{label: 'A', value: 'a'}], label: 'X' })
129+
let options: SelectOption[];
130+
let finalConfig: FieldInput;
131+
132+
if (Array.isArray(optionsOrConfig)) {
133+
// Old signature: array as first param
134+
options = optionsOrConfig.map(o => typeof o === 'string' ? { label: o, value: o } : o);
135+
finalConfig = config || {};
136+
} else {
137+
// New signature: config object with options
138+
options = (optionsOrConfig.options || []).map(o => typeof o === 'string' ? { label: o, value: o } : o);
139+
finalConfig = optionsOrConfig;
140+
}
141+
142+
return { type: 'select', ...finalConfig, options } as const;
143+
},
129144

130-
multiselect: (options: string[], config: FieldInput = {}) => ({
131-
type: 'multiselect',
132-
options: options.map(o => ({ label: o, value: o })),
133-
...config
134-
} as const),
145+
multiselect: (optionsOrConfig: SelectOption[] | string[] | FieldInput & { options: SelectOption[] | string[] }, config?: FieldInput) => {
146+
// Support both old and new signatures
147+
let options: SelectOption[];
148+
let finalConfig: FieldInput;
149+
150+
if (Array.isArray(optionsOrConfig)) {
151+
// Old signature: array as first param
152+
options = optionsOrConfig.map(o => typeof o === 'string' ? { label: o, value: o } : o);
153+
finalConfig = config || {};
154+
} else {
155+
// New signature: config object with options
156+
options = (optionsOrConfig.options || []).map(o => typeof o === 'string' ? { label: o, value: o } : o);
157+
finalConfig = optionsOrConfig;
158+
}
159+
160+
return { type: 'multiselect', ...finalConfig, options } as const;
161+
},
135162

136163
lookup: (reference: string, config: FieldInput = {}) => ({
137164
type: 'lookup',

packages/spec/src/ui/action.zod.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ export const ActionSchema = z.object({
5656
});
5757

5858
export type Action = z.infer<typeof ActionSchema>;
59+
export type ActionParam = z.infer<typeof ActionParamSchema>;
60+
61+
/**
62+
* Action Factory Helper
63+
*/
64+
export const Action = {
65+
create: (config: z.input<typeof ActionSchema>): Action => ActionSchema.parse(config),
66+
} as const;

packages/spec/src/ui/dashboard.zod.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ export const DashboardSchema = z.object({
7878

7979
export type Dashboard = z.infer<typeof DashboardSchema>;
8080
export type DashboardWidget = z.infer<typeof DashboardWidgetSchema>;
81+
82+
/**
83+
* Dashboard Factory Helper
84+
*/
85+
export const Dashboard = {
86+
create: (config: z.input<typeof DashboardSchema>): Dashboard => DashboardSchema.parse(config),
87+
} as const;

packages/spec/src/ui/report.zod.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,13 @@ export const ReportSchema = z.object({
7676
});
7777

7878
export type Report = z.infer<typeof ReportSchema>;
79+
export type ReportColumn = z.infer<typeof ReportColumnSchema>;
80+
export type ReportGrouping = z.infer<typeof ReportGroupingSchema>;
81+
export type ReportChart = z.infer<typeof ReportChartSchema>;
82+
83+
/**
84+
* Report Factory Helper
85+
*/
86+
export const Report = {
87+
create: (config: z.input<typeof ReportSchema>): Report => ReportSchema.parse(config),
88+
} as const;

0 commit comments

Comments
 (0)