zod-codegen 1.3.0 → 1.4.0

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +61 -9
  3. package/dist/scripts/update-manifest.d.ts +14 -0
  4. package/dist/scripts/update-manifest.d.ts.map +1 -0
  5. package/dist/src/cli.d.ts +3 -0
  6. package/dist/src/cli.d.ts.map +1 -0
  7. package/dist/src/cli.js +31 -2
  8. package/dist/src/generator.d.ts +23 -0
  9. package/dist/src/generator.d.ts.map +1 -0
  10. package/dist/src/generator.js +3 -2
  11. package/dist/src/http/fetch-client.d.ts +15 -0
  12. package/dist/src/http/fetch-client.d.ts.map +1 -0
  13. package/dist/src/interfaces/code-generator.d.ts +20 -0
  14. package/dist/src/interfaces/code-generator.d.ts.map +1 -0
  15. package/dist/src/interfaces/file-reader.d.ts +13 -0
  16. package/dist/src/interfaces/file-reader.d.ts.map +1 -0
  17. package/dist/src/polyfills/fetch.d.ts +5 -0
  18. package/dist/src/polyfills/fetch.d.ts.map +1 -0
  19. package/dist/src/services/code-generator.service.d.ts +57 -0
  20. package/dist/src/services/code-generator.service.d.ts.map +1 -0
  21. package/dist/src/services/code-generator.service.js +38 -1
  22. package/dist/src/services/file-reader.service.d.ts +9 -0
  23. package/dist/src/services/file-reader.service.d.ts.map +1 -0
  24. package/dist/src/services/file-writer.service.d.ts +10 -0
  25. package/dist/src/services/file-writer.service.d.ts.map +1 -0
  26. package/dist/src/services/import-builder.service.d.ts +14 -0
  27. package/dist/src/services/import-builder.service.d.ts.map +1 -0
  28. package/dist/src/services/type-builder.service.d.ts +12 -0
  29. package/dist/src/services/type-builder.service.d.ts.map +1 -0
  30. package/dist/src/types/generator-options.d.ts +59 -0
  31. package/dist/src/types/generator-options.d.ts.map +1 -0
  32. package/dist/src/types/generator-options.js +1 -0
  33. package/dist/src/types/http.d.ts +25 -0
  34. package/dist/src/types/http.d.ts.map +1 -0
  35. package/dist/src/types/openapi.d.ts +1120 -0
  36. package/dist/src/types/openapi.d.ts.map +1 -0
  37. package/dist/src/utils/error-handler.d.ts +3 -0
  38. package/dist/src/utils/error-handler.d.ts.map +1 -0
  39. package/dist/src/utils/error-handler.js +2 -2
  40. package/dist/src/utils/execution-time.d.ts +2 -0
  41. package/dist/src/utils/execution-time.d.ts.map +1 -0
  42. package/dist/src/utils/manifest.d.ts +8 -0
  43. package/dist/src/utils/manifest.d.ts.map +1 -0
  44. package/dist/src/utils/naming-convention.d.ts +80 -0
  45. package/dist/src/utils/naming-convention.d.ts.map +1 -0
  46. package/dist/src/utils/naming-convention.js +135 -0
  47. package/dist/src/utils/reporter.d.ts +7 -0
  48. package/dist/src/utils/reporter.d.ts.map +1 -0
  49. package/dist/src/utils/signal-handler.d.ts +3 -0
  50. package/dist/src/utils/signal-handler.d.ts.map +1 -0
  51. package/dist/src/utils/signal-handler.js +2 -2
  52. package/dist/src/utils/tty.d.ts +2 -0
  53. package/dist/src/utils/tty.d.ts.map +1 -0
  54. package/dist/tests/integration/cli.test.d.ts +2 -0
  55. package/dist/tests/integration/cli.test.d.ts.map +1 -0
  56. package/dist/tests/integration/cli.test.js +2 -2
  57. package/dist/tests/unit/code-generator.test.d.ts +2 -0
  58. package/dist/tests/unit/code-generator.test.d.ts.map +1 -0
  59. package/dist/tests/unit/code-generator.test.js +170 -1
  60. package/dist/tests/unit/file-reader.test.d.ts +2 -0
  61. package/dist/tests/unit/file-reader.test.d.ts.map +1 -0
  62. package/dist/tests/unit/generator.test.d.ts +2 -0
  63. package/dist/tests/unit/generator.test.d.ts.map +1 -0
  64. package/dist/tests/unit/naming-convention.test.d.ts +2 -0
  65. package/dist/tests/unit/naming-convention.test.d.ts.map +1 -0
  66. package/dist/tests/unit/naming-convention.test.js +231 -0
  67. package/dist/vitest.config.d.ts +3 -0
  68. package/dist/vitest.config.d.ts.map +1 -0
  69. package/package.json +10 -5
  70. package/src/cli.ts +34 -3
  71. package/src/generator.ts +8 -1
  72. package/src/services/code-generator.service.ts +47 -1
  73. package/src/types/generator-options.ts +60 -0
  74. package/src/utils/error-handler.ts +2 -2
  75. package/src/utils/naming-convention.ts +214 -0
  76. package/src/utils/signal-handler.ts +2 -2
  77. package/tests/integration/cli.test.ts +2 -2
  78. package/tests/unit/code-generator.test.ts +189 -1
  79. package/tests/unit/naming-convention.test.ts +263 -0
  80. package/tsconfig.json +2 -0
@@ -0,0 +1,263 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {transformNamingConvention, type NamingConvention} from '../../src/utils/naming-convention.js';
3
+
4
+ describe('transformNamingConvention', () => {
5
+ describe('transform', () => {
6
+ const testCases: Array<{
7
+ input: string;
8
+ convention: NamingConvention;
9
+ expected: string;
10
+ description: string;
11
+ }> = [
12
+ // camelCase
13
+ {
14
+ input: 'get_user_by_id',
15
+ convention: 'camelCase',
16
+ expected: 'getUserById',
17
+ description: 'should convert snake_case to camelCase',
18
+ },
19
+ {
20
+ input: 'GetUserById',
21
+ convention: 'camelCase',
22
+ expected: 'getUserById',
23
+ description: 'should convert PascalCase to camelCase',
24
+ },
25
+ {
26
+ input: 'get-user-by-id',
27
+ convention: 'camelCase',
28
+ expected: 'getUserById',
29
+ description: 'should convert kebab-case to camelCase',
30
+ },
31
+ {
32
+ input: 'getUserById',
33
+ convention: 'camelCase',
34
+ expected: 'getUserById',
35
+ description: 'should keep camelCase as camelCase',
36
+ },
37
+
38
+ // PascalCase
39
+ {
40
+ input: 'get_user_by_id',
41
+ convention: 'PascalCase',
42
+ expected: 'GetUserById',
43
+ description: 'should convert snake_case to PascalCase',
44
+ },
45
+ {
46
+ input: 'get-user-by-id',
47
+ convention: 'PascalCase',
48
+ expected: 'GetUserById',
49
+ description: 'should convert kebab-case to PascalCase',
50
+ },
51
+ {
52
+ input: 'getUserById',
53
+ convention: 'PascalCase',
54
+ expected: 'GetUserById',
55
+ description: 'should convert camelCase to PascalCase',
56
+ },
57
+
58
+ // snake_case
59
+ {
60
+ input: 'getUserById',
61
+ convention: 'snake_case',
62
+ expected: 'get_user_by_id',
63
+ description: 'should convert camelCase to snake_case',
64
+ },
65
+ {
66
+ input: 'GetUserById',
67
+ convention: 'snake_case',
68
+ expected: 'get_user_by_id',
69
+ description: 'should convert PascalCase to snake_case',
70
+ },
71
+ {
72
+ input: 'get-user-by-id',
73
+ convention: 'snake_case',
74
+ expected: 'get_user_by_id',
75
+ description: 'should convert kebab-case to snake_case',
76
+ },
77
+
78
+ // kebab-case
79
+ {
80
+ input: 'getUserById',
81
+ convention: 'kebab-case',
82
+ expected: 'get-user-by-id',
83
+ description: 'should convert camelCase to kebab-case',
84
+ },
85
+ {
86
+ input: 'GetUserById',
87
+ convention: 'kebab-case',
88
+ expected: 'get-user-by-id',
89
+ description: 'should convert PascalCase to kebab-case',
90
+ },
91
+ {
92
+ input: 'get_user_by_id',
93
+ convention: 'kebab-case',
94
+ expected: 'get-user-by-id',
95
+ description: 'should convert snake_case to kebab-case',
96
+ },
97
+
98
+ // SCREAMING_SNAKE_CASE
99
+ {
100
+ input: 'getUserById',
101
+ convention: 'SCREAMING_SNAKE_CASE',
102
+ expected: 'GET_USER_BY_ID',
103
+ description: 'should convert camelCase to SCREAMING_SNAKE_CASE',
104
+ },
105
+ {
106
+ input: 'get-user-by-id',
107
+ convention: 'SCREAMING_SNAKE_CASE',
108
+ expected: 'GET_USER_BY_ID',
109
+ description: 'should convert kebab-case to SCREAMING_SNAKE_CASE',
110
+ },
111
+
112
+ // SCREAMING-KEBAB-CASE
113
+ {
114
+ input: 'getUserById',
115
+ convention: 'SCREAMING-KEBAB-CASE',
116
+ expected: 'GET-USER-BY-ID',
117
+ description: 'should convert camelCase to SCREAMING-KEBAB-CASE',
118
+ },
119
+ {
120
+ input: 'get_user_by_id',
121
+ convention: 'SCREAMING-KEBAB-CASE',
122
+ expected: 'GET-USER-BY-ID',
123
+ description: 'should convert snake_case to SCREAMING-KEBAB-CASE',
124
+ },
125
+
126
+ // Edge cases
127
+ {
128
+ input: '',
129
+ convention: 'camelCase',
130
+ expected: '',
131
+ description: 'should handle empty string',
132
+ },
133
+ {
134
+ input: 'a',
135
+ convention: 'camelCase',
136
+ expected: 'a',
137
+ description: 'should handle single character',
138
+ },
139
+ {
140
+ input: 'API',
141
+ convention: 'camelCase',
142
+ expected: 'aPI',
143
+ description: 'should handle all uppercase (splits at uppercase boundaries)',
144
+ },
145
+ {
146
+ input: 'getUser123ById',
147
+ convention: 'snake_case',
148
+ expected: 'get_user_123_by_id',
149
+ description: 'should handle numbers in identifiers (splits at digit boundaries)',
150
+ },
151
+ ];
152
+
153
+ testCases.forEach(({input, convention, expected, description}) => {
154
+ it(description, () => {
155
+ const result = transformNamingConvention(input, convention);
156
+ expect(result).toBe(expected);
157
+ });
158
+ });
159
+ });
160
+
161
+ describe('edge cases', () => {
162
+ describe('consecutive delimiters', () => {
163
+ it('should handle consecutive underscores', () => {
164
+ expect(transformNamingConvention('get__user__by__id', 'camelCase')).toBe('getUserById');
165
+ });
166
+
167
+ it('should handle consecutive hyphens', () => {
168
+ expect(transformNamingConvention('get--user--by--id', 'snake_case')).toBe('get_user_by_id');
169
+ });
170
+
171
+ it('should handle mixed consecutive delimiters', () => {
172
+ expect(transformNamingConvention('get__user--by_id', 'kebab-case')).toBe('get-user-by-id');
173
+ });
174
+ });
175
+
176
+ describe('mixed delimiters', () => {
177
+ it('should handle snake_case and kebab-case mixed', () => {
178
+ // Note: Delimiters split the string, so 'byId' becomes 'by' and 'id' (normalized to lowercase)
179
+ expect(transformNamingConvention('get_user-byId', 'camelCase')).toBe('getUserByid');
180
+ });
181
+
182
+ it('should handle camelCase with underscores', () => {
183
+ // Note: Underscore delimiter splits, so 'byId' becomes 'by' and 'id'
184
+ expect(transformNamingConvention('getUser_byId', 'PascalCase')).toBe('GetuserByid');
185
+ });
186
+
187
+ it('should handle dots as delimiters', () => {
188
+ expect(transformNamingConvention('get.user.by.id', 'snake_case')).toBe('get_user_by_id');
189
+ });
190
+
191
+ it('should handle spaces as delimiters', () => {
192
+ expect(transformNamingConvention('get user by id', 'kebab-case')).toBe('get-user-by-id');
193
+ });
194
+ });
195
+
196
+ describe('unicode and special characters', () => {
197
+ it('should handle accented characters', () => {
198
+ expect(transformNamingConvention('getRésumé', 'snake_case')).toBe('get_résumé');
199
+ });
200
+
201
+ it('should handle numbers at start', () => {
202
+ expect(transformNamingConvention('123getUser', 'camelCase')).toBe('123getUser');
203
+ });
204
+
205
+ it('should handle single uppercase letter', () => {
206
+ expect(transformNamingConvention('getX', 'snake_case')).toBe('get_x');
207
+ });
208
+
209
+ it('should handle all numbers', () => {
210
+ expect(transformNamingConvention('123456', 'camelCase')).toBe('123456');
211
+ });
212
+ });
213
+
214
+ describe('acronyms and abbreviations', () => {
215
+ it('should handle acronyms in camelCase (splits on uppercase boundaries)', () => {
216
+ // Note: Algorithm splits on uppercase boundaries, so 'XML' becomes 'X', 'M', 'L'
217
+ // This is correct behavior - detecting acronyms would require a dictionary
218
+ expect(transformNamingConvention('getXMLData', 'snake_case')).toBe('get_x_m_l_data');
219
+ });
220
+
221
+ it('should handle multiple acronyms (splits on uppercase boundaries)', () => {
222
+ // Note: 'JSON' and 'XML' are split into individual letters
223
+ // 'parseJSONToXML' → ['parse', 'j', 's', 'o', 'n', 'to', 'x', 'm', 'l']
224
+ expect(transformNamingConvention('parseJSONToXML', 'kebab-case')).toBe('parse-j-s-o-n-to-x-m-l');
225
+ });
226
+
227
+ it('should handle ID abbreviation (splits on uppercase boundaries)', () => {
228
+ // Note: 'ID' is split into 'I' and 'D' because the algorithm splits on uppercase boundaries
229
+ // This is correct behavior - detecting acronyms would require a dictionary
230
+ expect(transformNamingConvention('getUserID', 'snake_case')).toBe('get_user_i_d');
231
+ });
232
+ });
233
+
234
+ describe('already transformed names', () => {
235
+ it('should be idempotent for camelCase', () => {
236
+ const input = 'getUserById';
237
+ const result = transformNamingConvention(input, 'camelCase');
238
+ expect(transformNamingConvention(result, 'camelCase')).toBe(result);
239
+ });
240
+
241
+ it('should be idempotent for snake_case', () => {
242
+ const input = 'get_user_by_id';
243
+ const result = transformNamingConvention(input, 'snake_case');
244
+ expect(transformNamingConvention(result, 'snake_case')).toBe(result);
245
+ });
246
+ });
247
+
248
+ describe('special patterns', () => {
249
+ it('should handle single word', () => {
250
+ expect(transformNamingConvention('user', 'PascalCase')).toBe('User');
251
+ });
252
+
253
+ it('should handle two words', () => {
254
+ expect(transformNamingConvention('getUser', 'snake_case')).toBe('get_user');
255
+ });
256
+
257
+ it('should handle very long names', () => {
258
+ const longName = 'getVeryLongOperationNameWithManyWords';
259
+ expect(transformNamingConvention(longName, 'kebab-case')).toBe('get-very-long-operation-name-with-many-words');
260
+ });
261
+ });
262
+ });
263
+ });
package/tsconfig.json CHANGED
@@ -13,6 +13,8 @@
13
13
  "lib": ["ES2022", "DOM"],
14
14
  "module": "ESNext",
15
15
  "moduleResolution": "Bundler",
16
+ "declaration": true,
17
+ "declarationMap": true,
16
18
  "noEmit": false,
17
19
  "noFallthroughCasesInSwitch": true,
18
20
  "noImplicitAny": true,