@akanjs/devkit 3.2.0-rc.2 → 3.2.0-rc.20

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 (365) hide show
  1. package/CHANGELOG.md +315 -11
  2. package/DEV_RUNTIME_KNOBS.md +4 -3
  3. package/README.ko.md +3 -2
  4. package/README.md +4 -2
  5. package/akanApp/BackendImportGraph.test.ts +1 -1
  6. package/akanApp/akanApp.host.test.ts +257 -1
  7. package/akanApp/akanApp.host.ts +146 -1223
  8. package/akanApp/akanApp.host.wiring.test.ts +727 -0
  9. package/akanApp/builderGap.ts +68 -0
  10. package/akanApp/builderRequestRelay.test.ts +93 -0
  11. package/akanApp/builderRequestRelay.ts +100 -0
  12. package/akanApp/builderRssRecycler.ts +182 -0
  13. package/akanApp/devBackend.ts +392 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +196 -0
  16. package/akanApp/devHostPolicy.test.ts +11 -11
  17. package/akanApp/devHostPolicy.ts +2 -4
  18. package/akanApp/devIdleSuspend.test.ts +221 -0
  19. package/akanApp/devIdleSuspend.ts +192 -0
  20. package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
  21. package/akanApp/devRecycler.test.ts +66 -0
  22. package/akanApp/devRecycler.ts +305 -0
  23. package/akanApp/processRss.ts +61 -0
  24. package/akanConfig/akanConfig.test.ts +24 -1
  25. package/akanConfig/akanConfig.ts +10 -10
  26. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  27. package/akanConfig/productionLockfile.ts +1 -1
  28. package/apiReport/apiDeclarationPrinter.ts +120 -0
  29. package/apiReport/apiReport.test.ts +526 -0
  30. package/apiReport/apiReport.ts +232 -0
  31. package/apiReport/apiReportDiff.ts +160 -0
  32. package/apiReport/apiReportPolicy.ts +65 -0
  33. package/apiReport/apiTargets.ts +311 -0
  34. package/apiReport/changesetBump.ts +19 -0
  35. package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +21 -0
  36. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +10 -49
  37. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +74 -7
  38. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +20 -15
  39. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  40. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +48 -12
  41. package/{routeJsBudget.ts → app/routeJsBudget.ts} +90 -27
  42. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  43. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  44. package/artifact/implicitRootLayout.test.ts +71 -3
  45. package/artifact/implicitRootLayout.ts +21 -4
  46. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  47. package/biome.base.json +2 -1
  48. package/cloud/cloudApi.test.ts +1 -1
  49. package/cloud/configLock.test.ts +1 -1
  50. package/cloud/globalConfig.test.ts +1 -1
  51. package/cloud/globalConfig.ts +1 -1
  52. package/cloud/updatePackUpload.test.ts +1 -1
  53. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  54. package/codeAgent/agent/akanCodePaths.ts +1 -1
  55. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  56. package/codeAgent/agent/codeAgent.test.ts +1 -1
  57. package/codeAgent/skills/akan-debug/SKILL.md +10 -3
  58. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  59. package/codeAgent/skills/akan-mcp/SKILL.md +10 -1
  60. package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
  61. package/codeAgent/skills/akan-transport/SKILL.md +2 -0
  62. package/codeAgent/skills/akan-validate/SKILL.md +1 -0
  63. package/codeAgent/tools/AkanCli.ts +1 -1
  64. package/codeAgent/tools/AkanToolPack.ts +1 -1
  65. package/codeAgent/tools/McpClient.ts +28 -6
  66. package/codeAgent/tools/McpToolPack.ts +1 -1
  67. package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
  68. package/commandDecorators/argMeta.ts +4 -0
  69. package/commandDecorators/cliError.ts +72 -0
  70. package/commandDecorators/command.ts +165 -91
  71. package/commandDecorators/commandBuilder.ts +1 -1
  72. package/commandDecorators/commandDecorators.test.ts +191 -16
  73. package/commandDecorators/exitCodeError.ts +6 -7
  74. package/commandDecorators/index.ts +1 -0
  75. package/commandDecorators/targetMeta.ts +1 -0
  76. package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
  77. package/commandDecorators/workspaceVersionCheck.ts +1 -1
  78. package/context/akanContext.ts +576 -0
  79. package/context/akanContextInspection.ts +296 -0
  80. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  81. package/{akanMcpContract.ts → context/akanMcpContract.ts} +33 -263
  82. package/context/akanMcpToolError.ts +16 -0
  83. package/context/doctor/agentGuideCheck.ts +81 -0
  84. package/context/doctor/configLeftoverCheck.ts +35 -0
  85. package/context/doctor/doctorFindings.ts +70 -0
  86. package/context/doctor/generatedFreshness.ts +56 -0
  87. package/context/doctor/moduleShapeCheck.ts +88 -0
  88. package/context/doctor/recipeDuplicateCheck.ts +39 -0
  89. package/context/doctor/recipeIndexCheck.ts +87 -0
  90. package/context/doctor/rootShapeCheck.ts +55 -0
  91. package/context/doctor/workflowScope.ts +97 -0
  92. package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
  93. package/context/moduleFieldNames.ts +25 -0
  94. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  95. package/context/safeRead.ts +9 -0
  96. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  97. package/devkitUtils.test.ts +39 -5
  98. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  99. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  100. package/docs/errorCodeReference.test.ts +282 -0
  101. package/docs/errorCodeReference.ts +71 -0
  102. package/docs/errorCodeScan.ts +551 -0
  103. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  104. package/executors/appExecutor.ts +448 -0
  105. package/executors/commandExecutionError.ts +53 -0
  106. package/executors/executor.ts +527 -0
  107. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  108. package/{executors.test.ts → executors/executors.test.ts} +76 -15
  109. package/executors/index.ts +8 -0
  110. package/executors/libExecutor.ts +23 -0
  111. package/executors/moduleExecutor.ts +18 -0
  112. package/executors/pkgExecutor.ts +129 -0
  113. package/executors/sysExecutor.ts +301 -0
  114. package/executors/workspaceExecutor.ts +277 -0
  115. package/frontendBuild/allRoutesBuilder.test.ts +17 -5
  116. package/frontendBuild/allRoutesBuilder.ts +24 -6
  117. package/frontendBuild/autoImportSync.test.ts +1 -1
  118. package/frontendBuild/autoImportSync.ts +1 -1
  119. package/frontendBuild/buildRouteClient.test.ts +1 -1
  120. package/frontendBuild/bundleDefine.ts +2 -0
  121. package/frontendBuild/clientBuildTypes.ts +5 -2
  122. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  123. package/frontendBuild/clientEntryDiscovery.test.ts +58 -0
  124. package/frontendBuild/clientEntryDiscovery.ts +25 -6
  125. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  126. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  127. package/frontendBuild/cssCompiler.test.ts +1 -1
  128. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  129. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  130. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  131. package/frontendBuild/fontOptimizer.test.ts +1 -1
  132. package/frontendBuild/fontPruner.test.ts +1 -1
  133. package/frontendBuild/frontendBuild.test.ts +3 -3
  134. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  135. package/frontendBuild/hmrWatcher.test.ts +1 -1
  136. package/frontendBuild/hmrWatcher.ts +22 -1
  137. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  138. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  139. package/frontendBuild/nativeCore.test.ts +148 -0
  140. package/frontendBuild/optionalPeers.test.ts +36 -8
  141. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  142. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  143. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  144. package/frontendBuild/precompressArtifacts.ts +1 -1
  145. package/frontendBuild/serverGraphFile.ts +1 -1
  146. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  147. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
  148. package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
  149. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  150. package/frontendBuild/vendorImportScanner.test.ts +25 -4
  151. package/frontendBuild/vendorImportScanner.ts +25 -10
  152. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  153. package/frontendBuild/watchRootResolver.test.ts +1 -1
  154. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  155. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  156. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  157. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  158. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  159. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  160. package/{prompter.ts → guideline/prompter.ts} +2 -3
  161. package/incrementalBuilder/buildBatch.proc.ts +14 -4
  162. package/incrementalBuilder/buildBatchProtocol.ts +2 -0
  163. package/incrementalBuilder/buildBatchRunner.test.ts +108 -1
  164. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  165. package/incrementalBuilder/builderBoot.ts +106 -0
  166. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  167. package/incrementalBuilder/builderChannel.test.ts +1 -1
  168. package/incrementalBuilder/builderChannel.ts +11 -0
  169. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  170. package/incrementalBuilder/builderLanes.ts +157 -0
  171. package/incrementalBuilder/builderWatch.ts +213 -0
  172. package/incrementalBuilder/csrRegistry.ts +234 -0
  173. package/incrementalBuilder/incrementalBuilder.host.test.ts +30 -1
  174. package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
  175. package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
  176. package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
  177. package/incrementalBuilder/ssrRegistry.ts +278 -0
  178. package/index.ts +22 -22
  179. package/integration/devStability.integration.test.ts +62 -56
  180. package/integration/devStabilityHarness.test.ts +1 -1
  181. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  182. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  183. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  184. package/lint/gritRules.test.ts +1 -1
  185. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  186. package/lint/no-import-common-err.grit +31 -0
  187. package/lint/no-init-fetch-in-client.grit +1 -1
  188. package/lint/no-web-only-api-outside-webkit.grit +3 -3
  189. package/mobile/desktopBin.test.ts +1 -1
  190. package/mobile/desktopRelease.test.ts +1 -1
  191. package/mobile/desktopServerStage.test.ts +2 -2
  192. package/mobile/desktopServerStage.ts +1 -1
  193. package/mobile/nativeApi.test.ts +1 -1
  194. package/mobile/nativeApp.test.ts +1 -1
  195. package/mobile/nativeConfig.test.ts +1 -1
  196. package/mobile/nativePluginFolders.test.ts +1 -1
  197. package/mobile/nativePublicEnv.test.ts +1 -1
  198. package/mobile/nativeWebDir.test.ts +1 -1
  199. package/mobile/serverBundleSecrets.test.ts +1 -1
  200. package/mobile/tarWriter.test.ts +1 -1
  201. package/mobile/updatePackFolder.test.ts +1 -1
  202. package/package.json +167 -3
  203. package/packageExports.test.ts +20 -2
  204. package/piDependencyPins.test.ts +1 -1
  205. package/pipeline/PipelineDefinition.ts +1 -1
  206. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  207. package/platformTest/PlatformTestRun.test.ts +1 -1
  208. package/platformTest/TestSnapshot.test.ts +1 -1
  209. package/preview/PreviewView.ts +32 -11
  210. package/preview/previewView.test.ts +76 -9
  211. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  212. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  213. package/quality/bareErrorScanner.ts +126 -0
  214. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  215. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  216. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  217. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  218. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  219. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  220. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  221. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  222. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +1 -1
  223. package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
  224. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  225. package/{subspace.test.ts → subspace/subspace.test.ts} +9 -3
  226. package/{subspace.ts → subspace/subspace.ts} +5 -5
  227. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  228. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  229. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  230. package/transforms/barrelAnalyzer.ts +26 -8
  231. package/transforms/browserDirnamePlugin.test.ts +1 -1
  232. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  233. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  234. package/transforms/pureLazyMarker.test.ts +1 -1
  235. package/transforms/serverEnvPlugin.test.ts +1 -1
  236. package/transforms/serverEnvProfile.test.ts +1 -1
  237. package/transforms/sideEffectImportOrder.test.ts +1 -1
  238. package/transforms/transforms.test.ts +29 -2
  239. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  240. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  241. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  242. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  243. package/typecheck/projectTypecheck.test.ts +1 -1
  244. package/typecheck/projectTypecheck.ts +6 -2
  245. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  246. package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
  247. package/typecheck/typecheck.proc.ts +4 -3
  248. package/typecheck/typecheckFailure.ts +7 -2
  249. package/util/errorReport.ts +66 -0
  250. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  251. package/workflow/artifacts.ts +8 -7
  252. package/workflow/constantSource.ts +187 -0
  253. package/workflow/dictionarySource.ts +184 -0
  254. package/workflow/executor.ts +6 -9
  255. package/workflow/fieldExpression.ts +153 -0
  256. package/workflow/fieldLabel.ts +61 -0
  257. package/workflow/fieldOrder.ts +117 -0
  258. package/workflow/fieldType.ts +93 -0
  259. package/workflow/guardCatalog.test.ts +1 -1
  260. package/workflow/index.ts +2 -0
  261. package/workflow/keyRename.ts +1 -1
  262. package/workflow/moduleIndex.test.ts +2 -2
  263. package/workflow/moduleIndex.ts +2 -2
  264. package/workflow/modulePaths.ts +27 -0
  265. package/workflow/mutationScaffold.ts +7 -15
  266. package/workflow/mutationSource.ts +2 -1
  267. package/workflow/plainName.ts +28 -0
  268. package/workflow/plan.ts +15 -9
  269. package/workflow/primitiveReport.ts +78 -0
  270. package/workflow/rolloutGate.test.ts +1 -1
  271. package/workflow/rolloutGate.ts +1 -1
  272. package/workflow/serviceSource.ts +33 -0
  273. package/workflow/signalSource.ts +96 -0
  274. package/workflow/source.ts +50 -1105
  275. package/workflow/sourceAst.ts +30 -0
  276. package/workflow/sourceImports.ts +105 -0
  277. package/workflow/sourceText.ts +13 -0
  278. package/workflow/templateSource.ts +30 -0
  279. package/workflow/testSource.ts +31 -0
  280. package/workflow/types.ts +1 -1
  281. package/workflow/uiPolicy.ts +1 -1
  282. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  283. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  284. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  285. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  286. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  287. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  288. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  289. package/{libSource.ts → workspace/libSource.ts} +1 -1
  290. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  291. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  292. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  293. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +85 -1
  294. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +41 -6
  295. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  296. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  297. package/akanContext.ts +0 -1084
  298. package/constantFieldNames.ts +0 -18
  299. package/executors.ts +0 -1749
  300. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  301. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  302. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  303. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  304. /package/{linter.ts → lint/linter.ts} +0 -0
  305. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  306. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  307. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  308. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  309. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  310. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  311. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  312. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  313. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  314. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  315. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  316. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  317. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  318. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  319. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  320. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  321. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  322. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  323. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  324. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  325. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  326. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  327. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  328. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  329. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  330. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  331. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  332. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  333. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  334. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  335. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  336. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  337. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  338. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  339. /package/{writePath.ts → quality/writePath.ts} +0 -0
  340. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  341. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  342. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  343. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  344. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  345. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  346. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  347. /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
  348. /package/{fileSys.ts → util/fileSys.ts} +0 -0
  349. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  350. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  351. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  352. /package/{semver.ts → util/semver.ts} +0 -0
  353. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  354. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  355. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  356. /package/{spinner.ts → util/spinner.ts} +0 -0
  357. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  358. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  359. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  360. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  361. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  362. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  363. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  364. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  365. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,187 @@
1
+ import ts from "typescript";
2
+ import { insertOrderedFieldLine, locatedObject, type ObjectInsertionLocator } from "./fieldOrder";
3
+ import {
4
+ expressionName,
5
+ firstObjectReturnedByArrow,
6
+ hasParseDiagnostics,
7
+ heritageCall,
8
+ nodeName,
9
+ propertyName,
10
+ sourceFileFor,
11
+ } from "./sourceAst";
12
+ import { findNamedImport } from "./sourceImports";
13
+ import { spliceText } from "./sourceText";
14
+
15
+ interface ArrayInsertionLocator {
16
+ projectionStart: number;
17
+ projectionEnd: number;
18
+ fields: string[];
19
+ }
20
+
21
+ export interface AkanConstantFieldStructure {
22
+ name: string;
23
+ expressionBuilder: string | null;
24
+ }
25
+
26
+ export interface AkanConstantStructure {
27
+ parseValid: boolean;
28
+ inputObjectFound: boolean;
29
+ builderName: string | null;
30
+ fields: AkanConstantFieldStructure[];
31
+ lightProjectionFields: string[];
32
+ baseImports: string[];
33
+ }
34
+
35
+ const findConstantInputObject = (source: ts.SourceFile, className: string): ObjectInsertionLocator | null => {
36
+ let locator: ObjectInsertionLocator | null = null;
37
+ const visit = (node: ts.Node) => {
38
+ if (locator) return;
39
+ if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
40
+ ts.forEachChild(node, visit);
41
+ return;
42
+ }
43
+ const viaCall = heritageCall(node);
44
+ const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
45
+ const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
46
+ if (objectLiteral) locator = locatedObject(source, objectLiteral);
47
+ };
48
+ ts.forEachChild(source, visit);
49
+ return locator;
50
+ };
51
+
52
+ const findLightProjectionArray = (source: ts.SourceFile, moduleClassName: string): ArrayInsertionLocator | null => {
53
+ let locator: ArrayInsertionLocator | null = null;
54
+ const visit = (node: ts.Node) => {
55
+ if (locator) return;
56
+ if (!ts.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
57
+ ts.forEachChild(node, visit);
58
+ return;
59
+ }
60
+ const viaCall = heritageCall(node);
61
+ const projectionArg = viaCall?.arguments.find((arg) => {
62
+ const expression = ts.isAsExpression(arg) ? arg.expression : arg;
63
+ return ts.isArrayLiteralExpression(expression);
64
+ });
65
+ const arrayLiteral = projectionArg
66
+ ? ts.isAsExpression(projectionArg)
67
+ ? projectionArg.expression
68
+ : projectionArg
69
+ : null;
70
+ if (!projectionArg || !arrayLiteral || !ts.isArrayLiteralExpression(arrayLiteral)) return;
71
+ locator = {
72
+ projectionStart: projectionArg.getStart(source),
73
+ projectionEnd: projectionArg.getEnd(),
74
+ fields: arrayLiteral.elements
75
+ .map((element) => (ts.isStringLiteralLike(element) ? element.text : null))
76
+ .filter((field): field is string => field !== null),
77
+ };
78
+ };
79
+ ts.forEachChild(source, visit);
80
+ return locator;
81
+ };
82
+
83
+ const fieldExpressionBuilder = (property: ts.ObjectLiteralElementLike) => {
84
+ if (!ts.isPropertyAssignment(property)) return null;
85
+ const initializer = ts.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
86
+ if (!ts.isCallExpression(initializer)) return null;
87
+ return expressionName(initializer.expression);
88
+ };
89
+
90
+ export const viaBuilderParameterName = (content: string, className: string) => {
91
+ const source = sourceFileFor("constant.ts", content);
92
+ let builderName: string | null = null;
93
+ const visit = (node: ts.Node) => {
94
+ if (builderName !== null) return;
95
+ if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
96
+ ts.forEachChild(node, visit);
97
+ return;
98
+ }
99
+ const viaCall = heritageCall(node);
100
+ const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
101
+ if (callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
102
+ builderName = nodeName(callback.parameters[0]?.name);
103
+ }
104
+ };
105
+ ts.forEachChild(source, visit);
106
+ return builderName;
107
+ };
108
+
109
+ export const inspectConstantStructure = (
110
+ content: string,
111
+ className: string,
112
+ moduleClassName: string,
113
+ ): AkanConstantStructure => {
114
+ const source = sourceFileFor("constant.ts", content);
115
+ const inputObject = findConstantInputObject(source, className);
116
+ const lightProjection = findLightProjectionArray(source, moduleClassName);
117
+ const baseImport = findNamedImport(source, "akanjs/base");
118
+ const fields: AkanConstantFieldStructure[] = [];
119
+ if (inputObject) {
120
+ const visit = (node: ts.Node) => {
121
+ if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
122
+ ts.forEachChild(node, visit);
123
+ return;
124
+ }
125
+ const viaCall = heritageCall(node);
126
+ const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
127
+ const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
128
+ if (!objectLiteral) return;
129
+ fields.push(
130
+ ...objectLiteral.properties
131
+ .map((property): AkanConstantFieldStructure | null => {
132
+ const name = propertyName(property);
133
+ if (!name) return null;
134
+ return { name, expressionBuilder: fieldExpressionBuilder(property) };
135
+ })
136
+ .filter((field): field is AkanConstantFieldStructure => field !== null),
137
+ );
138
+ };
139
+ ts.forEachChild(source, visit);
140
+ }
141
+ return {
142
+ parseValid: !hasParseDiagnostics(source),
143
+ inputObjectFound: inputObject !== null,
144
+ builderName: viaBuilderParameterName(content, className),
145
+ fields,
146
+ lightProjectionFields: lightProjection?.fields ?? [],
147
+ baseImports: baseImport?.names ?? [],
148
+ };
149
+ };
150
+
151
+ export const insertIntoObject = (content: string, className: string, line: string) => {
152
+ const fieldName = /^([A-Za-z_$][\w$]*)\s*:/.exec(line.trim())?.[1];
153
+ if (!fieldName) return null;
154
+ const source = sourceFileFor("constant.ts", content);
155
+ const locator = findConstantInputObject(source, className);
156
+ if (!locator) return null;
157
+ return insertOrderedFieldLine(content, locator, fieldName, line, { fieldIndent: " ", closingIndent: "" });
158
+ };
159
+
160
+ export const insertLightProjectionField = (content: string, moduleClassName: string, fieldName: string) => {
161
+ const source = sourceFileFor("constant.ts", content);
162
+ const locator = findLightProjectionArray(source, moduleClassName);
163
+ if (!locator) return null;
164
+ if (locator.fields.includes(fieldName)) return content;
165
+ const nextFields = [...locator.fields, fieldName];
166
+ const nextArray =
167
+ nextFields.length === 0
168
+ ? "[] as const"
169
+ : `[\n${nextFields.map((field) => ` ${JSON.stringify(field)},`).join("\n")}\n] as const`;
170
+ return spliceText(content, locator.projectionStart, locator.projectionEnd, nextArray);
171
+ };
172
+
173
+ export const insertEnumClass = (content: string, enumClassName: string, enumName: string, values: string[]) => {
174
+ if (content.includes(`export class ${enumClassName} extends enumOf`)) return content;
175
+ const enumClass = `export class ${enumClassName} extends enumOf("${enumName}", [\n${values
176
+ .map((value) => ` ${JSON.stringify(value)},`)
177
+ .join("\n")}\n] as const) {}\n\n`;
178
+ const firstClassIndex = content.indexOf("export class ");
179
+ if (firstClassIndex < 0) return `${content}\n${enumClass}`;
180
+ return `${content.slice(0, firstClassIndex)}${enumClass}${content.slice(firstClassIndex)}`;
181
+ };
182
+
183
+ export const hasConstantInputField = (content: string, className: string, fieldName: string) => {
184
+ const source = sourceFileFor("constant.ts", content);
185
+ if (hasParseDiagnostics(source)) return false;
186
+ return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
187
+ };
@@ -0,0 +1,184 @@
1
+ import ts from "typescript";
2
+ import { bilingualDescriptionForField, bilingualLabelForField, titleize } from "./fieldLabel";
3
+ import { insertOrderedFieldLine, locatedObject, type ObjectInsertionLocator } from "./fieldOrder";
4
+ import {
5
+ callExpressionName,
6
+ expressionName,
7
+ firstObjectReturnedByArrow,
8
+ hasParseDiagnostics,
9
+ sourceFileFor,
10
+ } from "./sourceAst";
11
+ import { lineStartAt, spliceText } from "./sourceText";
12
+
13
+ export interface AkanDictionaryStructure {
14
+ parseValid: boolean;
15
+ modelObjectFound: boolean;
16
+ chainOrderValid: boolean;
17
+ chainMethods: string[];
18
+ fields: string[];
19
+ }
20
+
21
+ interface DictionaryModelLocator extends ObjectInsertionLocator {
22
+ chainMethods: string[];
23
+ }
24
+
25
+ const chainMethodsForCall = (node: ts.Expression): string[] => {
26
+ if (ts.isAsExpression(node) || ts.isParenthesizedExpression(node)) return chainMethodsForCall(node.expression);
27
+ if (!ts.isCallExpression(node)) return [];
28
+ if (ts.isPropertyAccessExpression(node.expression)) {
29
+ return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
30
+ }
31
+ const name = expressionName(node.expression);
32
+ return name ? [name] : [];
33
+ };
34
+
35
+ const outermostFluentCall = (node: ts.CallExpression) => {
36
+ let current: ts.CallExpression = node;
37
+ while (
38
+ ts.isPropertyAccessExpression(current.parent) &&
39
+ current.parent.expression === current &&
40
+ ts.isCallExpression(current.parent.parent) &&
41
+ current.parent.parent.expression === current.parent
42
+ ) {
43
+ current = current.parent.parent;
44
+ }
45
+ return current;
46
+ };
47
+
48
+ const protectedDictionaryChainOrder = ["model", "slice", "enum", "error", "translate"] as const;
49
+
50
+ const dictionaryChainOrderValid = (chainMethods: readonly string[]) => {
51
+ const protectedOrder = new Map(protectedDictionaryChainOrder.map((method, index) => [method, index]));
52
+ let lastOrder = -1;
53
+ for (const method of chainMethods) {
54
+ const order = protectedOrder.get(method as (typeof protectedDictionaryChainOrder)[number]);
55
+ if (order === undefined) continue;
56
+ if (order < lastOrder) return false;
57
+ lastOrder = order;
58
+ }
59
+ return true;
60
+ };
61
+
62
+ const findDictionaryModelObject = (source: ts.SourceFile, moduleClassName: string) =>
63
+ findDictionaryStageObject(source, "model", moduleClassName);
64
+
65
+ const findDictionaryStageObject = (
66
+ source: ts.SourceFile,
67
+ stage: string,
68
+ typeName: string,
69
+ ): DictionaryModelLocator | null => {
70
+ let locator: DictionaryModelLocator | null = null;
71
+ const visit = (node: ts.Node) => {
72
+ if (locator) return;
73
+ if (!ts.isCallExpression(node) || callExpressionName(node) !== stage) {
74
+ ts.forEachChild(node, visit);
75
+ return;
76
+ }
77
+ const typeArgument = node.typeArguments?.[0];
78
+ if (!typeArgument || typeArgument.getText(source) !== typeName) {
79
+ ts.forEachChild(node, visit);
80
+ return;
81
+ }
82
+ const callback = node.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
83
+ const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
84
+ if (objectLiteral) {
85
+ locator = {
86
+ ...locatedObject(source, objectLiteral),
87
+ chainMethods: chainMethodsForCall(outermostFluentCall(node)),
88
+ };
89
+ }
90
+ };
91
+ ts.forEachChild(source, visit);
92
+ return locator;
93
+ };
94
+
95
+ export const inspectDictionaryStructure = (content: string, moduleClassName: string): AkanDictionaryStructure => {
96
+ const source = sourceFileFor("dictionary.ts", content);
97
+ const modelObject = findDictionaryModelObject(source, moduleClassName);
98
+ return {
99
+ parseValid: !hasParseDiagnostics(source),
100
+ modelObjectFound: modelObject !== null,
101
+ chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
102
+ chainMethods: modelObject?.chainMethods ?? [],
103
+ fields: modelObject?.fields.map((field) => field.name) ?? [],
104
+ };
105
+ };
106
+
107
+ const dictionaryModelFieldLine = (fieldName: string) => {
108
+ const label = bilingualLabelForField(fieldName);
109
+ const desc = bilingualDescriptionForField(fieldName);
110
+ return `${fieldName}: t([${JSON.stringify(label.en)}, ${JSON.stringify(label.ko)}]).desc([${JSON.stringify(
111
+ desc.en,
112
+ )}, ${JSON.stringify(desc.ko)}]),`;
113
+ };
114
+
115
+ export const insertDictionaryModelField = (content: string, moduleClassName: string, fieldName: string) => {
116
+ const source = sourceFileFor("dictionary.ts", content);
117
+ const locator = findDictionaryModelObject(source, moduleClassName);
118
+ if (!locator) return null;
119
+ return insertOrderedFieldLine(content, locator, fieldName, dictionaryModelFieldLine(fieldName), {
120
+ fieldIndent: " ",
121
+ closingIndent: " ",
122
+ });
123
+ };
124
+
125
+ export const hasDictionaryModelField = (content: string, moduleClassName: string, fieldName: string) => {
126
+ const source = sourceFileFor("dictionary.ts", content);
127
+ if (hasParseDiagnostics(source)) return false;
128
+ return findDictionaryModelObject(source, moduleClassName)?.fields.some((field) => field.name === fieldName) ?? false;
129
+ };
130
+
131
+ export const hasDictionaryEndpointEntry = (content: string, moduleClassName: string, entryName: string) => {
132
+ const source = sourceFileFor("dictionary.ts", content);
133
+ return (
134
+ findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`)?.fields.some(
135
+ (field) => field.name === entryName,
136
+ ) ?? false
137
+ );
138
+ };
139
+
140
+ export const insertDictionaryEndpointEntry = (
141
+ content: string,
142
+ moduleClassName: string,
143
+ entryName: string,
144
+ entryText: string,
145
+ ) => {
146
+ const source = sourceFileFor("dictionary.ts", content);
147
+ const locator = findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`);
148
+ if (!locator) return null;
149
+ return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
150
+ };
151
+
152
+ const dictionaryChainOf = (node: ts.Node): ts.CallExpression | undefined => {
153
+ if (
154
+ ts.isCallExpression(node) &&
155
+ outermostFluentCall(node) === node &&
156
+ protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method))
157
+ )
158
+ return node;
159
+ return ts.forEachChild(node, dictionaryChainOf);
160
+ };
161
+
162
+ const chainMethodNames = (call: ts.Expression): ts.Identifier[] => {
163
+ if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression)) return [];
164
+ const name = call.expression.name;
165
+ return [...chainMethodNames(call.expression.expression), ...(ts.isIdentifier(name) ? [name] : [])];
166
+ };
167
+
168
+ //* Located on the parsed chain, never by text search: the sample dictionary's header comment mentions `.error()`.
169
+ export const insertDictionaryEnum = (content: string, enumClassName: string, enumName: string, values: string[]) => {
170
+ if (content.includes(`.enum<${enumClassName}>("${enumName}"`)) return content;
171
+ const source = sourceFileFor("dictionary.ts", content);
172
+ if (hasParseDiagnostics(source)) return null;
173
+ const chain = dictionaryChainOf(source);
174
+ if (!chain) return null;
175
+ const enumBlock = ` .enum<${enumClassName}>("${enumName}", (t) => ({\n${values
176
+ .map((value) => ` ${value}: t([${JSON.stringify(titleize(value))}, ${JSON.stringify(titleize(value))}]),`)
177
+ .join("\n")}\n }))\n`;
178
+ const later = chainMethodNames(chain).find((name) => name.text === "error" || name.text === "translate");
179
+ if (!later) return spliceText(content, chain.getEnd(), chain.getEnd(), `\n${enumBlock.trimEnd()}`);
180
+ const dot = content.lastIndexOf(".", later.getStart(source));
181
+ const lineStart = lineStartAt(content, dot);
182
+ if (content.slice(lineStart, dot).trim() === "") return spliceText(content, lineStart, lineStart, enumBlock);
183
+ return spliceText(content, dot, dot, `\n${enumBlock}`);
184
+ };
@@ -1,18 +1,15 @@
1
1
  import { capitalize } from "akanjs/common";
2
2
  import ts from "typescript";
3
- import type { AkanModuleContext } from "../akanContext";
4
3
  import type { Sys, Workspace } from "../commandDecorators";
4
+ import type { AkanModuleContext } from "../context/akanContext";
5
5
  import { AppExecutor, LibExecutor } from "../executors";
6
6
  import { createWorkflowApplyReport, workflowCommandsForPlan } from "./artifacts";
7
+ import { inspectConstantStructure } from "./constantSource";
8
+ import { inspectDictionaryStructure } from "./dictionarySource";
9
+ import { normalizeFieldType } from "./fieldExpression";
10
+ import { insertionIndexForFieldOrder } from "./fieldOrder";
7
11
  import { buildAkanModuleContextIndex } from "./moduleIndex";
8
- import {
9
- insertionIndexForFieldOrder,
10
- inspectConstantStructure,
11
- inspectDictionaryStructure,
12
- moduleComponentName,
13
- moduleSourcePaths,
14
- normalizeFieldType,
15
- } from "./source";
12
+ import { moduleComponentName, moduleSourcePaths } from "./modulePaths";
16
13
  import type {
17
14
  PrimitiveChangedFile,
18
15
  PrimitiveGeneratedFile,
@@ -0,0 +1,153 @@
1
+ import type { WorkflowDiagnostic } from "./types";
2
+
3
+ export const normalizeFieldType = (typeName: string) => {
4
+ const normalizedTypes: Record<string, string> = {
5
+ string: "String",
6
+ boolean: "Boolean",
7
+ date: "Date",
8
+ int: "Int",
9
+ integer: "Int",
10
+ float: "Float",
11
+ double: "Float",
12
+ decimal: "Float",
13
+ };
14
+ return normalizedTypes[typeName.toLowerCase()] ?? typeName;
15
+ };
16
+
17
+ export type FieldDefaultValue = string | number | boolean | null;
18
+
19
+ const numericDefault = (typeName: "Int" | "Float", rawDefault: FieldDefaultValue): string | null => {
20
+ if (typeof rawDefault === "number") {
21
+ if (!Number.isFinite(rawDefault)) return null;
22
+ if (typeName === "Int" && !Number.isInteger(rawDefault)) return null;
23
+ return String(rawDefault);
24
+ }
25
+ if (typeof rawDefault !== "string") return null;
26
+ const trimmed = rawDefault.trim();
27
+ if (!trimmed || !Number.isFinite(Number(trimmed))) return null;
28
+ if (typeName === "Int" && !/^-?\d+$/.test(trimmed)) return null;
29
+ return trimmed;
30
+ };
31
+
32
+ const booleanDefault = (rawDefault: FieldDefaultValue): string | null => {
33
+ if (typeof rawDefault === "boolean") return String(rawDefault);
34
+ if (typeof rawDefault !== "string") return null;
35
+ const lowered = rawDefault.trim().toLowerCase();
36
+ return lowered === "true" || lowered === "false" ? lowered : null;
37
+ };
38
+
39
+ const dateDefault = (rawDefault: FieldDefaultValue): string | null => {
40
+ if (typeof rawDefault === "number" && Number.isFinite(rawDefault)) return `() => dayjs(${rawDefault})`;
41
+ if (typeof rawDefault !== "string") return null;
42
+ const trimmed = rawDefault.trim();
43
+ if (!trimmed) return null;
44
+ if (trimmed === "now") return "() => dayjs()";
45
+ if (!Number.isNaN(Date.parse(trimmed))) return `() => dayjs(${JSON.stringify(trimmed)})`;
46
+ return null;
47
+ };
48
+
49
+ export const coerceFieldDefault = (
50
+ typeName: string,
51
+ defaultValue?: FieldDefaultValue,
52
+ options: { enumValues?: readonly string[] | null } = {},
53
+ ): { expression: string | null; diagnostic?: WorkflowDiagnostic; normalized: boolean; normalizedType: string } => {
54
+ const normalizedType = typeName.toLowerCase() === "enum" ? "enum" : normalizeFieldType(typeName);
55
+ if (defaultValue === undefined || defaultValue === null || defaultValue === "") {
56
+ return { expression: null, normalized: false, normalizedType };
57
+ }
58
+ if (normalizedType === "Int" || normalizedType === "Float") {
59
+ const expression = numericDefault(normalizedType, defaultValue);
60
+ if (expression !== null) return { expression, normalized: typeof defaultValue === "string", normalizedType };
61
+ return {
62
+ expression: null,
63
+ normalized: false,
64
+ normalizedType,
65
+ diagnostic: {
66
+ severity: "error",
67
+ code: "primitive-default-value-invalid",
68
+ input: "default",
69
+ failureScope: "source-change",
70
+ message: `Default value for ${normalizedType} must be a numeric literal. Received: ${JSON.stringify(defaultValue)}.`,
71
+ },
72
+ };
73
+ }
74
+ if (normalizedType === "Boolean") {
75
+ const expression = booleanDefault(defaultValue);
76
+ if (expression !== null) return { expression, normalized: typeof defaultValue === "string", normalizedType };
77
+ return {
78
+ expression: null,
79
+ normalized: false,
80
+ normalizedType,
81
+ diagnostic: {
82
+ severity: "error",
83
+ code: "primitive-default-value-invalid",
84
+ input: "default",
85
+ failureScope: "source-change",
86
+ message: `Default value for Boolean must be true or false. Received: ${JSON.stringify(defaultValue)}.`,
87
+ },
88
+ };
89
+ }
90
+ if (normalizedType === "Date") {
91
+ const expression = dateDefault(defaultValue);
92
+ if (expression !== null) return { expression, normalized: true, normalizedType };
93
+ return {
94
+ expression: null,
95
+ normalized: false,
96
+ normalizedType,
97
+ diagnostic: {
98
+ severity: "error",
99
+ code: "primitive-default-value-invalid",
100
+ input: "default",
101
+ failureScope: "source-change",
102
+ message: `Default value for Date must be "now", a timestamp, or a parseable date string. Received: ${JSON.stringify(
103
+ defaultValue,
104
+ )}.`,
105
+ },
106
+ };
107
+ }
108
+ if (normalizedType === "enum") {
109
+ if (typeof defaultValue === "string" && options.enumValues?.includes(defaultValue)) {
110
+ return { expression: JSON.stringify(defaultValue), normalized: false, normalizedType };
111
+ }
112
+ return {
113
+ expression: null,
114
+ normalized: false,
115
+ normalizedType,
116
+ diagnostic: {
117
+ severity: "error",
118
+ code: "primitive-default-value-invalid",
119
+ input: "default",
120
+ failureScope: "source-change",
121
+ message: `Default value for enum must be one of: ${(options.enumValues ?? []).join(", ")}. Received: ${JSON.stringify(
122
+ defaultValue,
123
+ )}.`,
124
+ },
125
+ };
126
+ }
127
+ return {
128
+ expression: JSON.stringify(String(defaultValue)),
129
+ normalized: typeof defaultValue !== "string",
130
+ normalizedType,
131
+ };
132
+ };
133
+
134
+ export const fieldExpression = (
135
+ typeName: string,
136
+ defaultValue?: FieldDefaultValue,
137
+ options: { enumValues?: readonly string[] | null; builderName?: string } = {},
138
+ ) => {
139
+ const typeExpression = normalizeFieldType(typeName);
140
+ const defaultExpression = coerceFieldDefault(
141
+ options.enumValues ? "enum" : typeExpression,
142
+ defaultValue,
143
+ options,
144
+ ).expression;
145
+ const defaultOption = defaultExpression ? `, { default: ${defaultExpression} }` : "";
146
+ return `${options.builderName ?? "field"}(${typeExpression}${defaultOption})`;
147
+ };
148
+
149
+ export const parseValues = (value: string | null) =>
150
+ value
151
+ ?.split(",")
152
+ .map((item) => item.trim())
153
+ .filter(Boolean) ?? [];
@@ -0,0 +1,61 @@
1
+ import { lowerlize } from "akanjs/common";
2
+
3
+ export const titleize = (value: string) =>
4
+ value
5
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
6
+ .replace(/[-_]+/g, " ")
7
+ .replace(/\b\w/g, (char) => char.toUpperCase());
8
+
9
+ const koLabels: Record<string, string> = {
10
+ amount: "금액",
11
+ budget: "예산",
12
+ category: "카테고리",
13
+ content: "내용",
14
+ count: "개수",
15
+ createdAt: "생성일",
16
+ date: "날짜",
17
+ description: "설명",
18
+ due: "마감일",
19
+ dueAt: "마감일",
20
+ email: "이메일",
21
+ enabled: "활성화",
22
+ endAt: "종료일",
23
+ id: "ID",
24
+ name: "이름",
25
+ owner: "담당자",
26
+ priority: "우선순위",
27
+ project: "프로젝트",
28
+ rating: "평점",
29
+ startAt: "시작일",
30
+ status: "상태",
31
+ title: "제목",
32
+ updatedAt: "수정일",
33
+ };
34
+
35
+ const splitFieldWords = (fieldName: string) =>
36
+ fieldName
37
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
38
+ .replace(/[-_]+/g, " ")
39
+ .split(/\s+/)
40
+ .map((word) => word.trim())
41
+ .filter(Boolean);
42
+
43
+ const koLabelForField = (fieldName: string) => {
44
+ if (koLabels[fieldName]) return koLabels[fieldName];
45
+ const words = splitFieldWords(fieldName);
46
+ const translated = words.map((word) => koLabels[word] ?? koLabels[lowerlize(word)] ?? null);
47
+ return translated.every(Boolean) ? translated.join(" ") : null;
48
+ };
49
+
50
+ export const bilingualLabelForField = (fieldName: string) => {
51
+ const en = titleize(fieldName);
52
+ return { en, ko: koLabelForField(fieldName) ?? en };
53
+ };
54
+
55
+ export const bilingualDescriptionForField = (fieldName: string) => {
56
+ const label = bilingualLabelForField(fieldName);
57
+ return {
58
+ en: `Enter ${label.en.toLowerCase()}.`,
59
+ ko: `${label.ko} 값을 입력합니다.`,
60
+ };
61
+ };