@famgia/omnify-typescript 0.0.87 → 0.0.89

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.87",
3
+ "version": "0.0.89",
4
4
  "description": "TypeScript type definitions generator for Omnify schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -48,7 +48,7 @@
48
48
  "directory": "packages/typescript-generator"
49
49
  },
50
50
  "dependencies": {
51
- "@famgia/omnify-types": "0.0.97"
51
+ "@famgia/omnify-types": "0.0.99"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "zod": "^3.0.0"
@@ -70,6 +70,87 @@ export interface UserListParams { ... }
70
70
  export interface UserCreateInput { ... } // WRONG
71
71
  ```
72
72
 
73
+ ## ⚠️ Enum Usage Rules (CRITICAL)
74
+
75
+ **ALWAYS use generated Enums** - NEVER inline union types or type extractions!
76
+
77
+ ### ❌ BAD Patterns (FORBIDDEN)
78
+
79
+ ```typescript
80
+ // ❌ Complex type extraction - FORBIDDEN!
81
+ newFilter.approval_status = status as NonNullable<ListParams["filter"]>["approval_status"];
82
+
83
+ // ❌ Hardcoded union type - NOT DRY!
84
+ newFilter.approval_status = status as "pending" | "approved" | "rejected";
85
+
86
+ // ❌ Using string type - NO TYPE SAFETY!
87
+ const [status, setStatus] = useState<string>("");
88
+
89
+ // ❌ Hardcoded comparisons
90
+ if (status === "pending") { ... }
91
+ ```
92
+
93
+ ### ✅ GOOD Patterns (REQUIRED)
94
+
95
+ ```typescript
96
+ // ✅ Import Enum from generated file
97
+ import {
98
+ ApprovalStatus,
99
+ ApprovalStatusValues,
100
+ isApprovalStatus,
101
+ getApprovalStatusLabel
102
+ } from "@/omnify/enum/ApprovalStatus";
103
+
104
+ // ✅ Type assertions with Enum
105
+ newFilter.approval_status = status as ApprovalStatus;
106
+
107
+ // ✅ State with Enum type
108
+ const [status, setStatus] = useState<ApprovalStatus | "">("");
109
+ // OR with default value:
110
+ const [status, setStatus] = useState<ApprovalStatus>(ApprovalStatus.Pending);
111
+
112
+ // ✅ Enum comparisons
113
+ if (status === ApprovalStatus.Pending) { ... }
114
+
115
+ // ✅ Iterate with Values array
116
+ const options = ApprovalStatusValues.map(value => ({
117
+ value,
118
+ label: getApprovalStatusLabel(value, locale)
119
+ }));
120
+
121
+ // ✅ Type guard for validation
122
+ if (isApprovalStatus(unknownValue)) {
123
+ // unknownValue is ApprovalStatus here
124
+ }
125
+ ```
126
+
127
+ ### Generated Enum Files Structure
128
+
129
+ ```
130
+ @/omnify/enum/
131
+ ├── ApprovalStatus.ts
132
+ │ ├── ApprovalStatus (enum)
133
+ │ ├── ApprovalStatusValues (array of all values)
134
+ │ ├── isApprovalStatus() (type guard)
135
+ │ └── getApprovalStatusLabel() (i18n label)
136
+ ├── OrderStatus.ts
137
+ └── ...
138
+ ```
139
+
140
+ ### Select/Filter Options Pattern
141
+
142
+ ```typescript
143
+ import { ApprovalStatus, ApprovalStatusValues, getApprovalStatusLabel } from "@/omnify/enum/ApprovalStatus";
144
+
145
+ // ✅ Build options from Enum
146
+ const statusOptions = ApprovalStatusValues.map(value => ({
147
+ value,
148
+ label: getApprovalStatusLabel(value, locale)
149
+ }));
150
+
151
+ <Select options={statusOptions} />
152
+ ```
153
+
73
154
  ## Form Pattern (Omnify)
74
155
 
75
156
  > **Detailed Guide:** See `react-form.mdc` for complete form development guide.
@@ -82,7 +82,154 @@ export interface User extends UserBase {
82
82
 
83
83
  ---
84
84
 
85
- ## 2. Using Generated Types
85
+ ## 2. Enum Types (CRITICAL)
86
+
87
+ **Location**: `@/omnify/enum/` or `@/types/model/enum/`
88
+
89
+ **ALWAYS use generated Enums - NEVER inline union types!**
90
+
91
+ ### Generated Enum Structure
92
+
93
+ ```typescript
94
+ // @/omnify/enum/ApprovalStatus.ts (auto-generated)
95
+
96
+ // 1. Enum type
97
+ export enum ApprovalStatus {
98
+ Pending = "pending",
99
+ Approved = "approved",
100
+ Rejected = "rejected",
101
+ Cancelled = "cancelled",
102
+ }
103
+
104
+ // 2. Values array (for iteration)
105
+ export const ApprovalStatusValues = [
106
+ ApprovalStatus.Pending,
107
+ ApprovalStatus.Approved,
108
+ ApprovalStatus.Rejected,
109
+ ApprovalStatus.Cancelled,
110
+ ] as const;
111
+
112
+ // 3. Type guard
113
+ export function isApprovalStatus(value: unknown): value is ApprovalStatus {
114
+ return ApprovalStatusValues.includes(value as ApprovalStatus);
115
+ }
116
+
117
+ // 4. i18n label getter
118
+ export function getApprovalStatusLabel(value: ApprovalStatus, locale: string): string {
119
+ // Returns localized label
120
+ }
121
+ ```
122
+
123
+ ### ❌ FORBIDDEN Patterns
124
+
125
+ ```typescript
126
+ // ❌ Complex type extraction - FORBIDDEN!
127
+ const status = value as NonNullable<ListParams["filter"]>["status"];
128
+
129
+ // ❌ Hardcoded union type - NOT DRY!
130
+ const status: "pending" | "approved" | "rejected" = "pending";
131
+
132
+ // ❌ String type - NO TYPE SAFETY!
133
+ const [status, setStatus] = useState<string>("");
134
+
135
+ // ❌ Hardcoded string comparisons
136
+ if (status === "pending") { ... }
137
+ ```
138
+
139
+ ### ✅ REQUIRED Patterns
140
+
141
+ ```typescript
142
+ // ✅ Import from generated enum file
143
+ import {
144
+ ApprovalStatus,
145
+ ApprovalStatusValues,
146
+ isApprovalStatus,
147
+ getApprovalStatusLabel
148
+ } from "@/omnify/enum/ApprovalStatus";
149
+
150
+ // ✅ Type assertions
151
+ const status = unknownValue as ApprovalStatus;
152
+
153
+ // ✅ State with Enum
154
+ const [status, setStatus] = useState<ApprovalStatus | "">("");
155
+ const [status, setStatus] = useState<ApprovalStatus>(ApprovalStatus.Pending);
156
+
157
+ // ✅ Enum comparisons
158
+ if (status === ApprovalStatus.Pending) { ... }
159
+
160
+ // ✅ Iterate with Values array
161
+ const options = ApprovalStatusValues.map(value => ({
162
+ value,
163
+ label: getApprovalStatusLabel(value, locale)
164
+ }));
165
+
166
+ // ✅ Type guard
167
+ if (isApprovalStatus(value)) {
168
+ // value is ApprovalStatus
169
+ }
170
+ ```
171
+
172
+ ### Select/Filter Options Pattern
173
+
174
+ ```typescript
175
+ import {
176
+ ApprovalStatus,
177
+ ApprovalStatusValues,
178
+ getApprovalStatusLabel
179
+ } from "@/omnify/enum/ApprovalStatus";
180
+ import { useLocale } from "next-intl";
181
+
182
+ function StatusFilter() {
183
+ const locale = useLocale();
184
+
185
+ // ✅ Build options from generated enum
186
+ const statusOptions = ApprovalStatusValues.map(value => ({
187
+ value,
188
+ label: getApprovalStatusLabel(value, locale)
189
+ }));
190
+
191
+ // ✅ State with Enum type
192
+ const [status, setStatus] = useState<ApprovalStatus | "all">("all");
193
+
194
+ return (
195
+ <Select
196
+ value={status}
197
+ onChange={setStatus}
198
+ options={[
199
+ { value: "all", label: t("common.all") },
200
+ ...statusOptions
201
+ ]}
202
+ />
203
+ );
204
+ }
205
+ ```
206
+
207
+ ### Filter Params with Enum
208
+
209
+ ```typescript
210
+ import { ApprovalStatus } from "@/omnify/enum/ApprovalStatus";
211
+
212
+ interface AttendanceListParams {
213
+ filter?: {
214
+ approval_status?: ApprovalStatus; // ✅ Use Enum type
215
+ };
216
+ }
217
+
218
+ // ✅ Type assertion with Enum
219
+ const handleStatusChange = (value: string) => {
220
+ setFilters(prev => ({
221
+ ...prev,
222
+ filter: {
223
+ ...prev.filter,
224
+ approval_status: value as ApprovalStatus // ✅ Not inline union type!
225
+ }
226
+ }));
227
+ };
228
+ ```
229
+
230
+ ---
231
+
232
+ ## 3. Using Generated Types
86
233
 
87
234
  ### Create/Update Types
88
235