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

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 +350 -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 +13 -2
  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
@@ -1,1105 +1,50 @@
1
- import { lowerlize } from "akanjs/common";
2
- import ts from "typescript";
3
- import type { Sys } from "../commandDecorators";
4
- import { generatedFilePathsForTarget } from "./artifacts";
5
- import {
6
- callExpressionName,
7
- expressionName,
8
- firstObjectReturnedByArrow,
9
- heritageCall,
10
- nodeName,
11
- propertyName,
12
- sourceFileFor,
13
- } from "./sourceAst";
14
- import type {
15
- PrimitiveChangedFile,
16
- PrimitiveFileMap,
17
- PrimitiveGeneratedFile,
18
- PrimitiveNextAction,
19
- PrimitiveValidationCommand,
20
- PrimitiveWriteReport,
21
- WorkflowDiagnostic,
22
- } from "./types";
23
-
24
- export const getSysRoot = (sys: Sys) => `${sys.type}s/${sys.name}`;
25
-
26
- export const sourceFile = (sys: Sys, path: string, action: PrimitiveChangedFile["action"], reason: string) => ({
27
- path: `${getSysRoot(sys)}/${path}`,
28
- action,
29
- reason,
30
- });
31
-
32
- export const moduleComponentName = (moduleName: string) =>
33
- moduleName
34
- .replace(/[-_]+/g, " ")
35
- .replace(/(?<=^|\s)[a-zA-Z0-9]/g, (char) => char.toUpperCase())
36
- .replace(/\s+/g, "");
37
-
38
- export const moduleSourcePaths = (moduleName: string) => {
39
- const componentName = moduleComponentName(moduleName);
40
- return {
41
- abstract: `lib/${moduleName}/${moduleName}.abstract.md`,
42
- constant: `lib/${moduleName}/${moduleName}.constant.ts`,
43
- dictionary: `lib/${moduleName}/${moduleName}.dictionary.ts`,
44
- document: `lib/${moduleName}/${moduleName}.document.ts`,
45
- service: `lib/${moduleName}/${moduleName}.service.ts`,
46
- signal: `lib/${moduleName}/${moduleName}.signal.ts`,
47
- store: `lib/${moduleName}/${moduleName}.store.ts`,
48
- template: `lib/${moduleName}/${componentName}.Template.tsx`,
49
- unit: `lib/${moduleName}/${componentName}.Unit.tsx`,
50
- util: `lib/${moduleName}/${componentName}.Util.tsx`,
51
- view: `lib/${moduleName}/${componentName}.View.tsx`,
52
- zone: `lib/${moduleName}/${componentName}.Zone.tsx`,
53
- };
54
- };
55
-
56
- export const generatedFilesForSync = (sys: Sys, reason = "Generated files may change after sync.") =>
57
- generatedFilePathsForTarget(getSysRoot(sys), reason);
58
-
59
- export const validationCommandsForTarget = (target: string) =>
60
- [
61
- { command: `akan verify ${target}`, reason: "Sync, lint, typecheck and build the target in one run." },
62
- ] satisfies PrimitiveValidationCommand[];
63
-
64
- export const nextActionsForTarget = (target: string) =>
65
- [
66
- { command: `akan verify ${target}`, reason: "Refresh generated files and validate the target in one run." },
67
- ] satisfies PrimitiveNextAction[];
68
-
69
- export const createPrimitiveWriteReport = ({
70
- command,
71
- status,
72
- changedFiles = [],
73
- generatedFiles = [],
74
- validationCommands = [],
75
- diagnostics = [],
76
- nextActions = [],
77
- }: Omit<PrimitiveWriteReport, "schemaVersion" | "status"> & {
78
- status?: PrimitiveWriteReport["status"];
79
- }): PrimitiveWriteReport => ({
80
- schemaVersion: 1,
81
- command,
82
- status: status ?? (diagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed"),
83
- changedFiles,
84
- generatedFiles,
85
- validationCommands,
86
- diagnostics,
87
- nextActions,
88
- });
89
-
90
- export const createPassedPrimitiveReport = ({
91
- command,
92
- changedFiles,
93
- generatedFiles,
94
- target,
95
- nextActions,
96
- }: {
97
- command: string;
98
- changedFiles: PrimitiveChangedFile[];
99
- generatedFiles?: PrimitiveGeneratedFile[];
100
- target: string;
101
- nextActions?: PrimitiveNextAction[];
102
- }) =>
103
- createPrimitiveWriteReport({
104
- command,
105
- changedFiles,
106
- generatedFiles: generatedFiles ?? [],
107
- validationCommands: validationCommandsForTarget(target),
108
- diagnostics: [],
109
- nextActions: nextActions ?? nextActionsForTarget(target),
110
- });
111
-
112
- export const scalarChangedFiles = (sys: Sys, scalarName: string, files: PrimitiveFileMap) =>
113
- Object.values(files).map((file) =>
114
- sourceFile(sys, `lib/__scalar/${scalarName}/${file.filename}`, "create", "Scalar source file was created."),
115
- );
116
-
117
- export const titleize = (value: string) =>
118
- value
119
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
120
- .replace(/[-_]+/g, " ")
121
- .replace(/\b\w/g, (char) => char.toUpperCase());
122
-
123
- const koLabels: Record<string, string> = {
124
- amount: "금액",
125
- budget: "예산",
126
- category: "카테고리",
127
- content: "내용",
128
- count: "개수",
129
- createdAt: "생성일",
130
- date: "날짜",
131
- description: "설명",
132
- due: "마감일",
133
- dueAt: "마감일",
134
- email: "이메일",
135
- enabled: "활성화",
136
- endAt: "종료일",
137
- id: "ID",
138
- name: "이름",
139
- owner: "담당자",
140
- priority: "우선순위",
141
- project: "프로젝트",
142
- rating: "평점",
143
- startAt: "시작일",
144
- status: "상태",
145
- title: "제목",
146
- updatedAt: "수정일",
147
- };
148
-
149
- const splitFieldWords = (fieldName: string) =>
150
- fieldName
151
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
152
- .replace(/[-_]+/g, " ")
153
- .split(/\s+/)
154
- .map((word) => word.trim())
155
- .filter(Boolean);
156
-
157
- const koLabelForField = (fieldName: string) => {
158
- if (koLabels[fieldName]) return koLabels[fieldName];
159
- const words = splitFieldWords(fieldName);
160
- const translated = words.map((word) => koLabels[word] ?? koLabels[lowerlize(word)] ?? null);
161
- return translated.every(Boolean) ? translated.join(" ") : null;
162
- };
163
-
164
- export const bilingualLabelForField = (fieldName: string) => {
165
- const en = titleize(fieldName);
166
- return { en, ko: koLabelForField(fieldName) ?? en };
167
- };
168
-
169
- export const bilingualDescriptionForField = (fieldName: string) => {
170
- const label = bilingualLabelForField(fieldName);
171
- return {
172
- en: `Enter ${label.en.toLowerCase()}.`,
173
- ko: `${label.ko} 값을 입력합니다.`,
174
- };
175
- };
176
-
177
- export const normalizeFieldType = (typeName: string) => {
178
- const normalizedTypes: Record<string, string> = {
179
- string: "String",
180
- boolean: "Boolean",
181
- date: "Date",
182
- int: "Int",
183
- integer: "Int",
184
- float: "Float",
185
- double: "Float",
186
- decimal: "Float",
187
- };
188
- return normalizedTypes[typeName.toLowerCase()] ?? typeName;
189
- };
190
-
191
- //? Biome's organizeImports order: case-insensitive, an uppercase name before its lowercase twin.
192
- const importOrder = (a: string, b: string) => {
193
- const [lowerA, lowerB] = [a.toLowerCase(), b.toLowerCase()];
194
- if (lowerA !== lowerB) return lowerA < lowerB ? -1 : 1;
195
- return a < b ? -1 : a > b ? 1 : 0;
196
- };
197
-
198
- export const ensureNamedImport = (content: string, moduleSpecifier: string, name: string) => {
199
- const source = sourceFileFor("source.ts", content);
200
- const namedImport = findNamedImport(source, moduleSpecifier, { valueOnly: true });
201
- if (!namedImport) return ensureImportDeclaration(content, moduleSpecifier, `{ ${name} }`);
202
- if (namedImport.names.includes(name)) return content;
203
- const nextElements = [...namedImport.elements, { name, text: name }].sort((a, b) => importOrder(a.name, b.name));
204
- return spliceText(
205
- content,
206
- namedImport.namedBindingsStart,
207
- namedImport.namedBindingsEnd,
208
- `{ ${nextElements.map((element) => element.text).join(", ")} }`,
209
- );
210
- };
211
-
212
- export const ensureImportDeclaration = (content: string, moduleSpecifier: string, clause: string) => {
213
- const line = `import ${clause} from "${moduleSpecifier}";`;
214
- if (content.includes(line)) return content;
215
- const source = sourceFileFor("source.ts", content);
216
- const imports = source.statements
217
- .filter((statement): statement is ts.ImportDeclaration => ts.isImportDeclaration(statement))
218
- .flatMap((statement) =>
219
- ts.isStringLiteral(statement.moduleSpecifier)
220
- ? [{ specifier: statement.moduleSpecifier.text, start: statement.getStart(source), end: statement.getEnd() }]
221
- : [],
222
- );
223
- const isRelative = (specifier: string) => specifier.startsWith(".");
224
- const peers = imports.filter((entry) => isRelative(entry.specifier) === isRelative(moduleSpecifier));
225
- const before = peers.find((entry) => importOrder(entry.specifier, moduleSpecifier) > 0);
226
- if (before) {
227
- const insertAt = lineStartAt(content, before.start);
228
- return spliceText(content, insertAt, insertAt, `${line}\n`);
229
- }
230
- const after = peers.at(-1) ?? (isRelative(moduleSpecifier) ? imports.at(-1) : undefined);
231
- if (after) {
232
- const insertAt = lineEndAt(content, after.end);
233
- return spliceText(content, insertAt, insertAt, peers.length ? `${line}\n` : `\n${line}\n`);
234
- }
235
- const insertAt = imports[0] ? lineStartAt(content, imports[0].start) : 0;
236
- return spliceText(content, insertAt, insertAt, `${line}\n\n`);
237
- };
238
-
239
- export const ensureBaseImport = (content: string, name: string) => ensureNamedImport(content, "akanjs/base", name);
240
-
241
- export const ensureBaseTypeImport = (content: string, typeName: string) => {
242
- if (typeName !== "Int" && typeName !== "Float") return content;
243
- return ensureBaseImport(content, typeName);
244
- };
245
-
246
- export type FieldDefaultValue = string | number | boolean | null;
247
-
248
- const numericDefault = (typeName: "Int" | "Float", rawDefault: FieldDefaultValue): string | null => {
249
- if (typeof rawDefault === "number") {
250
- if (!Number.isFinite(rawDefault)) return null;
251
- if (typeName === "Int" && !Number.isInteger(rawDefault)) return null;
252
- return String(rawDefault);
253
- }
254
- if (typeof rawDefault !== "string") return null;
255
- const trimmed = rawDefault.trim();
256
- if (!trimmed || !Number.isFinite(Number(trimmed))) return null;
257
- if (typeName === "Int" && !/^-?\d+$/.test(trimmed)) return null;
258
- return trimmed;
259
- };
260
-
261
- const booleanDefault = (rawDefault: FieldDefaultValue): string | null => {
262
- if (typeof rawDefault === "boolean") return String(rawDefault);
263
- if (typeof rawDefault !== "string") return null;
264
- const lowered = rawDefault.trim().toLowerCase();
265
- return lowered === "true" || lowered === "false" ? lowered : null;
266
- };
267
-
268
- const dateDefault = (rawDefault: FieldDefaultValue): string | null => {
269
- if (typeof rawDefault === "number" && Number.isFinite(rawDefault)) return `() => dayjs(${rawDefault})`;
270
- if (typeof rawDefault !== "string") return null;
271
- const trimmed = rawDefault.trim();
272
- if (!trimmed) return null;
273
- if (trimmed === "now") return "() => dayjs()";
274
- if (!Number.isNaN(Date.parse(trimmed))) return `() => dayjs(${JSON.stringify(trimmed)})`;
275
- return null;
276
- };
277
-
278
- export const coerceFieldDefault = (
279
- typeName: string,
280
- defaultValue?: FieldDefaultValue,
281
- options: { enumValues?: readonly string[] | null } = {},
282
- ): { expression: string | null; diagnostic?: WorkflowDiagnostic; normalized: boolean; normalizedType: string } => {
283
- const normalizedType = typeName.toLowerCase() === "enum" ? "enum" : normalizeFieldType(typeName);
284
- if (defaultValue === undefined || defaultValue === null || defaultValue === "") {
285
- return { expression: null, normalized: false, normalizedType };
286
- }
287
- if (normalizedType === "Int" || normalizedType === "Float") {
288
- const expression = numericDefault(normalizedType, defaultValue);
289
- if (expression !== null) return { expression, normalized: typeof defaultValue === "string", normalizedType };
290
- return {
291
- expression: null,
292
- normalized: false,
293
- normalizedType,
294
- diagnostic: {
295
- severity: "error",
296
- code: "primitive-default-value-invalid",
297
- input: "default",
298
- failureScope: "source-change",
299
- message: `Default value for ${normalizedType} must be a numeric literal. Received: ${JSON.stringify(defaultValue)}.`,
300
- },
301
- };
302
- }
303
- if (normalizedType === "Boolean") {
304
- const expression = booleanDefault(defaultValue);
305
- if (expression !== null) return { expression, normalized: typeof defaultValue === "string", normalizedType };
306
- return {
307
- expression: null,
308
- normalized: false,
309
- normalizedType,
310
- diagnostic: {
311
- severity: "error",
312
- code: "primitive-default-value-invalid",
313
- input: "default",
314
- failureScope: "source-change",
315
- message: `Default value for Boolean must be true or false. Received: ${JSON.stringify(defaultValue)}.`,
316
- },
317
- };
318
- }
319
- if (normalizedType === "Date") {
320
- const expression = dateDefault(defaultValue);
321
- if (expression !== null) return { expression, normalized: true, normalizedType };
322
- return {
323
- expression: null,
324
- normalized: false,
325
- normalizedType,
326
- diagnostic: {
327
- severity: "error",
328
- code: "primitive-default-value-invalid",
329
- input: "default",
330
- failureScope: "source-change",
331
- message: `Default value for Date must be "now", a timestamp, or a parseable date string. Received: ${JSON.stringify(
332
- defaultValue,
333
- )}.`,
334
- },
335
- };
336
- }
337
- if (normalizedType === "enum") {
338
- if (typeof defaultValue === "string" && options.enumValues?.includes(defaultValue)) {
339
- return { expression: JSON.stringify(defaultValue), normalized: false, normalizedType };
340
- }
341
- return {
342
- expression: null,
343
- normalized: false,
344
- normalizedType,
345
- diagnostic: {
346
- severity: "error",
347
- code: "primitive-default-value-invalid",
348
- input: "default",
349
- failureScope: "source-change",
350
- message: `Default value for enum must be one of: ${(options.enumValues ?? []).join(", ")}. Received: ${JSON.stringify(
351
- defaultValue,
352
- )}.`,
353
- },
354
- };
355
- }
356
- return {
357
- expression: JSON.stringify(String(defaultValue)),
358
- normalized: typeof defaultValue !== "string",
359
- normalizedType,
360
- };
361
- };
362
-
363
- export const fieldExpression = (
364
- typeName: string,
365
- defaultValue?: FieldDefaultValue,
366
- options: { enumValues?: readonly string[] | null; builderName?: string } = {},
367
- ) => {
368
- const typeExpression = normalizeFieldType(typeName);
369
- const defaultExpression = coerceFieldDefault(
370
- options.enumValues ? "enum" : typeExpression,
371
- defaultValue,
372
- options,
373
- ).expression;
374
- const defaultOption = defaultExpression ? `, { default: ${defaultExpression} }` : "";
375
- return `${options.builderName ?? "field"}(${typeExpression}${defaultOption})`;
376
- };
377
-
378
- export const fieldOrderingPriority = [
379
- "id",
380
- "name",
381
- "title",
382
- "status",
383
- "category",
384
- "description",
385
- "content",
386
- "startAt",
387
- "dueAt",
388
- "endAt",
389
- "createdAt",
390
- "updatedAt",
391
- ] as const;
392
-
393
- type FieldOrderingName = string;
394
-
395
- interface LocatedField {
396
- name: FieldOrderingName;
397
- start: number;
398
- fullStart: number;
399
- end: number;
400
- }
401
-
402
- interface ObjectInsertionLocator {
403
- objectStart: number;
404
- objectEnd: number;
405
- fields: LocatedField[];
406
- }
407
-
408
- interface ArrayInsertionLocator {
409
- projectionStart: number;
410
- projectionEnd: number;
411
- fields: string[];
412
- }
413
-
414
- interface NamedImportLocator {
415
- names: string[];
416
- elements: { name: string; text: string }[];
417
- namedBindingsStart: number;
418
- namedBindingsEnd: number;
419
- }
420
-
421
- export interface AkanConstantFieldStructure {
422
- name: string;
423
- expressionBuilder: string | null;
424
- }
425
-
426
- export interface AkanConstantStructure {
427
- parseValid: boolean;
428
- inputObjectFound: boolean;
429
- builderName: string | null;
430
- fields: AkanConstantFieldStructure[];
431
- lightProjectionFields: string[];
432
- baseImports: string[];
433
- }
434
-
435
- export interface AkanDictionaryStructure {
436
- parseValid: boolean;
437
- modelObjectFound: boolean;
438
- chainOrderValid: boolean;
439
- chainMethods: string[];
440
- fields: string[];
441
- }
442
-
443
- const hasParseDiagnostics = (source: ts.SourceFile) =>
444
- ((source as ts.SourceFile & { parseDiagnostics?: readonly ts.Diagnostic[] }).parseDiagnostics ?? []).length > 0;
445
-
446
- const spliceText = (content: string, start: number, end: number, replacement: string) =>
447
- `${content.slice(0, start)}${replacement}${content.slice(end)}`;
448
-
449
- const lineStartAt = (content: string, position: number) => content.lastIndexOf("\n", Math.max(0, position - 1)) + 1;
450
-
451
- const lineEndAt = (content: string, position: number) => {
452
- const end = content.indexOf("\n", position);
453
- return end < 0 ? content.length : end + 1;
454
- };
455
-
456
- const lineIndentAt = (content: string, position: number) =>
457
- /^[ \t]*/.exec(content.slice(lineStartAt(content, position)))?.[0] ?? "";
458
-
459
- const locatedObject = (source: ts.SourceFile, objectLiteral: ts.ObjectLiteralExpression): ObjectInsertionLocator => ({
460
- objectStart: objectLiteral.getStart(source),
461
- objectEnd: objectLiteral.getEnd(),
462
- fields: objectLiteral.properties
463
- .map((property): LocatedField | null => {
464
- const name = propertyName(property);
465
- if (!name) return null;
466
- return {
467
- name,
468
- start: property.getStart(source),
469
- fullStart: property.getFullStart(),
470
- end: property.getEnd(),
471
- };
472
- })
473
- .filter((field): field is LocatedField => field !== null),
474
- });
475
-
476
- const findConstantInputObject = (source: ts.SourceFile, className: string): ObjectInsertionLocator | null => {
477
- let locator: ObjectInsertionLocator | null = null;
478
- const visit = (node: ts.Node) => {
479
- if (locator) return;
480
- if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
481
- ts.forEachChild(node, visit);
482
- return;
483
- }
484
- const viaCall = heritageCall(node);
485
- const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
486
- const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
487
- if (objectLiteral) locator = locatedObject(source, objectLiteral);
488
- };
489
- ts.forEachChild(source, visit);
490
- return locator;
491
- };
492
-
493
- interface DictionaryModelLocator extends ObjectInsertionLocator {
494
- chainMethods: string[];
495
- }
496
-
497
- const chainMethodsForCall = (node: ts.Expression): string[] => {
498
- if (ts.isAsExpression(node) || ts.isParenthesizedExpression(node)) return chainMethodsForCall(node.expression);
499
- if (!ts.isCallExpression(node)) return [];
500
- if (ts.isPropertyAccessExpression(node.expression)) {
501
- return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
502
- }
503
- const name = expressionName(node.expression);
504
- return name ? [name] : [];
505
- };
506
-
507
- const outermostFluentCall = (node: ts.CallExpression) => {
508
- let current: ts.CallExpression = node;
509
- while (
510
- ts.isPropertyAccessExpression(current.parent) &&
511
- current.parent.expression === current &&
512
- ts.isCallExpression(current.parent.parent) &&
513
- current.parent.parent.expression === current.parent
514
- ) {
515
- current = current.parent.parent;
516
- }
517
- return current;
518
- };
519
-
520
- const protectedDictionaryChainOrder = ["model", "slice", "enum", "error", "translate"] as const;
521
-
522
- const dictionaryChainOrderValid = (chainMethods: readonly string[]) => {
523
- const protectedOrder = new Map(protectedDictionaryChainOrder.map((method, index) => [method, index]));
524
- let lastOrder = -1;
525
- for (const method of chainMethods) {
526
- const order = protectedOrder.get(method as (typeof protectedDictionaryChainOrder)[number]);
527
- if (order === undefined) continue;
528
- if (order < lastOrder) return false;
529
- lastOrder = order;
530
- }
531
- return true;
532
- };
533
-
534
- const findDictionaryModelObject = (source: ts.SourceFile, moduleClassName: string) =>
535
- findDictionaryStageObject(source, "model", moduleClassName);
536
-
537
- const findDictionaryStageObject = (
538
- source: ts.SourceFile,
539
- stage: string,
540
- typeName: string,
541
- ): DictionaryModelLocator | null => {
542
- let locator: DictionaryModelLocator | null = null;
543
- const visit = (node: ts.Node) => {
544
- if (locator) return;
545
- if (!ts.isCallExpression(node) || callExpressionName(node) !== stage) {
546
- ts.forEachChild(node, visit);
547
- return;
548
- }
549
- const typeArgument = node.typeArguments?.[0];
550
- if (!typeArgument || typeArgument.getText(source) !== typeName) {
551
- ts.forEachChild(node, visit);
552
- return;
553
- }
554
- const callback = node.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
555
- const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
556
- if (objectLiteral) {
557
- locator = {
558
- ...locatedObject(source, objectLiteral),
559
- chainMethods: chainMethodsForCall(outermostFluentCall(node)),
560
- };
561
- }
562
- };
563
- ts.forEachChild(source, visit);
564
- return locator;
565
- };
566
-
567
- const findLightProjectionArray = (source: ts.SourceFile, moduleClassName: string): ArrayInsertionLocator | null => {
568
- let locator: ArrayInsertionLocator | null = null;
569
- const visit = (node: ts.Node) => {
570
- if (locator) return;
571
- if (!ts.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
572
- ts.forEachChild(node, visit);
573
- return;
574
- }
575
- const viaCall = heritageCall(node);
576
- const projectionArg = viaCall?.arguments.find((arg) => {
577
- const expression = ts.isAsExpression(arg) ? arg.expression : arg;
578
- return ts.isArrayLiteralExpression(expression);
579
- });
580
- const arrayLiteral = projectionArg
581
- ? ts.isAsExpression(projectionArg)
582
- ? projectionArg.expression
583
- : projectionArg
584
- : null;
585
- if (!projectionArg || !arrayLiteral || !ts.isArrayLiteralExpression(arrayLiteral)) return;
586
- locator = {
587
- projectionStart: projectionArg.getStart(source),
588
- projectionEnd: projectionArg.getEnd(),
589
- fields: arrayLiteral.elements
590
- .map((element) => (ts.isStringLiteralLike(element) ? element.text : null))
591
- .filter((field): field is string => field !== null),
592
- };
593
- };
594
- ts.forEachChild(source, visit);
595
- return locator;
596
- };
597
-
598
- const findNamedImport = (
599
- source: ts.SourceFile,
600
- moduleSpecifier: string,
601
- { valueOnly = false }: { valueOnly?: boolean } = {},
602
- ): NamedImportLocator | null => {
603
- for (const statement of source.statements) {
604
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
605
- if (statement.moduleSpecifier.text !== moduleSpecifier) continue;
606
- if (valueOnly && statement.importClause?.isTypeOnly) continue;
607
- const namedBindings = statement.importClause?.namedBindings;
608
- if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;
609
- return {
610
- names: namedBindings.elements.map((element) => element.name.text),
611
- elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
612
- namedBindingsStart: namedBindings.getStart(source),
613
- namedBindingsEnd: namedBindings.getEnd(),
614
- };
615
- }
616
- return null;
617
- };
618
-
619
- const fieldExpressionBuilder = (property: ts.ObjectLiteralElementLike) => {
620
- if (!ts.isPropertyAssignment(property)) return null;
621
- const initializer = ts.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
622
- if (!ts.isCallExpression(initializer)) return null;
623
- return expressionName(initializer.expression);
624
- };
625
-
626
- const priorityOf = (fieldName: string) => {
627
- const priority = (fieldOrderingPriority as readonly string[]).indexOf(fieldName);
628
- return priority < 0 ? null : priority;
629
- };
630
-
631
- export const insertionIndexForFieldOrder = (fieldNames: readonly string[], newFieldName: string) => {
632
- const newPriority = priorityOf(newFieldName);
633
- if (newPriority !== null) {
634
- const greaterPriorityIndex = fieldNames.findIndex((name) => {
635
- const existingPriority = priorityOf(name);
636
- return existingPriority !== null && existingPriority > newPriority;
637
- });
638
- if (greaterPriorityIndex >= 0) return greaterPriorityIndex;
639
-
640
- const lastPriorityIndex = fieldNames.reduce((lastIndex, name, index) => {
641
- const existingPriority = priorityOf(name);
642
- return existingPriority !== null ? index : lastIndex;
643
- }, -1);
644
- return lastPriorityIndex + 1;
645
- }
646
-
647
- const lastNonPriorityIndex = fieldNames.reduce(
648
- (lastIndex, name, index) => (priorityOf(name) === null ? index : lastIndex),
649
- -1,
650
- );
651
- return lastNonPriorityIndex >= 0 ? lastNonPriorityIndex + 1 : fieldNames.length;
652
- };
653
-
654
- const insertOrderedFieldLine = (
655
- content: string,
656
- locator: ObjectInsertionLocator,
657
- fieldName: string,
658
- line: string,
659
- options: { fieldIndent: string; closingIndent: string },
660
- ) => {
661
- if (locator.fields.some((field) => field.name === fieldName)) return content;
662
- const insertIndex = insertionIndexForFieldOrder(
663
- locator.fields.map((field) => field.name),
664
- fieldName,
665
- );
666
- const formattedLine = line.trim();
667
- if (locator.fields.length === 0) {
668
- return spliceText(
669
- content,
670
- locator.objectStart,
671
- locator.objectEnd,
672
- `{\n${options.fieldIndent}${formattedLine}\n${options.closingIndent}}`,
673
- );
674
- }
675
-
676
- const beforeField = locator.fields[insertIndex];
677
- if (beforeField) {
678
- const leadingComments = ts.getLeadingCommentRanges(content, beforeField.fullStart) ?? [];
679
- const insertAt = lineStartAt(content, leadingComments[0]?.pos ?? beforeField.start);
680
- const indent = lineIndentAt(content, beforeField.start) || options.fieldIndent;
681
- return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}\n`);
682
- }
683
-
684
- const afterField = locator.fields[locator.fields.length - 1];
685
- const insertAt = lineEndAt(content, afterField.end);
686
- const indent = lineIndentAt(content, afterField.start) || options.fieldIndent;
687
- return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}\n`);
688
- };
689
-
690
- export const viaBuilderParameterName = (content: string, className: string) => {
691
- const source = sourceFileFor("constant.ts", content);
692
- let builderName: string | null = null;
693
- const visit = (node: ts.Node) => {
694
- if (builderName !== null) return;
695
- if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
696
- ts.forEachChild(node, visit);
697
- return;
698
- }
699
- const viaCall = heritageCall(node);
700
- const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
701
- if (callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
702
- builderName = nodeName(callback.parameters[0]?.name);
703
- }
704
- };
705
- ts.forEachChild(source, visit);
706
- return builderName;
707
- };
708
-
709
- export const inspectConstantStructure = (
710
- content: string,
711
- className: string,
712
- moduleClassName: string,
713
- ): AkanConstantStructure => {
714
- const source = sourceFileFor("constant.ts", content);
715
- const inputObject = findConstantInputObject(source, className);
716
- const lightProjection = findLightProjectionArray(source, moduleClassName);
717
- const baseImport = findNamedImport(source, "akanjs/base");
718
- const fields: AkanConstantFieldStructure[] = [];
719
- if (inputObject) {
720
- const visit = (node: ts.Node) => {
721
- if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
722
- ts.forEachChild(node, visit);
723
- return;
724
- }
725
- const viaCall = heritageCall(node);
726
- const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
727
- const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
728
- if (!objectLiteral) return;
729
- fields.push(
730
- ...objectLiteral.properties
731
- .map((property): AkanConstantFieldStructure | null => {
732
- const name = propertyName(property);
733
- if (!name) return null;
734
- return { name, expressionBuilder: fieldExpressionBuilder(property) };
735
- })
736
- .filter((field): field is AkanConstantFieldStructure => field !== null),
737
- );
738
- };
739
- ts.forEachChild(source, visit);
740
- }
741
- return {
742
- parseValid: !hasParseDiagnostics(source),
743
- inputObjectFound: inputObject !== null,
744
- builderName: viaBuilderParameterName(content, className),
745
- fields,
746
- lightProjectionFields: lightProjection?.fields ?? [],
747
- baseImports: baseImport?.names ?? [],
748
- };
749
- };
750
-
751
- export const inspectDictionaryStructure = (content: string, moduleClassName: string): AkanDictionaryStructure => {
752
- const source = sourceFileFor("dictionary.ts", content);
753
- const modelObject = findDictionaryModelObject(source, moduleClassName);
754
- return {
755
- parseValid: !hasParseDiagnostics(source),
756
- modelObjectFound: modelObject !== null,
757
- chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
758
- chainMethods: modelObject?.chainMethods ?? [],
759
- fields: modelObject?.fields.map((field) => field.name) ?? [],
760
- };
761
- };
762
-
763
- export const insertIntoObject = (content: string, className: string, line: string) => {
764
- const fieldName = /^([A-Za-z_$][\w$]*)\s*:/.exec(line.trim())?.[1];
765
- if (!fieldName) return null;
766
- const source = sourceFileFor("constant.ts", content);
767
- const locator = findConstantInputObject(source, className);
768
- if (!locator) return null;
769
- return insertOrderedFieldLine(content, locator, fieldName, line, { fieldIndent: " ", closingIndent: "" });
770
- };
771
-
772
- export const insertLightProjectionField = (content: string, moduleClassName: string, fieldName: string) => {
773
- const source = sourceFileFor("constant.ts", content);
774
- const locator = findLightProjectionArray(source, moduleClassName);
775
- if (!locator) return null;
776
- if (locator.fields.includes(fieldName)) return content;
777
- const nextFields = [...locator.fields, fieldName];
778
- const nextArray =
779
- nextFields.length === 0
780
- ? "[] as const"
781
- : `[\n${nextFields.map((field) => ` ${JSON.stringify(field)},`).join("\n")}\n] as const`;
782
- return spliceText(content, locator.projectionStart, locator.projectionEnd, nextArray);
783
- };
784
-
785
- export const insertTemplateField = ({
786
- content,
787
- moduleName,
788
- moduleClassName,
789
- fieldName,
790
- component,
791
- }: {
792
- content: string;
793
- moduleName: string;
794
- moduleClassName: string;
795
- fieldName: string;
796
- component: "Field.Text" | "Field.Number" | "Field.Date";
797
- }) => {
798
- if (content.includes(`l("${moduleName}.${fieldName}")`) || content.includes(`.${fieldName}`)) return content;
799
- const layoutEndIndex = content.indexOf(" </Layout.Template>");
800
- if (layoutEndIndex < 0) return null;
801
- const formName = `${moduleName}Form`;
802
- if (!content.includes(`const ${formName} = st.use.${moduleName}Form();`)) return null;
803
- const fieldSetter = `st.do.set${moduleComponentName(fieldName)}On${moduleClassName}`;
804
- const fieldBlock = ` <${component}
805
- label={l("${moduleName}.${fieldName}")}
806
- desc={l("${moduleName}.${fieldName}.desc")}
807
- value={${formName}.${fieldName}}
808
- onChange={${fieldSetter}}
809
- />
810
- `;
811
- return `${content.slice(0, layoutEndIndex)}${fieldBlock}${content.slice(layoutEndIndex)}`;
812
- };
813
-
814
- export const ensureEnumImport = (content: string) => {
815
- if (content.includes("enumOf")) return content;
816
- const baseImport = /import \{ ([^{}]+) \} from "akanjs\/base";/.exec(content);
817
- if (baseImport) {
818
- const names = baseImport[1]?.split(",").map((name) => name.trim()) ?? [];
819
- return content.replace(baseImport[0], `import { ${[...names, "enumOf"].sort().join(", ")} } from "akanjs/base";`);
820
- }
821
- return `import { enumOf } from "akanjs/base";\n${content}`;
822
- };
823
-
824
- export const insertEnumClass = (content: string, enumClassName: string, enumName: string, values: string[]) => {
825
- if (content.includes(`export class ${enumClassName} extends enumOf`)) return content;
826
- const enumClass = `export class ${enumClassName} extends enumOf("${enumName}", [\n${values
827
- .map((value) => ` ${JSON.stringify(value)},`)
828
- .join("\n")}\n] as const) {}\n\n`;
829
- const firstClassIndex = content.indexOf("export class ");
830
- if (firstClassIndex < 0) return `${content}\n${enumClass}`;
831
- return `${content.slice(0, firstClassIndex)}${enumClass}${content.slice(firstClassIndex)}`;
832
- };
833
-
834
- const dictionaryModelFieldLine = (fieldName: string) => {
835
- const label = bilingualLabelForField(fieldName);
836
- const desc = bilingualDescriptionForField(fieldName);
837
- return `${fieldName}: t([${JSON.stringify(label.en)}, ${JSON.stringify(label.ko)}]).desc([${JSON.stringify(
838
- desc.en,
839
- )}, ${JSON.stringify(desc.ko)}]),`;
840
- };
841
-
842
- export const insertDictionaryModelField = (content: string, moduleClassName: string, fieldName: string) => {
843
- const source = sourceFileFor("dictionary.ts", content);
844
- const locator = findDictionaryModelObject(source, moduleClassName);
845
- if (!locator) return null;
846
- return insertOrderedFieldLine(content, locator, fieldName, dictionaryModelFieldLine(fieldName), {
847
- fieldIndent: " ",
848
- closingIndent: " ",
849
- });
850
- };
851
-
852
- export const hasConstantInputField = (content: string, className: string, fieldName: string) => {
853
- const source = sourceFileFor("constant.ts", content);
854
- if (hasParseDiagnostics(source)) return false;
855
- return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
856
- };
857
-
858
- export const hasDictionaryModelField = (content: string, moduleClassName: string, fieldName: string) => {
859
- const source = sourceFileFor("dictionary.ts", content);
860
- if (hasParseDiagnostics(source)) return false;
861
- return findDictionaryModelObject(source, moduleClassName)?.fields.some((field) => field.name === fieldName) ?? false;
862
- };
863
-
864
- export const hasDictionaryEndpointEntry = (content: string, moduleClassName: string, entryName: string) => {
865
- const source = sourceFileFor("dictionary.ts", content);
866
- return (
867
- findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`)?.fields.some(
868
- (field) => field.name === entryName,
869
- ) ?? false
870
- );
871
- };
872
-
873
- export const insertDictionaryEndpointEntry = (
874
- content: string,
875
- moduleClassName: string,
876
- entryName: string,
877
- entryText: string,
878
- ) => {
879
- const source = sourceFileFor("dictionary.ts", content);
880
- const locator = findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`);
881
- if (!locator) return null;
882
- return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
883
- };
884
-
885
- export const ensureConstantTypeImport = (content: string, constantPath: string, typeName: string) => {
886
- if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content)) return content;
887
- const importPattern = new RegExp(`import type \\{ ([^}]+) \\} from "${constantPath}";`);
888
- const existingImport = content.match(importPattern);
889
- if (existingImport !== null) {
890
- const names = existingImport[1]?.split(",").map((name) => name.trim()) ?? [];
891
- return content.replace(
892
- existingImport[0],
893
- `import type { ${[...names, typeName].sort().join(", ")} } from "${constantPath}";`,
894
- );
895
- }
896
- return `import type { ${typeName} } from "${constantPath}";\n${content}`;
897
- };
898
-
899
- const dictionaryChainOf = (node: ts.Node): ts.CallExpression | undefined => {
900
- if (
901
- ts.isCallExpression(node) &&
902
- outermostFluentCall(node) === node &&
903
- protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method))
904
- )
905
- return node;
906
- return ts.forEachChild(node, dictionaryChainOf);
907
- };
908
-
909
- const chainMethodNames = (call: ts.Expression): ts.Identifier[] => {
910
- if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression)) return [];
911
- const name = call.expression.name;
912
- return [...chainMethodNames(call.expression.expression), ...(ts.isIdentifier(name) ? [name] : [])];
913
- };
914
-
915
- //* Located on the parsed chain, never by text search: the sample dictionary's header comment mentions `.error()`.
916
- export const insertDictionaryEnum = (content: string, enumClassName: string, enumName: string, values: string[]) => {
917
- if (content.includes(`.enum<${enumClassName}>("${enumName}"`)) return content;
918
- const source = sourceFileFor("dictionary.ts", content);
919
- if (hasParseDiagnostics(source)) return null;
920
- const chain = dictionaryChainOf(source);
921
- if (!chain) return null;
922
- const enumBlock = ` .enum<${enumClassName}>("${enumName}", (t) => ({\n${values
923
- .map((value) => ` ${value}: t([${JSON.stringify(titleize(value))}, ${JSON.stringify(titleize(value))}]),`)
924
- .join("\n")}\n }))\n`;
925
- const later = chainMethodNames(chain).find((name) => name.text === "error" || name.text === "translate");
926
- if (!later) return spliceText(content, chain.getEnd(), chain.getEnd(), `\n${enumBlock.trimEnd()}`);
927
- const dot = content.lastIndexOf(".", later.getStart(source));
928
- const lineStart = lineStartAt(content, dot);
929
- if (content.slice(lineStart, dot).trim() === "") return spliceText(content, lineStart, lineStart, enumBlock);
930
- return spliceText(content, dot, dot, `\n${enumBlock}`);
931
- };
932
-
933
- export const parseValues = (value: string | null) =>
934
- value
935
- ?.split(",")
936
- .map((item) => item.trim())
937
- .filter(Boolean) ?? [];
938
-
939
- export const hasSourceParseErrors = (content: string, fileName = "source.ts") =>
940
- hasParseDiagnostics(sourceFileFor(fileName, content));
941
-
942
- const findClassDeclaration = (source: ts.SourceFile, className: string): ts.ClassDeclaration | null => {
943
- let found: ts.ClassDeclaration | null = null;
944
- const visit = (node: ts.Node) => {
945
- if (found) return;
946
- if (ts.isClassDeclaration(node) && node.name?.text === className) {
947
- found = node;
948
- return;
949
- }
950
- ts.forEachChild(node, visit);
951
- };
952
- ts.forEachChild(source, visit);
953
- return found;
954
- };
955
-
956
- const firstHeritageCall = (node: ts.ClassDeclaration): ts.CallExpression | null => {
957
- const expression = (node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [])[0]?.expression;
958
- return expression && ts.isCallExpression(expression) ? expression : null;
959
- };
960
-
961
- const factoryArrowOf = (call: ts.CallExpression): ts.ArrowFunction | ts.FunctionExpression | null => {
962
- const arg = call.arguments.find((argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
963
- return arg && (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) ? arg : null;
964
- };
965
-
966
- export const hasClassMethod = (content: string, className: string, methodName: string) => {
967
- const node = findClassDeclaration(sourceFileFor("service.ts", content), className);
968
- return Boolean(
969
- node?.members.some((member) => ts.isMethodDeclaration(member) && nodeName(member.name) === methodName),
970
- );
971
- };
972
-
973
- export const classMethodParameters = (content: string, className: string, methodName: string) => {
974
- const source = sourceFileFor("service.ts", content);
975
- const method = findClassDeclaration(source, className)?.members.find(
976
- (member): member is ts.MethodDeclaration => ts.isMethodDeclaration(member) && nodeName(member.name) === methodName,
977
- );
978
- return (
979
- method?.parameters.map((parameter) => ({
980
- name: nodeName(parameter.name),
981
- optional: !!parameter.questionToken || !!parameter.initializer || !!parameter.dotDotDotToken,
982
- })) ?? null
983
- );
984
- };
985
-
986
- export const insertClassMethod = (content: string, className: string, methodBlock: string): string | null => {
987
- const source = sourceFileFor("service.ts", content);
988
- const node = findClassDeclaration(source, className);
989
- if (!node) return null;
990
- const closeBrace = node.getEnd() - 1;
991
- if (content[closeBrace] !== "}") return null;
992
- const lead = content.slice(0, closeBrace).endsWith("\n") ? "" : "\n";
993
- return spliceText(content, closeBrace, closeBrace, `${lead}${methodBlock}\n`);
994
- };
995
-
996
- export interface FactoryParamPlan {
997
- mode: "destructure" | "positional";
998
- name: string;
999
- }
1000
-
1001
- const arrowParamInnerRegion = (
1002
- content: string,
1003
- source: ts.SourceFile,
1004
- arrow: ts.ArrowFunction | ts.FunctionExpression,
1005
- ) => {
1006
- if (arrow.parameters.length > 0) {
1007
- return {
1008
- start: arrow.parameters[0].getStart(source),
1009
- end: arrow.parameters[arrow.parameters.length - 1].getEnd(),
1010
- };
1011
- }
1012
- const open = content.indexOf("(", arrow.getStart(source));
1013
- if (open < 0) return null;
1014
- const close = content.indexOf(")", open);
1015
- if (close < 0) return null;
1016
- return { start: open + 1, end: close };
1017
- };
1018
-
1019
- const factoryParamEdit = (
1020
- content: string,
1021
- source: ts.SourceFile,
1022
- arrow: ts.ArrowFunction | ts.FunctionExpression,
1023
- plan: FactoryParamPlan,
1024
- ): { start: number; end: number; text: string } | "unchanged" | null => {
1025
- if (arrow.parameters.length > 1) return null;
1026
- const region = arrowParamInnerRegion(content, source, arrow);
1027
- if (!region) return null;
1028
- if (arrow.parameters.length === 0) {
1029
- return { ...region, text: plan.mode === "destructure" ? `{ ${plan.name} }` : plan.name };
1030
- }
1031
- const param = arrow.parameters[0];
1032
- if (plan.mode === "positional") return nodeName(param.name) === plan.name ? "unchanged" : null;
1033
- if (!ts.isObjectBindingPattern(param.name)) return null;
1034
- const names = param.name.elements.map((element) => (ts.isIdentifier(element.name) ? element.name.text : null));
1035
- if (names.some((name) => name === null)) return null;
1036
- if (names.includes(plan.name)) return "unchanged";
1037
- return {
1038
- start: param.getStart(source),
1039
- end: param.getEnd(),
1040
- text: `{ ${[...(names as string[]), plan.name].join(", ")} }`,
1041
- };
1042
- };
1043
-
1044
- const factoryObjectOf = (source: ts.SourceFile, className: string) => {
1045
- const node = findClassDeclaration(source, className);
1046
- const call = node ? firstHeritageCall(node) : null;
1047
- const arrow = call ? factoryArrowOf(call) : null;
1048
- const object = arrow ? firstObjectReturnedByArrow(arrow) : null;
1049
- return arrow && object ? { arrow, object } : null;
1050
- };
1051
-
1052
- export const hasSignalFactoryEntry = (content: string, className: string, entryName: string) => {
1053
- const located = factoryObjectOf(sourceFileFor("signal.ts", content), className);
1054
- return Boolean(located?.object.properties.some((property) => propertyName(property) === entryName));
1055
- };
1056
-
1057
- export const insertSignalFactoryEntry = (
1058
- content: string,
1059
- className: string,
1060
- entryName: string,
1061
- entryLine: string,
1062
- param: FactoryParamPlan,
1063
- ): string | null => {
1064
- const source = sourceFileFor("signal.ts", content);
1065
- const located = factoryObjectOf(source, className);
1066
- if (!located) return null;
1067
- const locator = locatedObject(source, located.object);
1068
- if (locator.fields.some((field) => field.name === entryName)) return content;
1069
- // Apply the param edit last: it sits before the object, so applying it first would shift the object's offsets.
1070
- const paramEdit = factoryParamEdit(content, source, located.arrow, param);
1071
- if (paramEdit === null) return null;
1072
- const withEntry = insertOrderedFieldLine(content, locator, entryName, entryLine, {
1073
- fieldIndent: " ",
1074
- closingIndent: "",
1075
- });
1076
- if (withEntry === content) return null;
1077
- return paramEdit === "unchanged" ? withEntry : spliceText(withEntry, paramEdit.start, paramEdit.end, paramEdit.text);
1078
- };
1079
-
1080
- export const appendTopLevelTestCases = (
1081
- content: string,
1082
- describeTitle: string,
1083
- render: (itName: string, indent: string) => string[],
1084
- ) => {
1085
- const bunImport = findNamedImport(sourceFileFor("test.ts", content), "bun:test", { valueOnly: true });
1086
- const itName = !bunImport?.names.includes("it") && bunImport?.names.includes("test") ? "test" : "it";
1087
- const imported = ensureNamedImport(content, "bun:test", itName);
1088
- const source = sourceFileFor("test.ts", imported);
1089
- const body = source.statements.flatMap((statement) => {
1090
- if (!ts.isExpressionStatement(statement) || !ts.isCallExpression(statement.expression)) return [];
1091
- if (expressionName(statement.expression.expression) !== "describe") return [];
1092
- const callback = factoryArrowOf(statement.expression);
1093
- return callback && ts.isBlock(callback.body) ? [callback.body] : [];
1094
- })[0];
1095
- if (!body) {
1096
- const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
1097
- return `${ensureNamedImport(imported, "bun:test", "describe").trimEnd()}\n\n${block.join("\n")}`;
1098
- }
1099
- const firstStatement = body.statements[0];
1100
- const indent = firstStatement
1101
- ? lineIndentAt(imported, firstStatement.getStart(source))
1102
- : `${lineIndentAt(imported, body.getStart(source))} `;
1103
- const insertAt = lineStartAt(imported, body.getEnd() - 1);
1104
- return spliceText(imported, insertAt, insertAt, `${render(itName, indent).join("\n")}\n`);
1105
- };
1
+ export {
2
+ type AkanConstantFieldStructure,
3
+ type AkanConstantStructure,
4
+ hasConstantInputField,
5
+ insertEnumClass,
6
+ insertIntoObject,
7
+ insertLightProjectionField,
8
+ inspectConstantStructure,
9
+ viaBuilderParameterName,
10
+ } from "./constantSource";
11
+ export {
12
+ type AkanDictionaryStructure,
13
+ hasDictionaryEndpointEntry,
14
+ hasDictionaryModelField,
15
+ insertDictionaryEndpointEntry,
16
+ insertDictionaryEnum,
17
+ insertDictionaryModelField,
18
+ inspectDictionaryStructure,
19
+ } from "./dictionarySource";
20
+ export {
21
+ coerceFieldDefault,
22
+ type FieldDefaultValue,
23
+ fieldExpression,
24
+ normalizeFieldType,
25
+ parseValues,
26
+ } from "./fieldExpression";
27
+ export { bilingualDescriptionForField, bilingualLabelForField, titleize } from "./fieldLabel";
28
+ export { fieldOrderingPriority, insertionIndexForFieldOrder } from "./fieldOrder";
29
+ export { getSysRoot, moduleComponentName, moduleSourcePaths } from "./modulePaths";
30
+ export {
31
+ createPassedPrimitiveReport,
32
+ createPrimitiveWriteReport,
33
+ generatedFilesForSync,
34
+ nextActionsForTarget,
35
+ scalarChangedFiles,
36
+ sourceFile,
37
+ validationCommandsForTarget,
38
+ } from "./primitiveReport";
39
+ export { classMethodParameters, hasClassMethod, insertClassMethod } from "./serviceSource";
40
+ export { type FactoryParamPlan, hasSignalFactoryEntry, insertSignalFactoryEntry } from "./signalSource";
41
+ export { hasSourceParseErrors } from "./sourceAst";
42
+ export {
43
+ ensureBaseImport,
44
+ ensureConstantTypeImport,
45
+ ensureEnumImport,
46
+ ensureImportDeclaration,
47
+ ensureNamedImport,
48
+ } from "./sourceImports";
49
+ export { insertTemplateField } from "./templateSource";
50
+ export { appendTopLevelTestCases } from "./testSource";