@next-vibe/checker 1.0.52 → 3.0.1

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 (430) hide show
  1. package/LICENSE +669 -5
  2. package/README.md +179 -200
  3. package/check.config.ts +85 -16
  4. package/generated/alias-map.ts +30 -0
  5. package/generated/endpoint.ts +75 -0
  6. package/{src/app/api/[locale]/system/check/oxlint/plugins/i18n/src/index.ts → oxlint-plugins/i18n.ts} +45 -9
  7. package/{src/app/api/[locale]/system/check/oxlint/plugins/jsx-capitalization/src/index.ts → oxlint-plugins/jsx-capitalization.ts} +84 -17
  8. package/{src/app/api/[locale]/system/check/oxlint/plugins/restricted-syntax/src/index.ts → oxlint-plugins/restricted-syntax.ts} +40 -14
  9. package/package.json +27 -131
  10. package/.dist/LICENSE +0 -674
  11. package/.dist/README.md +0 -257
  12. package/.dist/bin/vibe-runtime.js +0 -58166
  13. package/.dist/bin/vibe-runtime.js.map +0 -451
  14. package/.dist/oxlint-plugins/i18n.js +0 -381
  15. package/.dist/oxlint-plugins/jsx-capitalization.js +0 -436
  16. package/.dist/oxlint-plugins/restricted-syntax.js +0 -409
  17. package/src/app/api/[locale]/LICENSE +0 -674
  18. package/src/app/api/[locale]/i18n/de/index.ts +0 -15
  19. package/src/app/api/[locale]/i18n/en/index.ts +0 -14
  20. package/src/app/api/[locale]/i18n/pl/index.ts +0 -13
  21. package/src/app/api/[locale]/shared/i18n/de/index.ts +0 -85
  22. package/src/app/api/[locale]/shared/i18n/en/index.ts +0 -83
  23. package/src/app/api/[locale]/shared/i18n/pl/index.ts +0 -85
  24. package/src/app/api/[locale]/shared/stats-filtering.ts +0 -174
  25. package/src/app/api/[locale]/shared/types/common.schema.ts +0 -55
  26. package/src/app/api/[locale]/shared/types/response.schema.ts +0 -411
  27. package/src/app/api/[locale]/shared/types/stats-filtering.schema.ts +0 -315
  28. package/src/app/api/[locale]/shared/types/utils.ts +0 -187
  29. package/src/app/api/[locale]/shared/utils/base64.ts +0 -46
  30. package/src/app/api/[locale]/shared/utils/env-util.ts +0 -36
  31. package/src/app/api/[locale]/shared/utils/i18n/de/index.ts +0 -21
  32. package/src/app/api/[locale]/shared/utils/i18n/en/index.ts +0 -19
  33. package/src/app/api/[locale]/shared/utils/i18n/pl/index.ts +0 -21
  34. package/src/app/api/[locale]/shared/utils/index.ts +0 -11
  35. package/src/app/api/[locale]/shared/utils/object-path.ts +0 -41
  36. package/src/app/api/[locale]/shared/utils/object.test.ts +0 -82
  37. package/src/app/api/[locale]/shared/utils/object.ts +0 -73
  38. package/src/app/api/[locale]/shared/utils/parse-error.ts +0 -134
  39. package/src/app/api/[locale]/shared/utils/parse-json.ts +0 -62
  40. package/src/app/api/[locale]/shared/utils/time.ts +0 -46
  41. package/src/app/api/[locale]/shared/utils/validation.ts +0 -117
  42. package/src/app/api/[locale]/shared/utils/zod-required-fields.ts +0 -115
  43. package/src/app/api/[locale]/system/builder/definition.ts +0 -1750
  44. package/src/app/api/[locale]/system/builder/enum.ts +0 -78
  45. package/src/app/api/[locale]/system/builder/i18n/de/index.ts +0 -645
  46. package/src/app/api/[locale]/system/builder/i18n/en/index.ts +0 -653
  47. package/src/app/api/[locale]/system/builder/i18n/pl/index.ts +0 -643
  48. package/src/app/api/[locale]/system/builder/repository/build-executor.test.ts +0 -178
  49. package/src/app/api/[locale]/system/builder/repository/build-executor.ts +0 -538
  50. package/src/app/api/[locale]/system/builder/repository/bun-compiler.ts +0 -250
  51. package/src/app/api/[locale]/system/builder/repository/bundle-analyzer.ts +0 -170
  52. package/src/app/api/[locale]/system/builder/repository/config-loader.ts +0 -146
  53. package/src/app/api/[locale]/system/builder/repository/config-validator.ts +0 -97
  54. package/src/app/api/[locale]/system/builder/repository/constants.ts +0 -125
  55. package/src/app/api/[locale]/system/builder/repository/error-suggester.ts +0 -67
  56. package/src/app/api/[locale]/system/builder/repository/file-copier.ts +0 -90
  57. package/src/app/api/[locale]/system/builder/repository/folder-cleaner.ts +0 -75
  58. package/src/app/api/[locale]/system/builder/repository/index.ts +0 -2
  59. package/src/app/api/[locale]/system/builder/repository/npm-package-generator.ts +0 -143
  60. package/src/app/api/[locale]/system/builder/repository/output-formatter.ts +0 -104
  61. package/src/app/api/[locale]/system/builder/repository/profile-service.ts +0 -79
  62. package/src/app/api/[locale]/system/builder/repository/report-generator.ts +0 -109
  63. package/src/app/api/[locale]/system/builder/repository/vite-compiler.ts +0 -277
  64. package/src/app/api/[locale]/system/builder/route.ts +0 -21
  65. package/src/app/api/[locale]/system/builder/test-files/file1.ts +0 -2
  66. package/src/app/api/[locale]/system/builder/test-files/file2.tsx +0 -10
  67. package/src/app/api/[locale]/system/builder/test-files/file3.tsx +0 -16
  68. package/src/app/api/[locale]/system/builder/test-files/folderToCopy/fileInFolder.ts +0 -2
  69. package/src/app/api/[locale]/system/builder/test-files/test-config.ts +0 -38
  70. package/src/app/api/[locale]/system/builder/test-files/test-delete-config.ts +0 -8
  71. package/src/app/api/[locale]/system/builder/test-files/test-project/package.json +0 -24
  72. package/src/app/api/[locale]/system/builder/test-files/test-project/src/constants.ts +0 -6
  73. package/src/app/api/[locale]/system/builder/test-files/test-project/src/greet.ts +0 -18
  74. package/src/app/api/[locale]/system/builder/test-files/test-project/src/index.ts +0 -7
  75. package/src/app/api/[locale]/system/builder/test-files/test-project/src/utils/calculate.ts +0 -27
  76. package/src/app/api/[locale]/system/builder/test-files/test-project/tsconfig.json +0 -19
  77. package/src/app/api/[locale]/system/builder/test-files/test-project/tsconfig.tsbuildinfo +0 -1
  78. package/src/app/api/[locale]/system/builder/test-files/test3.css +0 -1
  79. package/src/app/api/[locale]/system/check/config/create/definition.ts +0 -266
  80. package/src/app/api/[locale]/system/check/config/create/i18n/de/index.ts +0 -151
  81. package/src/app/api/[locale]/system/check/config/create/i18n/en/index.ts +0 -146
  82. package/src/app/api/[locale]/system/check/config/create/i18n/pl/index.ts +0 -148
  83. package/src/app/api/[locale]/system/check/config/create/repository.ts +0 -269
  84. package/src/app/api/[locale]/system/check/config/create/route.ts +0 -21
  85. package/src/app/api/[locale]/system/check/config/repository.ts +0 -846
  86. package/src/app/api/[locale]/system/check/config/shared.ts +0 -364
  87. package/src/app/api/[locale]/system/check/config/types.ts +0 -610
  88. package/src/app/api/[locale]/system/check/config/utils.ts +0 -155
  89. package/src/app/api/[locale]/system/check/i18n/de/index.ts +0 -19
  90. package/src/app/api/[locale]/system/check/i18n/en/index.ts +0 -18
  91. package/src/app/api/[locale]/system/check/i18n/pl/index.ts +0 -19
  92. package/src/app/api/[locale]/system/check/lint/definition.ts +0 -383
  93. package/src/app/api/[locale]/system/check/lint/enum.ts +0 -34
  94. package/src/app/api/[locale]/system/check/lint/i18n/de/index.ts +0 -160
  95. package/src/app/api/[locale]/system/check/lint/i18n/en/index.ts +0 -158
  96. package/src/app/api/[locale]/system/check/lint/i18n/pl/index.ts +0 -160
  97. package/src/app/api/[locale]/system/check/lint/repository.ts +0 -844
  98. package/src/app/api/[locale]/system/check/lint/route.ts +0 -21
  99. package/src/app/api/[locale]/system/check/oxlint/README.md +0 -190
  100. package/src/app/api/[locale]/system/check/oxlint/definition.ts +0 -375
  101. package/src/app/api/[locale]/system/check/oxlint/enum.ts +0 -34
  102. package/src/app/api/[locale]/system/check/oxlint/i18n/de/index.ts +0 -166
  103. package/src/app/api/[locale]/system/check/oxlint/i18n/en/index.ts +0 -164
  104. package/src/app/api/[locale]/system/check/oxlint/i18n/pl/index.ts +0 -166
  105. package/src/app/api/[locale]/system/check/oxlint/plugins/jsx-capitalization/README.md +0 -269
  106. package/src/app/api/[locale]/system/check/oxlint/plugins/restricted-syntax/test.tsx +0 -74
  107. package/src/app/api/[locale]/system/check/oxlint/plugins/shared/config-loader.ts +0 -283
  108. package/src/app/api/[locale]/system/check/oxlint/repository.ts +0 -553
  109. package/src/app/api/[locale]/system/check/oxlint/route.ts +0 -21
  110. package/src/app/api/[locale]/system/check/oxlint/types.ts +0 -191
  111. package/src/app/api/[locale]/system/check/test-project/.vscode/settings.json +0 -48
  112. package/src/app/api/[locale]/system/check/test-project/bun.lock +0 -640
  113. package/src/app/api/[locale]/system/check/test-project/check.config.ts +0 -955
  114. package/src/app/api/[locale]/system/check/test-project/package.json +0 -17
  115. package/src/app/api/[locale]/system/check/test-project/src/constants.ts +0 -6
  116. package/src/app/api/[locale]/system/check/test-project/src/greet.ts +0 -18
  117. package/src/app/api/[locale]/system/check/test-project/src/test-issues/a11y-issues.tsx +0 -107
  118. package/src/app/api/[locale]/system/check/test-project/src/test-issues/eslint-issues.tsx +0 -37
  119. package/src/app/api/[locale]/system/check/test-project/src/test-issues/general-issues.ts +0 -135
  120. package/src/app/api/[locale]/system/check/test-project/src/test-issues/i18n-issues.tsx +0 -113
  121. package/src/app/api/[locale]/system/check/test-project/src/test-issues/jsx-capitalization-issues.tsx +0 -127
  122. package/src/app/api/[locale]/system/check/test-project/src/test-issues/nextjs-issues.tsx +0 -92
  123. package/src/app/api/[locale]/system/check/test-project/src/test-issues/promise-issues.ts +0 -73
  124. package/src/app/api/[locale]/system/check/test-project/src/test-issues/react-issues.tsx +0 -95
  125. package/src/app/api/[locale]/system/check/test-project/src/test-issues/restricted-syntax-issues.tsx +0 -61
  126. package/src/app/api/[locale]/system/check/test-project/src/test-issues/typescript-issues.ts +0 -78
  127. package/src/app/api/[locale]/system/check/test-project/src/utils/calculate.ts +0 -27
  128. package/src/app/api/[locale]/system/check/test-project/tsconfig.json +0 -22
  129. package/src/app/api/[locale]/system/check/test-project/tsconfig.tsbuildinfo +0 -1
  130. package/src/app/api/[locale]/system/check/typecheck/definition.ts +0 -328
  131. package/src/app/api/[locale]/system/check/typecheck/enum.ts +0 -34
  132. package/src/app/api/[locale]/system/check/typecheck/i18n/de/index.ts +0 -148
  133. package/src/app/api/[locale]/system/check/typecheck/i18n/en/index.ts +0 -145
  134. package/src/app/api/[locale]/system/check/typecheck/i18n/pl/index.ts +0 -148
  135. package/src/app/api/[locale]/system/check/typecheck/repository.ts +0 -863
  136. package/src/app/api/[locale]/system/check/typecheck/route.ts +0 -21
  137. package/src/app/api/[locale]/system/check/typecheck/utils.ts +0 -160
  138. package/src/app/api/[locale]/system/check/vibe-check/definition.ts +0 -448
  139. package/src/app/api/[locale]/system/check/vibe-check/enum.ts +0 -63
  140. package/src/app/api/[locale]/system/check/vibe-check/i18n/de/index.ts +0 -164
  141. package/src/app/api/[locale]/system/check/vibe-check/i18n/en/index.ts +0 -161
  142. package/src/app/api/[locale]/system/check/vibe-check/i18n/pl/index.ts +0 -163
  143. package/src/app/api/[locale]/system/check/vibe-check/repository.ts +0 -516
  144. package/src/app/api/[locale]/system/check/vibe-check/route.test.ts +0 -1010
  145. package/src/app/api/[locale]/system/check/vibe-check/route.ts +0 -21
  146. package/src/app/api/[locale]/system/generated/endpoint.ts +0 -274
  147. package/src/app/api/[locale]/system/generated/endpoints.ts +0 -138
  148. package/src/app/api/[locale]/system/generated/route-handlers.ts +0 -213
  149. package/src/app/api/[locale]/system/generators/endpoint/definition.ts +0 -167
  150. package/src/app/api/[locale]/system/generators/endpoint/i18n/de/index.ts +0 -48
  151. package/src/app/api/[locale]/system/generators/endpoint/i18n/en/index.ts +0 -48
  152. package/src/app/api/[locale]/system/generators/endpoint/i18n/pl/index.ts +0 -50
  153. package/src/app/api/[locale]/system/generators/endpoint/repository.ts +0 -286
  154. package/src/app/api/[locale]/system/generators/endpoint/route.ts +0 -18
  155. package/src/app/api/[locale]/system/generators/endpoints/definition.ts +0 -246
  156. package/src/app/api/[locale]/system/generators/endpoints/i18n/de/index.ts +0 -54
  157. package/src/app/api/[locale]/system/generators/endpoints/i18n/en/index.ts +0 -52
  158. package/src/app/api/[locale]/system/generators/endpoints/i18n/pl/index.ts +0 -54
  159. package/src/app/api/[locale]/system/generators/endpoints/options-repository.ts +0 -425
  160. package/src/app/api/[locale]/system/generators/endpoints/repository.ts +0 -368
  161. package/src/app/api/[locale]/system/generators/endpoints/route.ts +0 -17
  162. package/src/app/api/[locale]/system/generators/endpoints-index/definition.ts +0 -166
  163. package/src/app/api/[locale]/system/generators/endpoints-index/i18n/de/index.ts +0 -71
  164. package/src/app/api/[locale]/system/generators/endpoints-index/i18n/en/index.ts +0 -69
  165. package/src/app/api/[locale]/system/generators/endpoints-index/i18n/pl/index.ts +0 -71
  166. package/src/app/api/[locale]/system/generators/endpoints-index/repository.ts +0 -279
  167. package/src/app/api/[locale]/system/generators/endpoints-index/route.ts +0 -18
  168. package/src/app/api/[locale]/system/generators/generate-all/definition.ts +0 -327
  169. package/src/app/api/[locale]/system/generators/generate-all/i18n/de/index.ts +0 -96
  170. package/src/app/api/[locale]/system/generators/generate-all/i18n/en/index.ts +0 -94
  171. package/src/app/api/[locale]/system/generators/generate-all/i18n/pl/index.ts +0 -96
  172. package/src/app/api/[locale]/system/generators/generate-all/repository.ts +0 -240
  173. package/src/app/api/[locale]/system/generators/generate-all/route.ts +0 -19
  174. package/src/app/api/[locale]/system/generators/i18n/de/index.ts +0 -15
  175. package/src/app/api/[locale]/system/generators/i18n/en/index.ts +0 -14
  176. package/src/app/api/[locale]/system/generators/i18n/pl/index.ts +0 -15
  177. package/src/app/api/[locale]/system/generators/route-handlers/definition.ts +0 -178
  178. package/src/app/api/[locale]/system/generators/route-handlers/i18n/de/index.ts +0 -48
  179. package/src/app/api/[locale]/system/generators/route-handlers/i18n/en/index.ts +0 -48
  180. package/src/app/api/[locale]/system/generators/route-handlers/i18n/pl/index.ts +0 -50
  181. package/src/app/api/[locale]/system/generators/route-handlers/repository.ts +0 -267
  182. package/src/app/api/[locale]/system/generators/route-handlers/route.ts +0 -14
  183. package/src/app/api/[locale]/system/generators/shared/utils.ts +0 -215
  184. package/src/app/api/[locale]/system/help/definition.ts +0 -433
  185. package/src/app/api/[locale]/system/help/i18n/de/index.ts +0 -263
  186. package/src/app/api/[locale]/system/help/i18n/en/index.ts +0 -259
  187. package/src/app/api/[locale]/system/help/i18n/pl/index.ts +0 -262
  188. package/src/app/api/[locale]/system/help/interactive/definition.ts +0 -122
  189. package/src/app/api/[locale]/system/help/interactive/i18n/de/index.ts +0 -21
  190. package/src/app/api/[locale]/system/help/interactive/i18n/en/index.ts +0 -19
  191. package/src/app/api/[locale]/system/help/interactive/i18n/pl/index.ts +0 -21
  192. package/src/app/api/[locale]/system/help/interactive/repository.ts +0 -1131
  193. package/src/app/api/[locale]/system/help/interactive/route.ts +0 -43
  194. package/src/app/api/[locale]/system/help/list/definition.ts +0 -362
  195. package/src/app/api/[locale]/system/help/list/repository.ts +0 -99
  196. package/src/app/api/[locale]/system/help/list/route.ts +0 -21
  197. package/src/app/api/[locale]/system/help/repository.ts +0 -238
  198. package/src/app/api/[locale]/system/help/route.ts +0 -16
  199. package/src/app/api/[locale]/system/i18n/de/index.ts +0 -67
  200. package/src/app/api/[locale]/system/i18n/en/index.ts +0 -66
  201. package/src/app/api/[locale]/system/i18n/pl/index.ts +0 -67
  202. package/src/app/api/[locale]/system/release-tool/definition.ts +0 -2925
  203. package/src/app/api/[locale]/system/release-tool/i18n/de/index.ts +0 -782
  204. package/src/app/api/[locale]/system/release-tool/i18n/en/index.ts +0 -779
  205. package/src/app/api/[locale]/system/release-tool/i18n/pl/index.ts +0 -781
  206. package/src/app/api/[locale]/system/release-tool/repository/asset-zipper.ts +0 -122
  207. package/src/app/api/[locale]/system/release-tool/repository/changelog-generator.ts +0 -205
  208. package/src/app/api/[locale]/system/release-tool/repository/ci-detector.ts +0 -540
  209. package/src/app/api/[locale]/system/release-tool/repository/config.ts +0 -106
  210. package/src/app/api/[locale]/system/release-tool/repository/constants.ts +0 -406
  211. package/src/app/api/[locale]/system/release-tool/repository/dependency-manager.ts +0 -496
  212. package/src/app/api/[locale]/system/release-tool/repository/git-service.ts +0 -378
  213. package/src/app/api/[locale]/system/release-tool/repository/hook-runner.ts +0 -96
  214. package/src/app/api/[locale]/system/release-tool/repository/index.ts +0 -1
  215. package/src/app/api/[locale]/system/release-tool/repository/notification-service.ts +0 -575
  216. package/src/app/api/[locale]/system/release-tool/repository/package-service.ts +0 -150
  217. package/src/app/api/[locale]/system/release-tool/repository/publisher.ts +0 -241
  218. package/src/app/api/[locale]/system/release-tool/repository/quality-runner.ts +0 -413
  219. package/src/app/api/[locale]/system/release-tool/repository/release-creator.ts +0 -283
  220. package/src/app/api/[locale]/system/release-tool/repository/release-executor.ts +0 -1084
  221. package/src/app/api/[locale]/system/release-tool/repository/snyk-service.ts +0 -132
  222. package/src/app/api/[locale]/system/release-tool/repository/utils.ts +0 -603
  223. package/src/app/api/[locale]/system/release-tool/repository/validation.ts +0 -265
  224. package/src/app/api/[locale]/system/release-tool/repository/version-service.ts +0 -275
  225. package/src/app/api/[locale]/system/release-tool/route.ts +0 -21
  226. package/src/app/api/[locale]/system/unified-interface/README.md +0 -328
  227. package/src/app/api/[locale]/system/unified-interface/cli/README.md +0 -349
  228. package/src/app/api/[locale]/system/unified-interface/cli/auth/cli-handler.ts +0 -82
  229. package/src/app/api/[locale]/system/unified-interface/cli/auth/cli-user.ts +0 -120
  230. package/src/app/api/[locale]/system/unified-interface/cli/auth/session-file.ts +0 -244
  231. package/src/app/api/[locale]/system/unified-interface/cli/env.ts +0 -24
  232. package/src/app/api/[locale]/system/unified-interface/cli/i18n/de/index.ts +0 -159
  233. package/src/app/api/[locale]/system/unified-interface/cli/i18n/en/index.ts +0 -158
  234. package/src/app/api/[locale]/system/unified-interface/cli/i18n/pl/index.ts +0 -159
  235. package/src/app/api/[locale]/system/unified-interface/cli/runtime/debug.ts +0 -573
  236. package/src/app/api/[locale]/system/unified-interface/cli/runtime/entry-point.ts +0 -128
  237. package/src/app/api/[locale]/system/unified-interface/cli/runtime/environment.ts +0 -155
  238. package/src/app/api/[locale]/system/unified-interface/cli/runtime/execution-errors.ts +0 -423
  239. package/src/app/api/[locale]/system/unified-interface/cli/runtime/parsing.ts +0 -252
  240. package/src/app/api/[locale]/system/unified-interface/cli/runtime/route-executor.ts +0 -901
  241. package/src/app/api/[locale]/system/unified-interface/cli/setup/i18n/de/index.ts +0 -12
  242. package/src/app/api/[locale]/system/unified-interface/cli/setup/i18n/en/index.ts +0 -11
  243. package/src/app/api/[locale]/system/unified-interface/cli/setup/i18n/pl/index.ts +0 -12
  244. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/definition.ts +0 -235
  245. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/i18n/de/index.ts +0 -54
  246. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/i18n/en/index.ts +0 -52
  247. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/i18n/pl/index.ts +0 -54
  248. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/repository.ts +0 -444
  249. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/route.ts +0 -25
  250. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/definition.ts +0 -159
  251. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/i18n/de/index.ts +0 -61
  252. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/i18n/en/index.ts +0 -59
  253. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/i18n/pl/index.ts +0 -61
  254. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/repository.ts +0 -181
  255. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/route.ts +0 -22
  256. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/definition.ts +0 -164
  257. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/i18n/de/index.ts +0 -54
  258. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/i18n/en/index.ts +0 -52
  259. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/i18n/pl/index.ts +0 -54
  260. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/repository.ts +0 -195
  261. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/route.ts +0 -24
  262. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/definition.ts +0 -180
  263. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/i18n/de/index.ts +0 -54
  264. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/i18n/en/index.ts +0 -52
  265. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/i18n/pl/index.ts +0 -54
  266. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/repository.ts +0 -105
  267. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/route.ts +0 -22
  268. package/src/app/api/[locale]/system/unified-interface/cli/vibe-runtime.ts +0 -264
  269. package/src/app/api/[locale]/system/unified-interface/cli/widgets/core/base-renderer.ts +0 -246
  270. package/src/app/api/[locale]/system/unified-interface/cli/widgets/core/registry.ts +0 -305
  271. package/src/app/api/[locale]/system/unified-interface/cli/widgets/core/types.ts +0 -116
  272. package/src/app/api/[locale]/system/unified-interface/cli/widgets/i18n/de/index.ts +0 -67
  273. package/src/app/api/[locale]/system/unified-interface/cli/widgets/i18n/en/index.ts +0 -65
  274. package/src/app/api/[locale]/system/unified-interface/cli/widgets/i18n/pl/index.ts +0 -67
  275. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/accordion.ts +0 -70
  276. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/avatar.ts +0 -37
  277. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/badge.ts +0 -52
  278. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-output.ts +0 -285
  279. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-quality-files.ts +0 -71
  280. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-quality-list.ts +0 -281
  281. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-quality-summary.ts +0 -83
  282. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/container.ts +0 -175
  283. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-card.ts +0 -61
  284. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-cards.ts +0 -518
  285. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-list.ts +0 -75
  286. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-table.ts +0 -357
  287. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/editable-text.ts +0 -93
  288. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/empty-state.ts +0 -49
  289. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/errors.ts +0 -63
  290. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/grouped-list.ts +0 -667
  291. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/link-card.ts +0 -78
  292. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/link-list.ts +0 -99
  293. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/link.ts +0 -54
  294. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/loading.ts +0 -46
  295. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/markdown.ts +0 -123
  296. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/metric.ts +0 -269
  297. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/section.ts +0 -114
  298. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/stats-grid.ts +0 -138
  299. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/tabs.ts +0 -59
  300. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/text.ts +0 -76
  301. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/title.ts +0 -37
  302. package/src/app/api/[locale]/system/unified-interface/cli/widgets/renderers/response-renderer.ts +0 -403
  303. package/src/app/api/[locale]/system/unified-interface/cli/widgets/renderers/schema-handler.ts +0 -504
  304. package/src/app/api/[locale]/system/unified-interface/i18n/de/index.ts +0 -39
  305. package/src/app/api/[locale]/system/unified-interface/i18n/en/index.ts +0 -37
  306. package/src/app/api/[locale]/system/unified-interface/i18n/pl/index.ts +0 -39
  307. package/src/app/api/[locale]/system/unified-interface/mcp/README.md +0 -114
  308. package/src/app/api/[locale]/system/unified-interface/mcp/converter.ts +0 -136
  309. package/src/app/api/[locale]/system/unified-interface/mcp/i18n/de/index.ts +0 -180
  310. package/src/app/api/[locale]/system/unified-interface/mcp/i18n/en/index.ts +0 -178
  311. package/src/app/api/[locale]/system/unified-interface/mcp/i18n/pl/index.ts +0 -180
  312. package/src/app/api/[locale]/system/unified-interface/mcp/registry.ts +0 -305
  313. package/src/app/api/[locale]/system/unified-interface/mcp/serve/definition.ts +0 -124
  314. package/src/app/api/[locale]/system/unified-interface/mcp/serve/repository.ts +0 -44
  315. package/src/app/api/[locale]/system/unified-interface/mcp/serve/route.ts +0 -14
  316. package/src/app/api/[locale]/system/unified-interface/mcp/server/protocol-handler.ts +0 -291
  317. package/src/app/api/[locale]/system/unified-interface/mcp/server/server.ts +0 -155
  318. package/src/app/api/[locale]/system/unified-interface/mcp/server/stdio-transport.ts +0 -191
  319. package/src/app/api/[locale]/system/unified-interface/mcp/types.ts +0 -247
  320. package/src/app/api/[locale]/system/unified-interface/react/icons.tsx +0 -346
  321. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/create-form.ts +0 -1413
  322. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/create.ts +0 -525
  323. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/endpoint-to-metadata.ts +0 -52
  324. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/loader.ts +0 -144
  325. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definitions/registry.ts +0 -262
  326. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/permissions/registry.ts +0 -656
  327. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/executor.ts +0 -220
  328. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/handler.ts +0 -313
  329. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/multi.ts +0 -182
  330. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/request-validator.ts +0 -173
  331. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/single.ts +0 -58
  332. package/src/app/api/[locale]/system/unified-interface/shared/env/define-env-client.ts +0 -45
  333. package/src/app/api/[locale]/system/unified-interface/shared/env/define-env.ts +0 -43
  334. package/src/app/api/[locale]/system/unified-interface/shared/env/validation-logger.ts +0 -58
  335. package/src/app/api/[locale]/system/unified-interface/shared/field/enum.ts +0 -107
  336. package/src/app/api/[locale]/system/unified-interface/shared/field/specialized.ts +0 -336
  337. package/src/app/api/[locale]/system/unified-interface/shared/field/utils.test.ts +0 -385
  338. package/src/app/api/[locale]/system/unified-interface/shared/field/utils.ts +0 -1827
  339. package/src/app/api/[locale]/system/unified-interface/shared/field-config/endpoint-field-types.ts +0 -108
  340. package/src/app/api/[locale]/system/unified-interface/shared/field-config/field-config-types.ts +0 -288
  341. package/src/app/api/[locale]/system/unified-interface/shared/logger/colors.ts +0 -114
  342. package/src/app/api/[locale]/system/unified-interface/shared/logger/endpoint.ts +0 -155
  343. package/src/app/api/[locale]/system/unified-interface/shared/logger/file-logger.ts +0 -85
  344. package/src/app/api/[locale]/system/unified-interface/shared/logger/formatters.ts +0 -167
  345. package/src/app/api/[locale]/system/unified-interface/shared/server-only/auth/base-auth-handler.ts +0 -82
  346. package/src/app/api/[locale]/system/unified-interface/shared/server-only/auth/factory.ts +0 -34
  347. package/src/app/api/[locale]/system/unified-interface/shared/server-only/server-only.ts +0 -1
  348. package/src/app/api/[locale]/system/unified-interface/shared/types/actions.ts +0 -284
  349. package/src/app/api/[locale]/system/unified-interface/shared/types/endpoint.ts +0 -1101
  350. package/src/app/api/[locale]/system/unified-interface/shared/types/enums.ts +0 -383
  351. package/src/app/api/[locale]/system/unified-interface/shared/types/platform.ts +0 -34
  352. package/src/app/api/[locale]/system/unified-interface/shared/types/types.ts +0 -76
  353. package/src/app/api/[locale]/system/unified-interface/shared/types/ui-config.ts +0 -72
  354. package/src/app/api/[locale]/system/unified-interface/shared/utils/error-types.ts +0 -27
  355. package/src/app/api/[locale]/system/unified-interface/shared/utils/path.ts +0 -80
  356. package/src/app/api/[locale]/system/unified-interface/shared/utils/scanner.ts +0 -225
  357. package/src/app/api/[locale]/system/unified-interface/shared/widgets/actions.ts +0 -251
  358. package/src/app/api/[locale]/system/unified-interface/shared/widgets/configs.ts +0 -1060
  359. package/src/app/api/[locale]/system/unified-interface/shared/widgets/helpers.ts +0 -70
  360. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/accordion.ts +0 -75
  361. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/avatar.ts +0 -69
  362. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/badge.ts +0 -86
  363. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/code-output.ts +0 -283
  364. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/code-quality-list.ts +0 -190
  365. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/container.ts +0 -114
  366. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-card.ts +0 -71
  367. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-cards.ts +0 -228
  368. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-list.ts +0 -119
  369. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-table.ts +0 -367
  370. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/editable-text.ts +0 -81
  371. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/empty-state.ts +0 -71
  372. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/errors.ts +0 -79
  373. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/grouped-list.ts +0 -426
  374. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/index.ts +0 -38
  375. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/link-card.ts +0 -112
  376. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/link-list.ts +0 -110
  377. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/link.ts +0 -66
  378. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/loading.ts +0 -79
  379. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/markdown.ts +0 -159
  380. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/metric-card.ts +0 -225
  381. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/section.ts +0 -85
  382. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/stats-grid.ts +0 -63
  383. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/tabs.ts +0 -73
  384. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/text.ts +0 -96
  385. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/title.ts +0 -57
  386. package/src/app/api/[locale]/system/unified-interface/shared/widgets/types.ts +0 -236
  387. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/field-helpers.ts +0 -120
  388. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/formatting.ts +0 -414
  389. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/url.ts +0 -37
  390. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/widget-helpers.ts +0 -427
  391. package/src/app/api/[locale]/user/auth/i18n/de/index.ts +0 -204
  392. package/src/app/api/[locale]/user/auth/i18n/en/index.ts +0 -199
  393. package/src/app/api/[locale]/user/auth/i18n/pl/index.ts +0 -203
  394. package/src/app/api/[locale]/user/auth/types.ts +0 -45
  395. package/src/app/api/[locale]/user/enum.ts +0 -64
  396. package/src/app/api/[locale]/user/i18n/de/index.ts +0 -75
  397. package/src/app/api/[locale]/user/i18n/en/index.ts +0 -74
  398. package/src/app/api/[locale]/user/i18n/pl/index.ts +0 -75
  399. package/src/app/api/[locale]/user/types.ts +0 -111
  400. package/src/app/api/[locale]/user/user-roles/enum.ts +0 -103
  401. package/src/app/api/[locale]/user/user-roles/i18n/de/index.ts +0 -85
  402. package/src/app/api/[locale]/user/user-roles/i18n/en/index.ts +0 -83
  403. package/src/app/api/[locale]/user/user-roles/i18n/pl/index.ts +0 -85
  404. package/src/app/api/[locale]/user/user-roles/types.ts +0 -32
  405. package/src/app/api/i18n/de/index.ts +0 -6
  406. package/src/app/api/i18n/en/index.ts +0 -5
  407. package/src/app/api/i18n/pl/index.ts +0 -5
  408. package/src/app/i18n/de/index.ts +0 -18
  409. package/src/app/i18n/en/index.ts +0 -18
  410. package/src/app/i18n/pl/index.ts +0 -17
  411. package/src/config/constants.ts +0 -8
  412. package/src/config/debug.ts +0 -30
  413. package/src/config/env-client.ts +0 -57
  414. package/src/config/env.ts +0 -56
  415. package/src/config/i18n/de/index.ts +0 -3
  416. package/src/config/i18n/en/index.ts +0 -51
  417. package/src/config/i18n/pl/index.ts +0 -3
  418. package/src/i18n/core/config.ts +0 -225
  419. package/src/i18n/core/language-utils.ts +0 -226
  420. package/src/i18n/core/localization-utils.ts +0 -394
  421. package/src/i18n/core/scoped-translation.ts +0 -104
  422. package/src/i18n/core/shared-component.tsx +0 -28
  423. package/src/i18n/core/shared-translation-utils.ts +0 -97
  424. package/src/i18n/core/shared.ts +0 -44
  425. package/src/i18n/core/static-types.ts +0 -64
  426. package/src/i18n/core/translation-utils.ts +0 -186
  427. package/src/i18n/de/index.ts +0 -8
  428. package/src/i18n/en/index.ts +0 -7
  429. package/src/i18n/index.ts +0 -100
  430. package/src/i18n/pl/index.ts +0 -7
@@ -1,1827 +0,0 @@
1
- /**
2
- * Field Utilities
3
- *
4
- * Utility functions for creating and working with unified fields.
5
- * These utilities were moved from individual definition files for better organization.
6
- */
7
-
8
- import { z } from "zod";
9
-
10
- import type { TranslationKey } from "@/i18n/core/static-types";
11
-
12
- import type { EndpointLogger } from "../logger/endpoint";
13
- import type {
14
- ArrayField,
15
- ArrayOptionalField,
16
- FieldUsageConfig,
17
- InferSchemaFromField,
18
- ObjectField,
19
- ObjectOptionalField,
20
- ObjectUnionField,
21
- PrimitiveField,
22
- UnifiedField,
23
- WidgetField,
24
- } from "../types/endpoint";
25
- import type { CacheStrategy } from "../types/enums";
26
- import { FieldUsage } from "../types/enums";
27
- import type { WidgetConfig } from "../widgets/configs";
28
-
29
- // ============================================================================
30
- // TYPE GUARDS
31
- // ============================================================================
32
-
33
- /**
34
- * Type guard to check if a value is a Zod schema
35
- */
36
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Type guard: Must accept unknown to narrow any value to z.ZodTypeAny. This is the standard TypeScript pattern for type guards.
37
- function isZodSchema(value: unknown): value is z.ZodTypeAny {
38
- return typeof value === "object" && value !== null && "_def" in value;
39
- }
40
-
41
- // ============================================================================
42
- // SCHEMA DEFAULT VALUE EXTRACTION
43
- // ============================================================================
44
-
45
- interface ZodDefShape {
46
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Type guard for Zod internal structure requires unknown type
47
- _def: Record<string, unknown>;
48
- }
49
-
50
- /**
51
- * Type guard to check if a value is a Zod schema (has _def property)
52
- */
53
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Type guard parameter must accept unknown to narrow any value
54
- function hasZodDef(value: unknown): value is ZodDefShape {
55
- return typeof value === "object" && value !== null && "_def" in value;
56
- }
57
-
58
- /**
59
- * Safely get a property from an object if it exists
60
- */
61
- function getDefProperty<T>(
62
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Generic type parameter for flexible property extraction
63
- def: Record<string, unknown>,
64
- key: string,
65
- ): T | undefined {
66
- if (key in def) {
67
- return def[key] as T;
68
- }
69
- return undefined;
70
- }
71
-
72
- /**
73
- * Recursively extracts default values from a Zod schema.
74
- * This traverses the entire schema tree and builds an object with all default values.
75
- *
76
- * Key behavior for nested objects:
77
- * - If a nested object has ANY child with defaults, the object itself is included
78
- * - This ensures required nested objects get populated with their children's defaults
79
- *
80
- * Handles:
81
- * - ZodDefault: Extracts the default value
82
- * - ZodOptional: Recursively checks inner schema for defaults
83
- * - ZodObject: Recursively extracts defaults from all properties
84
- * - ZodEffects (refinements/transforms): Unwraps to inner schema
85
- * - ZodNullable: Recursively checks inner schema
86
- *
87
- * @param schema - The Zod schema to extract defaults from
88
- * @param logger - Optional logger for error reporting
89
- * @param path - Current path in schema (for debugging)
90
- * @param forFormInit - When true, returns empty values for primitives (empty string, 0, false, [])
91
- * to properly initialize form fields and avoid "expected X, received undefined" errors
92
- * @returns An object containing all extracted default values, or undefined if no defaults
93
- */
94
- export function extractSchemaDefaults<T>(
95
- schema: z.ZodTypeAny,
96
- logger?: EndpointLogger,
97
- path = "",
98
- forFormInit = false,
99
- ): T | Partial<T> | undefined {
100
- try {
101
- if (!hasZodDef(schema)) {
102
- return undefined;
103
- }
104
- const def = schema._def;
105
- const typeName = getDefProperty<string>(def, "typeName");
106
- // In Zod v4, typeName is undefined but def.type exists
107
- const defType = getDefProperty<string>(def, "type");
108
-
109
- // Handle ZodDefault - has a defaultValue (can be value or function depending on Zod version)
110
- if (schema instanceof z.ZodDefault) {
111
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Zod internal _def structure requires unknown type, no definition.ts type available
112
- const defaultValueOrFn = getDefProperty<unknown>(def, "defaultValue");
113
- // In Zod v4, defaultValue is the actual value; in older versions it may be a function
114
- const defaultValue =
115
- typeof defaultValueOrFn === "function"
116
- ? // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Zod callback pattern requires unknown return type
117
- (defaultValueOrFn as () => unknown)()
118
- : defaultValueOrFn;
119
-
120
- // If the inner type is an object, merge with extracted defaults from children
121
- const innerType = getDefProperty<z.ZodTypeAny>(def, "innerType");
122
- if (innerType && hasZodDef(innerType)) {
123
- const innerDefaults = extractSchemaDefaults<T>(
124
- innerType,
125
- logger,
126
- `${path}.inner`,
127
- forFormInit,
128
- );
129
- if (
130
- typeof defaultValue === "object" &&
131
- defaultValue !== null &&
132
- typeof innerDefaults === "object" &&
133
- innerDefaults !== null
134
- ) {
135
- return { ...innerDefaults, ...defaultValue } as Partial<T>;
136
- }
137
- }
138
- return defaultValue as Partial<T>;
139
- }
140
-
141
- // Handle ZodObject - recursively extract from all shape properties
142
- if (schema instanceof z.ZodObject) {
143
- const shapeFnOrObj = getDefProperty<
144
- (() => Record<string, z.ZodTypeAny>) | Record<string, z.ZodTypeAny>
145
- >(def, "shape");
146
- if (!shapeFnOrObj) {
147
- return {} as Partial<T>;
148
- }
149
- const shapeObj = typeof shapeFnOrObj === "function" ? shapeFnOrObj() : shapeFnOrObj;
150
- if (typeof shapeObj !== "object" || shapeObj === null) {
151
- return {} as Partial<T>;
152
- }
153
-
154
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Building dynamic object from Zod schema requires unknown values
155
- const result: Record<string, unknown> = {};
156
- for (const [key, fieldSchema] of Object.entries(shapeObj)) {
157
- if (hasZodDef(fieldSchema)) {
158
- const fieldDefaults = extractSchemaDefaults(
159
- fieldSchema,
160
- logger,
161
- `${path}.${key}`,
162
- forFormInit,
163
- );
164
- if (fieldDefaults !== undefined) {
165
- result[key] = fieldDefaults;
166
- }
167
- }
168
- }
169
- // Always return the result object for ZodObject (even if empty)
170
- return result as Partial<T>;
171
- }
172
-
173
- // Handle ZodOptional - check inner schema for defaults
174
- if (schema instanceof z.ZodOptional) {
175
- const innerType = getDefProperty<z.ZodTypeAny>(def, "innerType");
176
- if (innerType && hasZodDef(innerType)) {
177
- return extractSchemaDefaults<T>(innerType, logger, `${path}.optional`, forFormInit);
178
- }
179
- }
180
-
181
- // Handle ZodNullable - check inner schema for defaults
182
- if (schema instanceof z.ZodNullable) {
183
- const innerType = getDefProperty<z.ZodTypeAny>(def, "innerType");
184
- if (innerType && hasZodDef(innerType)) {
185
- return extractSchemaDefaults<T>(innerType, logger, `${path}.nullable`, forFormInit);
186
- }
187
- }
188
-
189
- // Handle ZodEffects (refinements, transforms)
190
- // In Zod v4, check typeName or use "effect" in traits
191
- const isZodEffects = typeName === "ZodEffects" || defType === "effect";
192
- if (isZodEffects) {
193
- const innerSchema = getDefProperty<z.ZodTypeAny>(def, "schema");
194
- if (innerSchema && hasZodDef(innerSchema)) {
195
- return extractSchemaDefaults<T>(innerSchema, logger, `${path}.effects`, forFormInit);
196
- }
197
- }
198
-
199
- // Handle ZodPipeline (Zod v4 uses this for transforms)
200
- // In Zod v4, check def.type === "pipe"
201
- const isZodPipeline = typeName === "ZodPipeline" || defType === "pipe";
202
- if (isZodPipeline) {
203
- const inSchema = getDefProperty<z.ZodTypeAny>(def, "in");
204
- if (inSchema && hasZodDef(inSchema)) {
205
- return extractSchemaDefaults<T>(inSchema, logger, `${path}.pipeline`, forFormInit);
206
- }
207
- }
208
-
209
- // Handle ZodLazy - evaluate and extract
210
- if (schema instanceof z.ZodLazy) {
211
- const getter = getDefProperty<() => z.ZodTypeAny>(def, "getter");
212
- if (typeof getter === "function") {
213
- const lazySchema = getter();
214
- if (hasZodDef(lazySchema)) {
215
- return extractSchemaDefaults<T>(lazySchema, logger, `${path}.lazy`, forFormInit);
216
- }
217
- }
218
- }
219
-
220
- // For form initialization, return appropriate empty defaults for primitives
221
- // This ensures form fields start with valid values instead of undefined,
222
- // which prevents "expected string, received undefined" validation errors
223
- if (forFormInit) {
224
- // Use both instanceof and def.type for Zod v4 compatibility
225
- // Note: Type assertions are necessary here because we're doing runtime schema introspection
226
- // and TypeScript can't verify at compile time that T matches the schema type
227
- if (schema instanceof z.ZodArray || typeName === "ZodArray" || defType === "array") {
228
- return [] as T;
229
- }
230
- if (schema instanceof z.ZodString || typeName === "ZodString" || defType === "string") {
231
- return "" as T;
232
- }
233
- if (schema instanceof z.ZodNumber || typeName === "ZodNumber" || defType === "number") {
234
- return 0 as T;
235
- }
236
- if (schema instanceof z.ZodBoolean || typeName === "ZodBoolean" || defType === "boolean") {
237
- return false as T;
238
- }
239
- }
240
-
241
- // For other types without defaults, return undefined
242
- return undefined;
243
- } catch (error) {
244
- if (logger) {
245
- logger.error("Error extracting schema defaults", {
246
- path,
247
- error: String(error),
248
- });
249
- }
250
- return undefined;
251
- }
252
- }
253
-
254
- // ============================================================================
255
- // FIELD BUILDER - New Pattern
256
- // ============================================================================
257
-
258
- /**
259
- * Field builder utility for creating unified fields with type-safe translation keys
260
- * This provides a clean API for both scoped and non-scoped routes
261
- *
262
- * @example
263
- * // In createEndpoint:
264
- * fields: (u) => u.objectField(
265
- * { type: WidgetType.CONTAINER, title: "form.label", ... },
266
- * { request: "data", response: true },
267
- * { name: u.requestDataField(...), email: u.requestDataField(...) }
268
- * )
269
- */
270
- export interface FieldBuilder<TKey extends string = TranslationKey> {
271
- // Primitive fields
272
- field<
273
- const TUIConfig extends WidgetConfig<TKey>,
274
- const TSchema extends z.ZodTypeAny,
275
- const TUsage extends FieldUsageConfig,
276
- >(
277
- schema: TSchema,
278
- usage: TUsage,
279
- ui: TUIConfig,
280
- cache?: CacheStrategy,
281
- ): PrimitiveField<TSchema, TUsage, TKey, TUIConfig>;
282
-
283
- requestResponseField<const TUIConfig extends WidgetConfig<TKey>, TSchema extends z.ZodTypeAny>(
284
- ui: TUIConfig,
285
- schema: TSchema,
286
- cache?: CacheStrategy,
287
- requestAsUrlParams?: boolean,
288
- ): PrimitiveField<
289
- TSchema,
290
- { request: "data" | "urlPathParams"; response: true },
291
- TKey,
292
- TUIConfig
293
- >;
294
-
295
- requestDataField<const TUIConfig extends WidgetConfig<TKey>, TSchema extends z.ZodTypeAny>(
296
- ui: TUIConfig,
297
- schema: TSchema,
298
- cache?: CacheStrategy,
299
- ): PrimitiveField<TSchema, { request: "data" }, TKey, TUIConfig>;
300
-
301
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
302
- requestDataRangeField<const TUIConfig extends WidgetConfig<TKey>, TEnum extends z.ZodEnum<any>>(
303
- ui: TUIConfig,
304
- enumSchema: TEnum,
305
- cache?: CacheStrategy,
306
- ): PrimitiveField<z.ZodTypeAny, { request: "data" }, TKey, TUIConfig>;
307
-
308
- requestUrlPathParamsField<
309
- const TUIConfig extends WidgetConfig<TKey>,
310
- TSchema extends z.ZodTypeAny,
311
- >(
312
- ui: TUIConfig,
313
- schema: TSchema,
314
- cache?: CacheStrategy,
315
- ): PrimitiveField<TSchema, { request: "urlPathParams"; response?: never }, TKey, TUIConfig>;
316
-
317
- responseField<TSchema extends z.ZodTypeAny, const TUIConfig extends WidgetConfig<TKey>>(
318
- ui: TUIConfig,
319
- schema: TSchema,
320
- cache?: CacheStrategy,
321
- ): PrimitiveField<TSchema, { response: true }, TKey, TUIConfig>;
322
-
323
- // Widget fields
324
- widgetField<TUsage extends FieldUsageConfig, const TUIConfig extends WidgetConfig<TKey>>(
325
- ui: TUIConfig,
326
- usage: TUsage,
327
- cache?: CacheStrategy,
328
- ): WidgetField<TUsage, TKey, TUIConfig>;
329
-
330
- // Object fields
331
- objectField<
332
- TChildren extends Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
333
- TUsage extends FieldUsageConfig,
334
- const TUIConfig extends WidgetConfig<TKey>,
335
- >(
336
- ui: TUIConfig,
337
- usage: TUsage,
338
- children: TChildren,
339
- cache?: CacheStrategy,
340
- ): ObjectField<TChildren, TUsage, TKey, TUIConfig>;
341
-
342
- objectOptionalField<C, U extends FieldUsageConfig, const TUIConfig extends WidgetConfig<TKey>>(
343
- ui: TUIConfig,
344
- usage: U,
345
- children: C,
346
- cache?: CacheStrategy,
347
- ): ObjectOptionalField<C, U, TKey, TUIConfig>;
348
-
349
- objectUnionField<
350
- TDiscriminator extends string,
351
- TVariants extends readonly [
352
- ObjectField<
353
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
354
- FieldUsageConfig,
355
- TKey,
356
- WidgetConfig<TKey>
357
- >,
358
- ...ObjectField<
359
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
360
- FieldUsageConfig,
361
- TKey,
362
- WidgetConfig<TKey>
363
- >[],
364
- ],
365
- TUsage extends FieldUsageConfig,
366
- const TUIConfig extends WidgetConfig<TKey>,
367
- >(
368
- ui: TUIConfig,
369
- usage: TUsage,
370
- discriminator: TDiscriminator,
371
- variants: TVariants,
372
- cache?: CacheStrategy,
373
- ): ObjectUnionField<TDiscriminator, TKey, TVariants, TUsage, TUIConfig>;
374
-
375
- // Array fields
376
- arrayField<Child, const TUIConfig extends WidgetConfig<TKey>>(
377
- usage: FieldUsageConfig,
378
- ui: TUIConfig,
379
- child: Child,
380
- cache?: CacheStrategy,
381
- ): ArrayField<Child, FieldUsageConfig, TKey, TUIConfig>;
382
-
383
- requestDataArrayField<Child, const TUIConfig extends WidgetConfig<TKey>>(
384
- ui: TUIConfig,
385
- child: Child,
386
- cache?: CacheStrategy,
387
- ): ArrayField<Child, { request: "data" }, TKey, TUIConfig>;
388
-
389
- responseArrayField<Child, const TUIConfig extends WidgetConfig<TKey>>(
390
- ui: TUIConfig,
391
- child: Child,
392
- cache?: CacheStrategy,
393
- ): ArrayField<Child, { response: true }, TKey, TUIConfig>;
394
-
395
- arrayOptionalField<Child, const TUIConfig extends WidgetConfig<TKey>>(
396
- usage: FieldUsageConfig,
397
- ui: TUIConfig,
398
- child: Child,
399
- cache?: CacheStrategy,
400
- ): ArrayOptionalField<Child, FieldUsageConfig, TKey, TUIConfig>;
401
-
402
- requestDataArrayOptionalField<Child, const TUIConfig extends WidgetConfig<TKey>>(
403
- ui: TUIConfig,
404
- child: Child,
405
- cache?: CacheStrategy,
406
- ): ArrayOptionalField<Child, { request: "data" }, TKey, TUIConfig>;
407
-
408
- responseArrayOptionalField<Child, const TUIConfig extends WidgetConfig<TKey>>(
409
- ui: TUIConfig,
410
- child: Child,
411
- cache?: CacheStrategy,
412
- ): ArrayOptionalField<Child, { response: true }, TKey, TUIConfig>;
413
- }
414
-
415
- /**
416
- * Create a FieldBuilder instance with proper type inference for translation keys
417
- * This is used internally by createEndpoint to provide the `u` parameter
418
- */
419
- export function createFieldBuilder<TKey extends string = TranslationKey>(): FieldBuilder<TKey> {
420
- return {
421
- field: <
422
- const TUIConfig extends WidgetConfig<TKey>,
423
- const TSchema extends z.ZodTypeAny,
424
- const TUsage extends FieldUsageConfig,
425
- >(
426
- schema: TSchema,
427
- usage: TUsage,
428
- ui: TUIConfig,
429
- cache?: CacheStrategy,
430
- ): PrimitiveField<TSchema, TUsage, TKey, TUIConfig> => ({
431
- type: "primitive" as const,
432
- schema,
433
- usage,
434
- ui,
435
- cache,
436
- }),
437
-
438
- requestResponseField: <
439
- const TUIConfig extends WidgetConfig<TKey>,
440
- TSchema extends z.ZodTypeAny,
441
- >(
442
- ui: TUIConfig,
443
- schema: TSchema,
444
- cache?: CacheStrategy,
445
- requestAsUrlParams?: boolean,
446
- ): PrimitiveField<
447
- TSchema,
448
- { request: "data" | "urlPathParams"; response: true },
449
- TKey,
450
- TUIConfig
451
- > => {
452
- const requestType = requestAsUrlParams ? "urlPathParams" : "data";
453
- return {
454
- type: "primitive" as const,
455
- schema,
456
- usage: { request: requestType, response: true },
457
- ui,
458
- cache,
459
- };
460
- },
461
-
462
- requestDataField: <const TUIConfig extends WidgetConfig<TKey>, TSchema extends z.ZodTypeAny>(
463
- ui: TUIConfig,
464
- schema: TSchema,
465
- cache?: CacheStrategy,
466
- ): PrimitiveField<TSchema, { request: "data" }, TKey, TUIConfig> => ({
467
- type: "primitive" as const,
468
- schema,
469
- usage: { request: "data" },
470
- ui,
471
- cache,
472
- }),
473
-
474
- requestDataRangeField: <
475
- const TUIConfig extends WidgetConfig<TKey>,
476
- TEnum extends z.ZodEnum<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
477
- >(
478
- ui: TUIConfig,
479
- enumSchema: TEnum,
480
- cache?: CacheStrategy,
481
- ): PrimitiveField<z.ZodTypeAny, { request: "data" }, TKey, TUIConfig> => {
482
- const rangeSchema = z
483
- .object({
484
- min: enumSchema.optional(),
485
- max: enumSchema.optional(),
486
- })
487
- .optional();
488
-
489
- return {
490
- type: "primitive" as const,
491
- schema: rangeSchema,
492
- usage: { request: "data" },
493
- ui,
494
- cache,
495
- };
496
- },
497
-
498
- requestUrlPathParamsField: <
499
- const TUIConfig extends WidgetConfig<TKey>,
500
- TSchema extends z.ZodTypeAny,
501
- >(
502
- ui: TUIConfig,
503
- schema: TSchema,
504
- cache?: CacheStrategy,
505
- ): PrimitiveField<
506
- TSchema,
507
- { request: "urlPathParams"; response?: never },
508
- TKey,
509
- TUIConfig
510
- > => ({
511
- type: "primitive" as const,
512
- schema,
513
- usage: { request: "urlPathParams" },
514
- ui,
515
- cache,
516
- }),
517
-
518
- responseField: <TSchema extends z.ZodTypeAny, const TUIConfig extends WidgetConfig<TKey>>(
519
- ui: TUIConfig,
520
- schema: TSchema,
521
- cache?: CacheStrategy,
522
- ): PrimitiveField<TSchema, { response: true }, TKey, TUIConfig> => ({
523
- type: "primitive" as const,
524
- schema,
525
- usage: { response: true },
526
- ui,
527
- cache,
528
- }),
529
-
530
- widgetField: <TUsage extends FieldUsageConfig, const TUIConfig extends WidgetConfig<TKey>>(
531
- ui: TUIConfig,
532
- usage: TUsage,
533
- cache?: CacheStrategy,
534
- ): WidgetField<TUsage, TKey, TUIConfig> => ({
535
- type: "widget" as const,
536
- usage,
537
- ui,
538
- cache,
539
- }),
540
-
541
- objectField: <
542
- TChildren extends Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
543
- TUsage extends FieldUsageConfig,
544
- const TUIConfig extends WidgetConfig<TKey>,
545
- >(
546
- ui: TUIConfig,
547
- usage: TUsage,
548
- children: TChildren,
549
- cache?: CacheStrategy,
550
- ): ObjectField<TChildren, TUsage, TKey, TUIConfig> => ({
551
- type: "object" as const,
552
- children,
553
- usage,
554
- ui,
555
- cache,
556
- }),
557
-
558
- objectOptionalField: <
559
- C,
560
- U extends FieldUsageConfig,
561
- const TUIConfig extends WidgetConfig<TKey>,
562
- >(
563
- ui: TUIConfig,
564
- usage: U,
565
- children: C,
566
- cache?: CacheStrategy,
567
- ): ObjectOptionalField<C, U, TKey, TUIConfig> => ({
568
- type: "object-optional" as const,
569
- children,
570
- usage,
571
- ui,
572
- cache,
573
- }),
574
-
575
- objectUnionField: <
576
- TDiscriminator extends string,
577
- TVariants extends readonly [
578
- ObjectField<
579
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
580
- FieldUsageConfig,
581
- TKey,
582
- WidgetConfig<TKey>
583
- >,
584
- ...ObjectField<
585
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
586
- FieldUsageConfig,
587
- TKey,
588
- WidgetConfig<TKey>
589
- >[],
590
- ],
591
- TUsage extends FieldUsageConfig,
592
- const TUIConfig extends WidgetConfig<TKey>,
593
- >(
594
- ui: TUIConfig,
595
- usage: TUsage,
596
- discriminator: TDiscriminator,
597
- variants: TVariants,
598
- cache?: CacheStrategy,
599
- ): ObjectUnionField<TDiscriminator, TKey, TVariants, TUsage, TUIConfig> => ({
600
- type: "object-union" as const,
601
- discriminator,
602
- variants,
603
- usage,
604
- ui,
605
- cache,
606
- }),
607
-
608
- arrayField: <Child, const TUIConfig extends WidgetConfig<TKey>>(
609
- usage: FieldUsageConfig,
610
- ui: TUIConfig,
611
- child: Child,
612
- cache?: CacheStrategy,
613
- ): ArrayField<Child, FieldUsageConfig, TKey, TUIConfig> => ({
614
- type: "array" as const,
615
- child,
616
- usage,
617
- ui,
618
- cache,
619
- }),
620
-
621
- requestDataArrayField: <Child, const TUIConfig extends WidgetConfig<TKey>>(
622
- ui: TUIConfig,
623
- child: Child,
624
- cache?: CacheStrategy,
625
- ): ArrayField<Child, { request: "data" }, TKey, TUIConfig> => ({
626
- type: "array" as const,
627
- child,
628
- usage: { request: "data" },
629
- ui,
630
- cache,
631
- }),
632
-
633
- responseArrayField: <Child, const TUIConfig extends WidgetConfig<TKey>>(
634
- ui: TUIConfig,
635
- child: Child,
636
- cache?: CacheStrategy,
637
- ): ArrayField<Child, { response: true }, TKey, TUIConfig> => ({
638
- type: "array" as const,
639
- child,
640
- usage: { response: true },
641
- ui,
642
- cache,
643
- }),
644
-
645
- arrayOptionalField: <Child, const TUIConfig extends WidgetConfig<TKey>>(
646
- usage: FieldUsageConfig,
647
- ui: TUIConfig,
648
- child: Child,
649
- cache?: CacheStrategy,
650
- ): ArrayOptionalField<Child, FieldUsageConfig, TKey, TUIConfig> => ({
651
- type: "array-optional" as const,
652
- child,
653
- usage,
654
- ui,
655
- cache,
656
- }),
657
-
658
- requestDataArrayOptionalField: <Child, const TUIConfig extends WidgetConfig<TKey>>(
659
- ui: TUIConfig,
660
- child: Child,
661
- cache?: CacheStrategy,
662
- ): ArrayOptionalField<Child, { request: "data" }, TKey, TUIConfig> => ({
663
- type: "array-optional" as const,
664
- child,
665
- usage: { request: "data" },
666
- ui,
667
- cache,
668
- }),
669
-
670
- responseArrayOptionalField: <Child, const TUIConfig extends WidgetConfig<TKey>>(
671
- ui: TUIConfig,
672
- child: Child,
673
- cache?: CacheStrategy,
674
- ): ArrayOptionalField<Child, { response: true }, TKey, TUIConfig> => ({
675
- type: "array-optional" as const,
676
- child,
677
- usage: { response: true },
678
- ui,
679
- cache,
680
- }),
681
- };
682
- }
683
-
684
- // ============================================================================
685
- // FIELD CREATORS - Legacy Pattern (Kept for backwards compatibility)
686
- // ============================================================================
687
-
688
- /**
689
- * Create a primitive field (string, number, boolean, etc.)
690
- */
691
- export function field<
692
- TKey extends string = TranslationKey,
693
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
694
- const TSchema extends z.ZodTypeAny = z.ZodTypeAny,
695
- const TUsage extends FieldUsageConfig = FieldUsageConfig,
696
- >(
697
- schema: TSchema,
698
- usage: TUsage,
699
- ui: TUIConfig,
700
- cache?: CacheStrategy,
701
- ): PrimitiveField<TSchema, TUsage, TKey, TUIConfig> {
702
- return {
703
- type: "primitive" as const,
704
- schema,
705
- usage,
706
- ui,
707
- cache,
708
- };
709
- }
710
-
711
- /**
712
- * Create a field that can be both request and response
713
- */
714
- export function requestResponseField<
715
- TKey extends string = TranslationKey,
716
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
717
- TSchema extends z.ZodTypeAny = z.ZodTypeAny,
718
- >(
719
- ui: TUIConfig,
720
- schema: TSchema,
721
- cache?: CacheStrategy,
722
- requestAsUrlParams?: false,
723
- ): PrimitiveField<TSchema, { request: "data"; response: true }, TKey, TUIConfig>;
724
- // eslint-disable-next-line no-redeclare
725
- export function requestResponseField<
726
- TKey extends string = TranslationKey,
727
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
728
- TSchema extends z.ZodTypeAny = z.ZodTypeAny,
729
- >(
730
- ui: TUIConfig,
731
- schema: TSchema,
732
- cache?: CacheStrategy,
733
- requestAsUrlParams?: true,
734
- ): PrimitiveField<TSchema, { request: "urlPathParams"; response: true }, TKey, TUIConfig>;
735
- // eslint-disable-next-line no-redeclare
736
- export function requestResponseField<
737
- TKey extends string = TranslationKey,
738
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
739
- TSchema extends z.ZodTypeAny = z.ZodTypeAny,
740
- >(
741
- ui: TUIConfig,
742
- schema: TSchema,
743
- cache?: CacheStrategy,
744
- requestAsUrlParams?: boolean,
745
- ): PrimitiveField<TSchema, { request: "data" | "urlPathParams"; response: true }, TKey, TUIConfig> {
746
- const requestType = requestAsUrlParams ? "urlPathParams" : "data";
747
- return {
748
- type: "primitive" as const,
749
- schema,
750
- usage: { request: requestType, response: true },
751
- ui,
752
- cache,
753
- };
754
- }
755
-
756
- /**
757
- * Create a request data field
758
- */
759
- export function requestDataField<
760
- TKey extends string = TranslationKey,
761
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
762
- TSchema extends z.ZodTypeAny = z.ZodTypeAny,
763
- >(
764
- ui: TUIConfig,
765
- schema: TSchema,
766
- cache?: CacheStrategy,
767
- ): PrimitiveField<TSchema, { request: "data" }, TKey, TUIConfig> {
768
- return {
769
- type: "primitive" as const,
770
- schema,
771
- usage: { request: "data" },
772
- ui,
773
- cache,
774
- };
775
- }
776
-
777
- /**
778
- * Create a request data range field (min/max)
779
- * Automatically wraps an enum schema in z.object({ min, max }) structure
780
- *
781
- * @example
782
- * requestDataRangeField(
783
- * {
784
- * type: WidgetType.FORM_FIELD,
785
- * fieldType: FieldDataType.RANGE_SLIDER,
786
- * label: "price.range.label",
787
- * options: PRICE_OPTIONS,
788
- * },
789
- * z.enum(PriceLevelDB),
790
- * )
791
- */
792
- export function requestDataRangeField<
793
- TKey extends string = TranslationKey,
794
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
795
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
796
- TEnum extends z.ZodEnum<any> = z.ZodEnum<any>,
797
- >(
798
- ui: TUIConfig,
799
- enumSchema: TEnum,
800
- cache?: CacheStrategy,
801
- ): PrimitiveField<
802
- z.ZodOptional<z.ZodObject<{ min: z.ZodOptional<TEnum>; max: z.ZodOptional<TEnum> }>>,
803
- { request: "data" },
804
- TKey,
805
- TUIConfig
806
- > {
807
- const rangeSchema = z
808
- .object({
809
- min: enumSchema.optional(),
810
- max: enumSchema.optional(),
811
- })
812
- .optional();
813
-
814
- return {
815
- type: "primitive" as const,
816
- schema: rangeSchema,
817
- usage: { request: "data" },
818
- ui,
819
- cache,
820
- };
821
- }
822
-
823
- /**
824
- * Create a request URL params field
825
- */
826
- export function requestUrlPathParamsField<
827
- TKey extends string = TranslationKey,
828
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
829
- TSchema extends z.ZodTypeAny = z.ZodTypeAny,
830
- >(
831
- ui: TUIConfig,
832
- schema: TSchema,
833
- cache?: CacheStrategy,
834
- ): PrimitiveField<TSchema, { request: "urlPathParams"; response?: never }, TKey, TUIConfig> {
835
- return {
836
- type: "primitive" as const,
837
- schema,
838
- usage: { request: "urlPathParams" },
839
- ui,
840
- cache,
841
- };
842
- }
843
-
844
- /**
845
- * Create a response field
846
- */
847
- export function responseField<
848
- TKey extends string = TranslationKey,
849
- TSchema extends z.ZodTypeAny = z.ZodTypeAny,
850
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
851
- >(
852
- ui: TUIConfig,
853
- schema: TSchema,
854
- cache?: CacheStrategy,
855
- ): PrimitiveField<TSchema, { response: true }, TKey, TUIConfig> {
856
- return {
857
- type: "primitive" as const,
858
- schema,
859
- usage: { response: true },
860
- ui,
861
- cache,
862
- };
863
- }
864
-
865
- /**
866
- * Create a widget-only field (buttons, alerts, static content)
867
- */
868
- export function widgetField<
869
- TKey extends string = TranslationKey,
870
- TUsage extends FieldUsageConfig = FieldUsageConfig,
871
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
872
- >(ui: TUIConfig, usage: TUsage, cache?: CacheStrategy): WidgetField<TUsage, TKey, TUIConfig> {
873
- return {
874
- type: "widget" as const,
875
- usage,
876
- ui,
877
- cache,
878
- };
879
- }
880
-
881
- /**
882
- * Create an object field containing other fields
883
- *
884
- * Uses TranslationKey by default for automatic validation.
885
- * For scoped translations, use scopedObjectField<ScopedKeyType> instead.
886
- */
887
- export function objectField<
888
- TKey extends string = TranslationKey,
889
- TChildren extends Record<string, UnifiedField<string, z.ZodTypeAny>> = Record<
890
- string,
891
- UnifiedField<string, z.ZodTypeAny>
892
- >,
893
- TUsage extends FieldUsageConfig = FieldUsageConfig,
894
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
895
- >(
896
- ui: TUIConfig,
897
- usage: TUsage,
898
- children: TChildren,
899
- cache?: CacheStrategy,
900
- ): ObjectField<TChildren, TUsage, TKey, TUIConfig> {
901
- return {
902
- type: "object" as const,
903
- children,
904
- usage,
905
- ui,
906
- cache,
907
- };
908
- }
909
-
910
- /**
911
- * Scoped translation object type for type inference
912
- */
913
- interface ScopedTranslationType<TKey extends string = string> {
914
- ScopedTranslationKey: TKey;
915
- }
916
-
917
- /**
918
- * Create an object field for scoped translations with full type checking.
919
- * Pass the scopedTranslation object to infer the key type and enable validation.
920
- *
921
- * @example
922
- * scopedObjectField(
923
- * scopedTranslation,
924
- * { type: WidgetType.CONTAINER, title: "form.label", ... },
925
- * { request: "data", response: true },
926
- * { name: scopedRequestDataField(scopedTranslation, { label: "form.name.label", ... }, z.string()) }
927
- * )
928
- */
929
- export function scopedObjectField<
930
- TScopedTranslation extends ScopedTranslationType,
931
- TChildren extends Record<
932
- string,
933
- UnifiedField<TScopedTranslation["ScopedTranslationKey"], z.ZodTypeAny>
934
- >,
935
- TUsage extends FieldUsageConfig,
936
- const TUIConfig extends WidgetConfig<TScopedTranslation["ScopedTranslationKey"]>,
937
- >(
938
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used for type inference only
939
- _scopedTranslation: TScopedTranslation,
940
- ui: TUIConfig,
941
- usage: TUsage,
942
- children: TChildren,
943
- cache?: CacheStrategy,
944
- ): ObjectField<TChildren, TUsage, TScopedTranslation["ScopedTranslationKey"], TUIConfig> {
945
- return {
946
- type: "object" as const,
947
- children,
948
- usage,
949
- ui,
950
- cache,
951
- };
952
- }
953
-
954
- /**
955
- * Create a request data field for scoped translations with full type checking.
956
- */
957
- export function scopedRequestDataField<
958
- TScopedTranslation extends ScopedTranslationType,
959
- const TUIConfig extends WidgetConfig<TScopedTranslation["ScopedTranslationKey"]>,
960
- TSchema extends z.ZodTypeAny,
961
- >(
962
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used for type inference only
963
- _scopedTranslation: TScopedTranslation,
964
- ui: TUIConfig,
965
- schema: TSchema,
966
- cache?: CacheStrategy,
967
- ): PrimitiveField<
968
- TSchema,
969
- { request: "data" },
970
- TScopedTranslation["ScopedTranslationKey"],
971
- TUIConfig
972
- > {
973
- return {
974
- type: "primitive" as const,
975
- schema,
976
- usage: { request: "data" },
977
- ui,
978
- cache,
979
- };
980
- }
981
-
982
- /**
983
- * Create a response field for scoped translations with full type checking.
984
- */
985
- export function scopedResponseField<
986
- TScopedTranslation extends ScopedTranslationType,
987
- TSchema extends z.ZodTypeAny,
988
- const TUIConfig extends WidgetConfig<TScopedTranslation["ScopedTranslationKey"]>,
989
- >(
990
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used for type inference only
991
- _scopedTranslation: TScopedTranslation,
992
- ui: TUIConfig,
993
- schema: TSchema,
994
- cache?: CacheStrategy,
995
- ): PrimitiveField<
996
- TSchema,
997
- { response: true },
998
- TScopedTranslation["ScopedTranslationKey"],
999
- TUIConfig
1000
- > {
1001
- return {
1002
- type: "primitive" as const,
1003
- schema,
1004
- usage: { response: true },
1005
- ui,
1006
- cache,
1007
- };
1008
- }
1009
-
1010
- /**
1011
- * Create a response array optional field for scoped translations with full type checking.
1012
- */
1013
- export function scopedResponseArrayOptionalField<
1014
- TScopedTranslation extends ScopedTranslationType,
1015
- Child,
1016
- const TUIConfig extends WidgetConfig<TScopedTranslation["ScopedTranslationKey"]>,
1017
- >(
1018
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Used for type inference only
1019
- _scopedTranslation: TScopedTranslation,
1020
- ui: TUIConfig,
1021
- child: Child,
1022
- cache?: CacheStrategy,
1023
- ): ArrayOptionalField<
1024
- Child,
1025
- { response: true },
1026
- TScopedTranslation["ScopedTranslationKey"],
1027
- TUIConfig
1028
- > {
1029
- return {
1030
- type: "array-optional" as const,
1031
- child,
1032
- usage: { response: true },
1033
- ui,
1034
- cache,
1035
- };
1036
- }
1037
-
1038
- /**
1039
- * Create an array field containing repeated items
1040
- */
1041
- export function arrayField<
1042
- Child,
1043
- const TKey extends string = TranslationKey,
1044
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1045
- >(
1046
- usage: FieldUsageConfig,
1047
- ui: TUIConfig,
1048
- child: Child,
1049
- cache?: CacheStrategy,
1050
- ): ArrayField<Child, FieldUsageConfig, TKey, TUIConfig> {
1051
- return {
1052
- type: "array" as const,
1053
- child,
1054
- usage,
1055
- ui,
1056
- cache,
1057
- };
1058
- }
1059
-
1060
- /**
1061
- * Create a request array field
1062
- */
1063
- export function requestDataArrayField<
1064
- Child,
1065
- const TKey extends string = TranslationKey,
1066
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1067
- >(
1068
- ui: TUIConfig,
1069
- child: Child,
1070
- cache?: CacheStrategy,
1071
- ): ArrayField<Child, { request: "data" }, TKey, TUIConfig> {
1072
- return {
1073
- type: "array" as const,
1074
- child,
1075
- usage: { request: "data" },
1076
- ui,
1077
- cache,
1078
- };
1079
- }
1080
-
1081
- /**
1082
- * Create a response array field
1083
- */
1084
- export function responseArrayField<
1085
- Child,
1086
- const TKey extends string = TranslationKey,
1087
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1088
- >(
1089
- ui: TUIConfig,
1090
- child: Child,
1091
- cache?: CacheStrategy,
1092
- ): ArrayField<Child, { response: true }, TKey, TUIConfig> {
1093
- return {
1094
- type: "array" as const,
1095
- child,
1096
- usage: { response: true },
1097
- ui,
1098
- cache,
1099
- };
1100
- }
1101
-
1102
- /**
1103
- * Create an optional object field
1104
- */
1105
- export function objectOptionalField<
1106
- C,
1107
- U extends FieldUsageConfig = FieldUsageConfig,
1108
- const TKey extends string = TranslationKey,
1109
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1110
- >(
1111
- ui: TUIConfig,
1112
- usage: U,
1113
- children: C,
1114
- cache?: CacheStrategy,
1115
- ): ObjectOptionalField<C, U, TKey, TUIConfig> {
1116
- return {
1117
- type: "object-optional" as const,
1118
- children,
1119
- usage,
1120
- ui,
1121
- cache,
1122
- };
1123
- }
1124
-
1125
- /**
1126
- * Create a discriminated union object field
1127
- */
1128
- export function objectUnionField<
1129
- TDiscriminator extends string,
1130
- TVariants extends readonly [
1131
- ObjectField<
1132
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
1133
- FieldUsageConfig,
1134
- TKey,
1135
- WidgetConfig<TKey>
1136
- >,
1137
- ...ObjectField<
1138
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
1139
- FieldUsageConfig,
1140
- TKey,
1141
- WidgetConfig<TKey>
1142
- >[],
1143
- ],
1144
- TUsage extends FieldUsageConfig = FieldUsageConfig,
1145
- const TKey extends string = TranslationKey,
1146
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1147
- >(
1148
- ui: TUIConfig,
1149
- usage: TUsage,
1150
- discriminator: TDiscriminator,
1151
- variants: TVariants,
1152
- cache?: CacheStrategy,
1153
- ): ObjectUnionField<TDiscriminator, TKey, TVariants, TUsage, TUIConfig> {
1154
- return {
1155
- type: "object-union" as const,
1156
- discriminator,
1157
- variants,
1158
- usage,
1159
- ui,
1160
- cache,
1161
- };
1162
- }
1163
-
1164
- /**
1165
- * Create an optional array field
1166
- */
1167
- export function arrayOptionalField<
1168
- Child,
1169
- const TKey extends string = TranslationKey,
1170
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1171
- >(
1172
- usage: FieldUsageConfig,
1173
- ui: TUIConfig,
1174
- child: Child,
1175
- cache?: CacheStrategy,
1176
- ): ArrayOptionalField<Child, FieldUsageConfig, TKey, TUIConfig> {
1177
- return {
1178
- type: "array-optional" as const,
1179
- child,
1180
- usage,
1181
- ui,
1182
- cache,
1183
- };
1184
- }
1185
-
1186
- /**
1187
- * Create an optional request array field
1188
- */
1189
- export function requestDataArrayOptionalField<
1190
- Child,
1191
- const TKey extends string = TranslationKey,
1192
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1193
- >(
1194
- ui: TUIConfig,
1195
- child: Child,
1196
- cache?: CacheStrategy,
1197
- ): ArrayOptionalField<Child, { request: "data" }, TKey, TUIConfig> {
1198
- return {
1199
- type: "array-optional" as const,
1200
- child,
1201
- usage: { request: "data" },
1202
- ui,
1203
- cache,
1204
- };
1205
- }
1206
-
1207
- /**
1208
- * Create an optional response array field
1209
- */
1210
- export function responseArrayOptionalField<
1211
- Child,
1212
- const TKey extends string = TranslationKey,
1213
- const TUIConfig extends WidgetConfig<TKey> = WidgetConfig<TKey>,
1214
- >(
1215
- ui: TUIConfig,
1216
- child: Child,
1217
- cache?: CacheStrategy,
1218
- ): ArrayOptionalField<Child, { response: true }, TKey, TUIConfig> {
1219
- return {
1220
- type: "array-optional" as const,
1221
- child,
1222
- usage: { response: true },
1223
- ui,
1224
- cache,
1225
- };
1226
- }
1227
-
1228
- // ============================================================================
1229
- // FIELD TYPE INFERENCE UTILITIES
1230
- // ============================================================================
1231
-
1232
- /**
1233
- * Check if a field usage has response capability
1234
- */
1235
- export type HasResponseUsage<U> = U extends { response: true } ? true : false;
1236
-
1237
- /**
1238
- * Check if a field usage has request data capability
1239
- */
1240
- export type HasRequestDataUsage<U> = U extends { request: "data" }
1241
- ? true
1242
- : U extends { request: "data&urlPathParams" }
1243
- ? true
1244
- : false;
1245
-
1246
- /**
1247
- * Check if a field usage has request URL params capability
1248
- */
1249
- export type HasRequestUrlParamsUsage<U> = U extends { request: "urlPathParams" }
1250
- ? true
1251
- : U extends { request: "data&urlPathParams" }
1252
- ? true
1253
- : false;
1254
-
1255
- /**
1256
- * Extract the core properties of a field
1257
- */
1258
- export type FieldCore<F> = F extends {
1259
- type: infer T;
1260
- usage: infer U;
1261
- schema: infer S;
1262
- }
1263
- ? { type: T; usage: U; schema: S }
1264
- : F extends {
1265
- type: infer T;
1266
- usage: infer U;
1267
- }
1268
- ? { type: T; usage: U }
1269
- : F extends {
1270
- type: infer T;
1271
- schema: infer S;
1272
- }
1273
- ? { type: T; schema: S }
1274
- : F extends {
1275
- type: infer T;
1276
- }
1277
- ? { type: T }
1278
- : never;
1279
- /**
1280
- * Check if a field has optional flag in UI config
1281
- * This type checks at the VALUE level, not just the type level
1282
- * It preserves literal types when the UI config is passed with proper inference
1283
- */
1284
- type IsOptionalField<F> =
1285
- // Check if field type is explicitly optional (array-optional, object-optional)
1286
- F extends { type: "array-optional" | "object-optional" }
1287
- ? true
1288
- : // Otherwise check ui.optional flag
1289
- F extends {
1290
- ui: infer UI;
1291
- }
1292
- ? UI extends { optional?: infer O }
1293
- ? [O] extends [true]
1294
- ? true
1295
- : [O] extends [false]
1296
- ? false
1297
- : false
1298
- : false
1299
- : false;
1300
-
1301
- /**
1302
- * Make type optional with nullable support (T | null | undefined)
1303
- */
1304
- type MakeOptional<T, IsOptional extends boolean> = IsOptional extends true
1305
- ? T | null | undefined
1306
- : T;
1307
-
1308
- /**
1309
- * Infer union type from ObjectUnionField variants
1310
- */
1311
- export type InferUnionType<
1312
- TTranslatedKey extends string,
1313
- TVariants extends readonly ObjectField<
1314
- Record<string, UnifiedField<TTranslatedKey, z.ZodTypeAny>>,
1315
- FieldUsageConfig,
1316
- TTranslatedKey,
1317
- WidgetConfig<TTranslatedKey>
1318
- >[],
1319
- Usage extends FieldUsage,
1320
- > = TVariants extends readonly [infer Head, ...infer Tail]
1321
- ? Head extends ObjectField<
1322
- Record<string, UnifiedField<TTranslatedKey, z.ZodTypeAny>>,
1323
- FieldUsageConfig,
1324
- TTranslatedKey,
1325
- WidgetConfig<TTranslatedKey>
1326
- >
1327
- ? Tail extends ObjectField<
1328
- Record<string, UnifiedField<TTranslatedKey, z.ZodTypeAny>>,
1329
- FieldUsageConfig,
1330
- TTranslatedKey,
1331
- WidgetConfig<TTranslatedKey>
1332
- >[]
1333
- ? InferFieldType<Head, Usage, TTranslatedKey> | InferUnionType<TTranslatedKey, Tail, Usage>
1334
- : InferFieldType<Head, Usage, TTranslatedKey>
1335
- : never
1336
- : never;
1337
-
1338
- /**
1339
- * Infer field type based on usage
1340
- */
1341
- export type InferFieldType<F, Usage extends FieldUsage, TKey extends string> =
1342
- F extends UnifiedField<TKey, infer TSchema>
1343
- ? F extends {
1344
- type: "primitive";
1345
- usage: infer U;
1346
- }
1347
- ? Usage extends FieldUsage.Response
1348
- ? HasResponseUsage<U> extends true
1349
- ? z.output<TSchema>
1350
- : never
1351
- : Usage extends FieldUsage.RequestData
1352
- ? HasRequestDataUsage<U> extends true
1353
- ? z.output<TSchema>
1354
- : never
1355
- : Usage extends FieldUsage.RequestUrlParams
1356
- ? HasRequestUrlParamsUsage<U> extends true
1357
- ? z.output<TSchema>
1358
- : never
1359
- : never
1360
- : F extends {
1361
- type: "array" | "array-optional";
1362
- child: infer Child;
1363
- usage: infer U;
1364
- }
1365
- ? Usage extends FieldUsage.Response
1366
- ? HasResponseUsage<U> extends true
1367
- ? MakeOptional<Array<InferFieldType<Child, Usage, TKey>>, IsOptionalField<F>>
1368
- : never
1369
- : Usage extends FieldUsage.RequestData
1370
- ? HasRequestDataUsage<U> extends true
1371
- ? MakeOptional<Array<InferFieldType<Child, Usage, TKey>>, IsOptionalField<F>>
1372
- : never
1373
- : Usage extends FieldUsage.RequestUrlParams
1374
- ? HasRequestUrlParamsUsage<U> extends true
1375
- ? MakeOptional<Array<InferFieldType<Child, Usage, TKey>>, IsOptionalField<F>>
1376
- : never
1377
- : never
1378
- : F extends {
1379
- type: "object-union";
1380
- variants: infer TVariants;
1381
- usage: infer U;
1382
- }
1383
- ? TVariants extends readonly ObjectField<
1384
- Record<string, UnifiedField<TKey, z.ZodTypeAny>>,
1385
- FieldUsageConfig,
1386
- TKey,
1387
- WidgetConfig<TKey>
1388
- >[]
1389
- ? Usage extends FieldUsage.Response
1390
- ? HasResponseUsage<U> extends true
1391
- ? InferUnionType<TKey, TVariants, Usage>
1392
- : never
1393
- : Usage extends FieldUsage.RequestData
1394
- ? HasRequestDataUsage<U> extends true
1395
- ? InferUnionType<TKey, TVariants, Usage>
1396
- : never
1397
- : Usage extends FieldUsage.RequestUrlParams
1398
- ? HasRequestUrlParamsUsage<U> extends true
1399
- ? InferUnionType<TKey, TVariants, Usage>
1400
- : never
1401
- : never
1402
- : never
1403
- : F extends {
1404
- type: "object" | "object-optional";
1405
- children: infer C;
1406
- usage: infer U;
1407
- }
1408
- ? Usage extends FieldUsage.Response
1409
- ? HasResponseUsage<U> extends true
1410
- ? MakeOptional<InferObjectType<C, Usage, TKey>, IsOptionalField<F>>
1411
- : never
1412
- : Usage extends FieldUsage.RequestData
1413
- ? HasRequestDataUsage<U> extends true
1414
- ? MakeOptional<InferObjectType<C, Usage, TKey>, IsOptionalField<F>>
1415
- : never
1416
- : Usage extends FieldUsage.RequestUrlParams
1417
- ? HasRequestUrlParamsUsage<U> extends true
1418
- ? MakeOptional<InferObjectType<C, Usage, TKey>, IsOptionalField<F>>
1419
- : never
1420
- : never
1421
- : F extends {
1422
- type: "object" | "object-optional";
1423
- children: infer C;
1424
- }
1425
- ? MakeOptional<InferObjectType<C, Usage, TKey>, IsOptionalField<F>>
1426
- : never
1427
- : never;
1428
-
1429
- /**
1430
- * Infer object type from children fields
1431
- * Uses flexible constraint that accepts both readonly and mutable properties
1432
- * Checks each field's optional flag to make properties optional in the resulting type
1433
- */
1434
- export type InferObjectType<C, Usage extends FieldUsage, TKey extends string> =
1435
- C extends Record<string, UnifiedField<TKey, z.ZodTypeAny>>
1436
- ? {
1437
- -readonly [K in keyof C as InferFieldType<C[K], Usage, TKey> extends never
1438
- ? never
1439
- : IsOptionalField<C[K]> extends true
1440
- ? never
1441
- : K]: InferFieldType<C[K], Usage, TKey>;
1442
- } & {
1443
- -readonly [K in keyof C as InferFieldType<C[K], Usage, TKey> extends never
1444
- ? never
1445
- : IsOptionalField<C[K]> extends true
1446
- ? K
1447
- : never]?: InferFieldType<C[K], Usage, TKey>;
1448
- }
1449
- : never;
1450
-
1451
- // ============================================================================
1452
- // SCHEMA GENERATION UTILITIES
1453
- // ============================================================================
1454
-
1455
- /**
1456
- * Generate schema for a specific usage from unified fields
1457
- * CRITICAL: This function must preserve the actual Zod schema types to enable
1458
- * proper input/output type differentiation using z.ZodType<Output, ZodTypeDef, Input>.
1459
- *
1460
- * We return the actual inferred schema type to preserve input/output differentiation.
1461
- */
1462
- export function generateSchemaForUsage<F, Usage extends FieldUsage>(
1463
- field: F,
1464
- targetUsage: Usage,
1465
- ): InferSchemaFromField<F, Usage> {
1466
- // Defensive check: ensure field is defined
1467
- if (!field || typeof field !== "object") {
1468
- return z.never() as InferSchemaFromField<F, Usage>;
1469
- }
1470
-
1471
- const hasUsage = (usage: FieldUsageConfig | undefined): boolean => {
1472
- if (!usage) {
1473
- return false;
1474
- }
1475
-
1476
- switch (targetUsage) {
1477
- case FieldUsage.Response:
1478
- return "response" in usage && usage.response === true;
1479
- case FieldUsage.RequestData:
1480
- return (
1481
- "request" in usage && (usage.request === "data" || usage.request === "data&urlPathParams")
1482
- );
1483
- case FieldUsage.RequestUrlParams:
1484
- return (
1485
- "request" in usage &&
1486
- (usage.request === "urlPathParams" || usage.request === "data&urlPathParams")
1487
- );
1488
- default:
1489
- return false;
1490
- }
1491
- };
1492
-
1493
- interface FieldWithType {
1494
- type:
1495
- | "primitive"
1496
- | "widget"
1497
- | "object"
1498
- | "object-optional"
1499
- | "object-union"
1500
- | "array"
1501
- | "array-optional";
1502
- usage?: FieldUsageConfig;
1503
- schema?: z.ZodTypeAny;
1504
- children?: Record<string, UnifiedField<string, z.ZodTypeAny>>;
1505
- child?: UnifiedField<string, z.ZodTypeAny>;
1506
- discriminator?: string;
1507
- variants?: readonly ObjectField<
1508
- Record<string, UnifiedField<string, z.ZodTypeAny>>,
1509
- FieldUsageConfig,
1510
- string,
1511
- WidgetConfig<string>
1512
- >[];
1513
- ui?: WidgetConfig<string>;
1514
- }
1515
-
1516
- const typedField = field as F & FieldWithType;
1517
-
1518
- // Create a reference z.never() type for comparison - ensures runtime correctness
1519
- const neverType = z.never()._def.type;
1520
-
1521
- // Widget-only fields have no schema and are skipped during schema generation
1522
- if (typedField.type === "widget") {
1523
- return z.never() as InferSchemaFromField<F, Usage>;
1524
- }
1525
-
1526
- if (typedField.type === "primitive") {
1527
- if (hasUsage(typedField.usage)) {
1528
- return typedField.schema as InferSchemaFromField<F, Usage>;
1529
- }
1530
- return z.never() as InferSchemaFromField<F, Usage>;
1531
- }
1532
-
1533
- if (typedField.type === "object") {
1534
- // Check if the object itself has the required usage
1535
- // If it has explicit usage that doesn't match, skip processing children
1536
- const objectHasUsage = typedField.usage ? hasUsage(typedField.usage) : true;
1537
-
1538
- if (typedField.usage && !objectHasUsage) {
1539
- // For request data, return empty object (endpoints with no parameters)
1540
- // This is critical for OpenAI function calling which requires type: "object"
1541
- if (targetUsage === FieldUsage.RequestData) {
1542
- const emptySchema = z.object({});
1543
- return emptySchema as InferSchemaFromField<F, Usage>;
1544
- }
1545
- return z.never() as InferSchemaFromField<F, Usage>;
1546
- }
1547
-
1548
- // Build shape object with proper typing to preserve schema types
1549
- // We need to avoid using Record<string, z.ZodTypeAny> which loses type information
1550
- const shape: Record<string, z.ZodTypeAny> = {};
1551
-
1552
- if (typedField.children) {
1553
- for (const [key, childField] of Object.entries(typedField.children)) {
1554
- // CRITICAL: Skip widget fields completely - they should NEVER be in validation schemas
1555
- // Widget fields (formAlert, submitButton, etc.) are UI-only and don't send/receive data
1556
- const isWidgetField = "type" in childField && childField.type === "widget";
1557
- if (isWidgetField) {
1558
- continue;
1559
- }
1560
-
1561
- // CRITICAL: Skip objectFields that only contain widget children - they're UI-only containers
1562
- // Examples: footerLinks container with only widget links inside
1563
- const isObjectFieldWithOnlyWidgets =
1564
- childField.type === "object" &&
1565
- childField.children &&
1566
- Object.values(childField.children).every(
1567
- (grandchild) => "type" in grandchild && grandchild.type === "widget",
1568
- );
1569
- if (isObjectFieldWithOnlyWidgets) {
1570
- continue;
1571
- }
1572
-
1573
- // Check if the child field has the required usage BEFORE generating the schema
1574
- // This is more efficient and avoids issues with z.never() detection
1575
- if (childField.usage) {
1576
- const childHasUsage =
1577
- targetUsage === FieldUsage.Response
1578
- ? "response" in childField.usage && childField.usage.response === true
1579
- : targetUsage === FieldUsage.RequestData
1580
- ? "request" in childField.usage &&
1581
- (childField.usage.request === "data" ||
1582
- childField.usage.request === "data&urlPathParams")
1583
- : targetUsage === FieldUsage.RequestUrlParams
1584
- ? "request" in childField.usage &&
1585
- (childField.usage.request === "urlPathParams" ||
1586
- childField.usage.request === "data&urlPathParams")
1587
- : false;
1588
-
1589
- // Skip fields that don't have the required usage
1590
- if (!childHasUsage) {
1591
- continue;
1592
- }
1593
- }
1594
-
1595
- const childSchema = generateSchemaForUsage<typeof childField, Usage>(
1596
- childField,
1597
- targetUsage,
1598
- );
1599
- // Check if schema is z.never() by comparing type to actual z.never() instance
1600
- if (childSchema._def.type !== neverType) {
1601
- shape[key] = childSchema;
1602
- }
1603
- }
1604
- }
1605
-
1606
- // If no children matched the usage, return z.never()
1607
- // This handles cases like container fields with only widget children
1608
- // These UI-only containers shouldn't be in validation schemas
1609
- if (Object.keys(shape).length === 0) {
1610
- return z.never() as InferSchemaFromField<F, Usage>;
1611
- }
1612
-
1613
- // Create the object schema and let TypeScript infer the exact type
1614
- // This preserves the specific field types instead of collapsing to ZodTypeAny
1615
- let objectSchema = z.object(shape);
1616
-
1617
- // Apply optional modifier if specified in UI config
1618
- if (typedField.ui && "optional" in typedField.ui && typedField.ui.optional) {
1619
- const optionalSchema = objectSchema.nullable().optional();
1620
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Type casting: Complex Zod schema inference requires unknown as intermediate step for type safety between incompatible generic structures.
1621
- return optionalSchema as unknown as InferSchemaFromField<F, Usage>;
1622
- }
1623
-
1624
- return objectSchema as InferSchemaFromField<F, Usage>;
1625
- }
1626
-
1627
- if (typedField.type === "object-optional") {
1628
- // Check if the object itself has the required usage
1629
- const objectHasUsage = typedField.usage ? hasUsage(typedField.usage) : true;
1630
-
1631
- if (typedField.usage && !objectHasUsage) {
1632
- return z.never() as InferSchemaFromField<F, Usage>;
1633
- }
1634
-
1635
- // Build shape object with proper typing to preserve schema types
1636
- const shape: Record<string, z.ZodTypeAny> = {};
1637
-
1638
- if (typedField.children) {
1639
- for (const [key, childField] of Object.entries(typedField.children)) {
1640
- // Skip widget fields - they're UI-only
1641
- const isWidgetField = "type" in childField && childField.type === "widget";
1642
- if (isWidgetField) {
1643
- continue;
1644
- }
1645
-
1646
- const childSchema = generateSchemaForUsage<typeof childField, Usage>(
1647
- childField,
1648
- targetUsage,
1649
- );
1650
- if (childSchema._def.type !== neverType) {
1651
- shape[key] = childSchema;
1652
- }
1653
- }
1654
- }
1655
-
1656
- // If no children matched the usage, return z.never()
1657
- if (Object.keys(shape).length === 0) {
1658
- return z.never() as InferSchemaFromField<F, Usage>;
1659
- }
1660
-
1661
- // Create the object schema and wrap in nullable().optional() for object-optional
1662
- const objectSchema = z.object(shape).nullable().optional();
1663
- return objectSchema as InferSchemaFromField<F, Usage>;
1664
- }
1665
-
1666
- if (typedField.type === "object-union") {
1667
- // Check if the union itself has the required usage
1668
- const unionHasUsage = typedField.usage ? hasUsage(typedField.usage) : true;
1669
-
1670
- if (typedField.usage && !unionHasUsage) {
1671
- return z.never() as InferSchemaFromField<F, Usage>;
1672
- }
1673
-
1674
- // Validate discriminator and variants exist
1675
- if (!typedField.discriminator || !typedField.variants) {
1676
- return z.never() as InferSchemaFromField<F, Usage>;
1677
- }
1678
-
1679
- // Generate schemas for each variant
1680
- const variantSchemas: z.ZodObject<z.ZodRawShape>[] = [];
1681
-
1682
- for (const variant of typedField.variants) {
1683
- // Generate schema for this variant using the same target usage
1684
- const variantSchema = generateSchemaForUsage<typeof variant, Usage>(variant, targetUsage);
1685
-
1686
- // Skip variants that don't match the usage
1687
- if (variantSchema._def.type === neverType) {
1688
- continue;
1689
- }
1690
-
1691
- // Ensure the variant schema is a ZodObject (required for discriminated unions)
1692
- if (variantSchema instanceof z.ZodObject) {
1693
- variantSchemas.push(variantSchema);
1694
- }
1695
- }
1696
-
1697
- // If no variants matched the usage, return z.never()
1698
- if (variantSchemas.length === 0) {
1699
- return z.never() as InferSchemaFromField<F, Usage>;
1700
- }
1701
-
1702
- // If only one variant, just return it (no need for union)
1703
- if (variantSchemas.length === 1) {
1704
- return variantSchemas[0] as InferSchemaFromField<F, Usage>;
1705
- }
1706
-
1707
- // Create discriminated union with at least 2 variants
1708
- const unionSchema = z.discriminatedUnion(
1709
- typedField.discriminator,
1710
- variantSchemas as [
1711
- z.ZodObject<z.ZodRawShape>,
1712
- z.ZodObject<z.ZodRawShape>,
1713
- ...z.ZodObject<z.ZodRawShape>[],
1714
- ],
1715
- );
1716
-
1717
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax, @typescript-eslint/no-explicit-any -- Schema generation requires type assertion for proper inference
1718
- return unionSchema as any as InferSchemaFromField<F, Usage>;
1719
- }
1720
-
1721
- if (typedField.type === "array") {
1722
- if (hasUsage(typedField.usage)) {
1723
- // Check if child exists
1724
- if (!typedField.child) {
1725
- return z.never() as InferSchemaFromField<F, Usage>;
1726
- }
1727
-
1728
- let childSchema: z.ZodTypeAny;
1729
- if (isZodSchema(typedField.child)) {
1730
- // Child is already a Zod schema, use it directly
1731
- childSchema = typedField.child;
1732
- } else {
1733
- // Child is a UnifiedField, generate schema from it
1734
- childSchema = generateSchemaForUsage<typeof typedField.child, Usage>(
1735
- typedField.child,
1736
- targetUsage,
1737
- );
1738
- // Check if schema is z.never() using _def.type check
1739
- if (childSchema._def.type === neverType) {
1740
- return z.never() as InferSchemaFromField<F, Usage>;
1741
- }
1742
- }
1743
-
1744
- let arraySchema = z.array(childSchema);
1745
-
1746
- // Apply optional modifier if specified in UI config
1747
- if (typedField.ui && "optional" in typedField.ui && typedField.ui.optional) {
1748
- const optionalArraySchema = arraySchema.nullable().optional();
1749
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Type casting: Complex Zod schema inference requires unknown as intermediate step for type safety between incompatible generic structures.
1750
- return optionalArraySchema as unknown as InferSchemaFromField<F, Usage>;
1751
- }
1752
-
1753
- return arraySchema as InferSchemaFromField<F, Usage>;
1754
- }
1755
- return z.never() as InferSchemaFromField<F, Usage>;
1756
- }
1757
-
1758
- if (typedField.type === "array-optional") {
1759
- if (hasUsage(typedField.usage)) {
1760
- // Check if child exists
1761
- if (!typedField.child) {
1762
- return z.never() as InferSchemaFromField<F, Usage>;
1763
- }
1764
-
1765
- let childSchema: z.ZodTypeAny;
1766
- if (isZodSchema(typedField.child)) {
1767
- // Child is already a Zod schema, use it directly
1768
- childSchema = typedField.child;
1769
- } else {
1770
- // Child is a UnifiedField, generate schema from it
1771
- childSchema = generateSchemaForUsage<typeof typedField.child, Usage>(
1772
- typedField.child,
1773
- targetUsage,
1774
- );
1775
- // Check if schema is z.never() using _def.type check
1776
- if (childSchema._def.type === neverType) {
1777
- return z.never() as InferSchemaFromField<F, Usage>;
1778
- }
1779
- }
1780
-
1781
- // For array-optional, always apply nullable and optional
1782
- const arrayOptionalSchema = z.array(childSchema).nullable().optional();
1783
-
1784
- // eslint-disable-next-line oxlint-plugin-restricted/restricted-syntax -- Type casting: Complex Zod schema inference requires unknown as intermediate step for type safety between incompatible generic structures.
1785
- return arrayOptionalSchema as unknown as InferSchemaFromField<F, Usage>;
1786
- }
1787
- return z.never() as InferSchemaFromField<F, Usage>;
1788
- }
1789
-
1790
- return z.never() as InferSchemaFromField<F, Usage>;
1791
- }
1792
-
1793
- // Utility types that work with z.ZodType<Output, ZodTypeDef, Input> to properly infer types
1794
- // These preserve the input/output type differentiation from Zod schemas
1795
-
1796
- export type InferFieldSchemaInputType<F, Usage extends FieldUsage> = z.input<
1797
- ReturnType<typeof generateSchemaForUsage<F, Usage>>
1798
- >;
1799
-
1800
- export type InferFieldSchemaOutputType<F, Usage extends FieldUsage> = z.output<
1801
- ReturnType<typeof generateSchemaForUsage<F, Usage>>
1802
- >;
1803
-
1804
- /**
1805
- * Generate request data schema with proper input/output type differentiation
1806
- */
1807
- export function generateRequestDataSchema<F>(
1808
- field: F,
1809
- ): InferSchemaFromField<F, FieldUsage.RequestData> {
1810
- return generateSchemaForUsage<F, FieldUsage.RequestData>(field, FieldUsage.RequestData);
1811
- }
1812
-
1813
- /**
1814
- * Generate request URL params schema with proper input/output type differentiation
1815
- */
1816
- export function generateRequestUrlSchema<F>(
1817
- field: F,
1818
- ): InferSchemaFromField<F, FieldUsage.RequestUrlParams> {
1819
- return generateSchemaForUsage<F, FieldUsage.RequestUrlParams>(field, FieldUsage.RequestUrlParams);
1820
- }
1821
-
1822
- /**
1823
- * Generate response schema with proper input/output type differentiation
1824
- */
1825
- export function generateResponseSchema<F>(field: F): InferSchemaFromField<F, FieldUsage.Response> {
1826
- return generateSchemaForUsage<F, FieldUsage.Response>(field, FieldUsage.Response);
1827
- }