@famgia/omnify-typescript 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@famgia/omnify-typescript",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "TypeScript type definitions generator for Omnify schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -47,7 +47,7 @@
47
47
  "directory": "packages/typescript-generator"
48
48
  },
49
49
  "dependencies": {
50
- "@famgia/omnify-types": "0.0.35"
50
+ "@famgia/omnify-types": "0.0.36"
51
51
  },
52
52
  "devDependencies": {
53
53
  "tsup": "^8.5.1",
@@ -11,8 +11,9 @@ This guide covers TypeScript-specific features and generated code patterns for O
11
11
 
12
12
  When you run \`npx omnify generate\`, the following TypeScript files are generated:
13
13
 
14
- - \`types/omnify-types.ts\` - All type definitions
15
- - \`types/enums.ts\` - Enum types and helpers
14
+ - \`base/*.ts\` - Base model interfaces
15
+ - \`enum/*.ts\` - Enum types with multi-locale labels
16
+ - \`rules/*.ts\` - Ant Design compatible validation rules
16
17
 
17
18
  ## Type Generation
18
19
 
@@ -66,16 +67,25 @@ export interface User {
66
67
  | \`EnumRef\` | Generated enum type |
67
68
  | \`Association\` | Related model type / array |
68
69
 
69
- ## Enum Generation
70
+ ## Enum Generation (Multi-locale)
70
71
 
71
72
  \`\`\`yaml
72
73
  # schemas/PostStatus.yaml
73
74
  name: PostStatus
74
75
  kind: enum
76
+ displayName:
77
+ ja: 投稿ステータス
78
+ en: Post Status
75
79
  values:
76
- draft: 下書き
77
- published: 公開済み
78
- archived: アーカイブ
80
+ draft:
81
+ ja: 下書き
82
+ en: Draft
83
+ published:
84
+ ja: 公開済み
85
+ en: Published
86
+ archived:
87
+ ja: アーカイブ
88
+ en: Archived
79
89
  \`\`\`
80
90
 
81
91
  Generated:
@@ -88,26 +98,136 @@ export const PostStatus = {
88
98
 
89
99
  export type PostStatus = typeof PostStatus[keyof typeof PostStatus];
90
100
 
101
+ // Multi-locale labels
102
+ export const PostStatusLabels: Record<PostStatus, Record<string, string>> = {
103
+ draft: { ja: '下書き', en: 'Draft' },
104
+ published: { ja: '公開済み', en: 'Published' },
105
+ archived: { ja: 'アーカイブ', en: 'Archived' },
106
+ };
107
+
108
+ // Get label for specific locale
109
+ export function getPostStatusLabel(value: PostStatus, locale: string = 'en'): string {
110
+ return PostStatusLabels[value]?.[locale] ?? PostStatusLabels[value]?.['en'] ?? value;
111
+ }
112
+
91
113
  // Helper functions
92
114
  export const PostStatusValues = Object.values(PostStatus);
93
- export const PostStatusKeys = Object.keys(PostStatus) as (keyof typeof PostStatus)[];
94
-
95
115
  export function isPostStatus(value: unknown): value is PostStatus {
96
116
  return PostStatusValues.includes(value as PostStatus);
97
117
  }
118
+ \`\`\`
119
+
120
+ ## Validation Rules (Ant Design)
121
+
122
+ Omnify generates Ant Design compatible validation rules with multi-locale messages.
123
+
124
+ \`\`\`yaml
125
+ # schemas/User.yaml
126
+ name: User
127
+ displayName:
128
+ ja: ユーザー
129
+ en: User
130
+ properties:
131
+ name:
132
+ type: String
133
+ displayName:
134
+ ja: 名前
135
+ en: Name
136
+ required: true
137
+ maxLength: 100
138
+ email:
139
+ type: String
140
+ displayName:
141
+ ja: メールアドレス
142
+ en: Email
143
+ required: true
144
+ \`\`\`
145
+
146
+ Generated (\`rules/User.rules.ts\`):
147
+ \`\`\`typescript
148
+ export const UserDisplayName: LocaleMap = {
149
+ ja: 'ユーザー',
150
+ en: 'User',
151
+ };
152
+
153
+ export const UserPropertyDisplayNames: Record<string, LocaleMap> = {
154
+ name: { ja: '名前', en: 'Name' },
155
+ email: { ja: 'メールアドレス', en: 'Email' },
156
+ };
98
157
 
99
- // Display names for UI
100
- export const PostStatusDisplayNames: Record<PostStatus, string> = {
101
- draft: '下書き',
102
- published: '公開済み',
103
- archived: 'アーカイブ',
158
+ export const UserRules: Record<string, ValidationRule[]> = {
159
+ name: [
160
+ { required: true, message: { ja: '名前は必須です', en: 'Name is required' } },
161
+ { max: 100, message: { ja: '名前は100文字以内で入力してください', en: 'Name must be at most 100 characters' } },
162
+ ],
163
+ email: [
164
+ { required: true, message: { ja: 'メールアドレスは必須です', en: 'Email is required' } },
165
+ ],
104
166
  };
105
167
 
106
- export function getPostStatusDisplayName(value: PostStatus): string {
107
- return PostStatusDisplayNames[value];
168
+ // Get rules for specific locale (for Ant Design Form)
169
+ export function getUserRules(locale: string): Record<string, Array<{ required?: boolean; max?: number; message: string }>> { ... }
170
+
171
+ // Get display names
172
+ export function getUserDisplayName(locale: string): string { ... }
173
+ export function getUserPropertyDisplayName(property: string, locale: string): string { ... }
174
+ \`\`\`
175
+
176
+ ### Using in Ant Design Form
177
+
178
+ \`\`\`tsx
179
+ import { Form, Input } from 'antd';
180
+ import { getUserRules, getUserPropertyDisplayName } from './types/model/rules/User.rules';
181
+
182
+ function UserForm({ locale = 'ja' }) {
183
+ const rules = getUserRules(locale);
184
+
185
+ return (
186
+ <Form>
187
+ <Form.Item
188
+ name="name"
189
+ label={getUserPropertyDisplayName('name', locale)}
190
+ rules={rules.name}
191
+ >
192
+ <Input />
193
+ </Form.Item>
194
+ <Form.Item
195
+ name="email"
196
+ label={getUserPropertyDisplayName('email', locale)}
197
+ rules={rules.email}
198
+ >
199
+ <Input />
200
+ </Form.Item>
201
+ </Form>
202
+ );
108
203
  }
109
204
  \`\`\`
110
205
 
206
+ ### Built-in Validation Templates
207
+
208
+ Omnify includes built-in validation message templates for 5 languages:
209
+ - Japanese (ja), English (en), Vietnamese (vi), Korean (ko), Chinese (zh)
210
+
211
+ You can customize templates in \`omnify.config.ts\`:
212
+ \`\`\`typescript
213
+ export default defineConfig({
214
+ output: {
215
+ typescript: {
216
+ validationTemplates: {
217
+ required: {
218
+ ja: '\${displayName}を入力してください',
219
+ en: '\${displayName} is required',
220
+ },
221
+ maxLength: {
222
+ ja: '\${displayName}は\${max}文字以内です',
223
+ en: '\${displayName} must be \${max} characters or less',
224
+ },
225
+ },
226
+ },
227
+ },
228
+ });
229
+ \`\`\`
230
+
111
231
  ## Association Types
112
232
 
113
233
  ### ManyToOne