@akanjs/devkit 3.3.0-rc.8 → 4.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/DEV_RUNTIME_KNOBS.md +1 -1
  2. package/README.ko.md +7 -1
  3. package/README.md +7 -1
  4. package/akanApp/akanApp.host.test.ts +3 -1
  5. package/akanApp/akanApp.host.ts +26 -2
  6. package/akanApp/akanApp.host.wiring.test.ts +111 -0
  7. package/akanApp/devHostPolicy.ts +5 -0
  8. package/akanApp/devMetadataRestart.ts +93 -0
  9. package/akanApp/devRecycler.test.ts +2 -0
  10. package/akanApp/devRecycler.ts +9 -0
  11. package/akanConfig/akanBin.ts +4 -0
  12. package/akanConfig/akanConfig.test.ts +269 -18
  13. package/akanConfig/akanConfig.ts +104 -210
  14. package/akanConfig/akanPreview.test.ts +28 -0
  15. package/akanConfig/akanPreview.ts +24 -0
  16. package/akanConfig/akanWorkers.test.ts +73 -0
  17. package/akanConfig/akanWorkers.ts +61 -0
  18. package/akanConfig/desktopServerConfig.ts +96 -0
  19. package/akanConfig/dockerImage.ts +212 -0
  20. package/akanConfig/index.ts +3 -0
  21. package/akanConfig/nativeFileSettings.ts +33 -0
  22. package/akanConfig/types.ts +4 -0
  23. package/app/appBin.test.ts +63 -0
  24. package/app/appBin.ts +50 -0
  25. package/app/applicationBuildReporter.test.ts +51 -1
  26. package/app/applicationBuildReporter.ts +6 -1
  27. package/app/applicationBuildRunner.test.ts +358 -5
  28. package/app/applicationBuildRunner.ts +221 -31
  29. package/app/clientServerBoundary.test.ts +115 -0
  30. package/app/clientServerBoundary.ts +89 -0
  31. package/app/dictionarySizes.test.ts +40 -0
  32. package/app/dictionarySizes.ts +95 -0
  33. package/app/routeFilesReport.test.ts +59 -0
  34. package/app/routeFilesReport.ts +46 -0
  35. package/app/routeJsBudget.ts +18 -4
  36. package/artifact/implicitRootLayout.test.ts +19 -0
  37. package/artifact/implicitRootLayout.ts +16 -2
  38. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  39. package/artifact/storeBootstrap.test.ts +28 -0
  40. package/artifact/storeBootstrap.ts +64 -8
  41. package/biome.base.json +7 -5
  42. package/codeAgent/index.ts +1 -34
  43. package/codeAgent/skills/akan-agent/SKILL.md +2 -2
  44. package/codeAgent/skills/akan-debug/SKILL.md +8 -3
  45. package/codeAgent/skills/akan-deps/SKILL.md +10 -3
  46. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  47. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  48. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  49. package/codeAgent/skills/akan-page/SKILL.md +65 -30
  50. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  51. package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
  52. package/codeAgent/skills/akan-service/SKILL.md +21 -20
  53. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  54. package/codeAgent/skills/akan-ui/SKILL.md +16 -21
  55. package/codeAgent/skills/akan-validate/SKILL.md +8 -2
  56. package/commandDecorators/command.ts +28 -12
  57. package/commandDecorators/commandBuilder.ts +8 -1
  58. package/commandDecorators/commandDecorators.test.ts +70 -3
  59. package/commandDecorators/helpFormatter.ts +14 -12
  60. package/context/akanContext.ts +2 -0
  61. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  62. package/csrE2e/ssrRegistry.e2e.test.ts +108 -22
  63. package/docs/apiReference.test.ts +25 -0
  64. package/docs/apiReference.ts +38 -5
  65. package/docs/declarationReader.ts +30 -0
  66. package/executors/appExecutor.ts +26 -12
  67. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  68. package/executors/clientRuntimeKeys.fixture.json +393 -0
  69. package/executors/clientRuntimeKeys.test.ts +1690 -0
  70. package/executors/executor.ts +14 -6
  71. package/executors/executors.test.ts +155 -1
  72. package/executors/pkgExecutor.ts +2 -1
  73. package/executors/sysExecutor.ts +112 -8
  74. package/executors/workspaceExecutor.ts +7 -4
  75. package/frontendBuild/allRoutesBuilder.ts +99 -7
  76. package/frontendBuild/autoImportSync.ts +3 -2
  77. package/frontendBuild/buildRouteClient.test.ts +684 -6
  78. package/frontendBuild/clientBuildTypes.ts +26 -0
  79. package/frontendBuild/clientEntriesBundler.ts +49 -1
  80. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  81. package/frontendBuild/clientEntryDiscovery.ts +134 -12
  82. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  83. package/frontendBuild/clientEntryGroups.ts +61 -0
  84. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  85. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  86. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  87. package/frontendBuild/csrDevPatcher.test.ts +4 -5
  88. package/frontendBuild/csrDevPatcher.ts +37 -11
  89. package/frontendBuild/csrDevTypes.ts +9 -0
  90. package/frontendBuild/devBarrelImports.test.ts +124 -0
  91. package/frontendBuild/devBarrelImports.ts +81 -21
  92. package/frontendBuild/devChangePlanner.ts +0 -1
  93. package/frontendBuild/devRegistryBundler.ts +4 -2
  94. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  95. package/frontendBuild/devRouteRuntime.ts +167 -0
  96. package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
  97. package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
  98. package/frontendBuild/dictionaryConstants.ts +136 -0
  99. package/frontendBuild/dictionaryOwnParts.ts +88 -0
  100. package/frontendBuild/dictionaryPackState.ts +131 -0
  101. package/frontendBuild/dictionaryPacking.test.ts +207 -0
  102. package/frontendBuild/dictionaryPacking.ts +160 -0
  103. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  104. package/frontendBuild/dictionaryRoutes.ts +227 -0
  105. package/frontendBuild/frontendBuild.test.ts +5 -3
  106. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  107. package/frontendBuild/pagesBundleBuilder.ts +78 -2
  108. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  109. package/frontendBuild/precompressArtifacts.ts +34 -8
  110. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  111. package/frontendBuild/renderedEntries.ts +144 -0
  112. package/frontendBuild/routeClientBuilder.ts +407 -43
  113. package/frontendBuild/routeHandoffs.test.ts +155 -0
  114. package/frontendBuild/routeHandoffs.ts +117 -0
  115. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  116. package/frontendBuild/routeModulePreloads.ts +20 -11
  117. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  118. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  119. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  120. package/frontendBuild/routeRuntimePays.ts +117 -0
  121. package/frontendBuild/ssrBaseArtifactBuilder.ts +30 -35
  122. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  123. package/frontendBuild/ssrDevBundler.ts +66 -11
  124. package/frontendBuild/vendorFileImports.test.ts +254 -0
  125. package/frontendBuild/vendorFileImports.ts +163 -0
  126. package/frontendBuild/vendorNarrowing.test.ts +47 -3
  127. package/frontendBuild/vendorNarrowing.ts +38 -2
  128. package/frontendBuild/vendorSpecifiers.ts +2 -0
  129. package/guideline/agentAssets.ts +1 -1
  130. package/incrementalBuilder/buildBatch.proc.ts +27 -1
  131. package/incrementalBuilder/buildBatchProtocol.ts +1 -0
  132. package/incrementalBuilder/builderWatch.ts +11 -1
  133. package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
  134. package/incrementalBuilder/incrementalBuilder.proc.ts +31 -3
  135. package/incrementalBuilder/pendingMetadata.test.ts +27 -0
  136. package/incrementalBuilder/pendingMetadata.ts +19 -0
  137. package/integration/devStability.integration.test.ts +46 -21
  138. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  139. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  140. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  141. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  142. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  143. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  144. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  145. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  146. package/lint/biomeBase.test.ts +50 -3
  147. package/lint/biomeBase.ts +1 -1
  148. package/lint/biomeCheck.test.ts +162 -0
  149. package/lint/biomeCheck.ts +131 -0
  150. package/lint/linter.test.ts +16 -11
  151. package/lint/no-arbitrary-color.grit +5 -0
  152. package/lint/no-conditional-st-hook.grit +5 -1
  153. package/lint/no-daisyui-legacy-class.grit +8 -0
  154. package/lint/no-document-cookie.grit +3 -0
  155. package/lint/no-inline-color.grit +10 -2
  156. package/lint/no-oversized-list-limit.grit +2 -0
  157. package/lint/no-raw-palette-class.grit +7 -0
  158. package/lint/no-unpublished-form-setter.grit +2 -0
  159. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  160. package/lint/no-web-storage.grit +3 -0
  161. package/lint/withheldEnvFile.ts +17 -0
  162. package/mobile/desktopBin.ts +2 -2
  163. package/mobile/desktopServerStage.test.ts +18 -3
  164. package/mobile/desktopServerStage.ts +7 -2
  165. package/mobile/nativeApp.test.ts +7 -5
  166. package/mobile/nativeApp.ts +2 -2
  167. package/mobile/nativeConfig.test.ts +17 -1
  168. package/mobile/nativeConfig.ts +11 -6
  169. package/mobile/nativePublicEnv.ts +1 -1
  170. package/mobile/serverBundleSecrets.ts +43 -0
  171. package/package.json +11 -12
  172. package/packageExports.test.ts +3 -2
  173. package/preview/PreviewView.ts +25 -3
  174. package/quality/dictionaryKeys.test.ts +356 -0
  175. package/quality/dictionaryKeys.ts +488 -0
  176. package/quality/objectImportReport.test.ts +36 -0
  177. package/quality/objectImportReport.ts +105 -0
  178. package/quality/qualityScanner.ts +1 -1
  179. package/quality/routeRuntimeReport.test.ts +91 -0
  180. package/quality/routeRuntimeReport.ts +121 -0
  181. package/quality/runtimeConstantFacts.ts +71 -0
  182. package/quality/runtimeConstantGraph.ts +123 -0
  183. package/quality/runtimeConstantReads.ts +116 -0
  184. package/quality/runtimeImports.test.ts +190 -0
  185. package/quality/runtimeImports.ts +233 -0
  186. package/quality/runtimeKeyNames.ts +46 -0
  187. package/quality/runtimeLexicalScope.ts +132 -0
  188. package/quality/runtimeMarkerReach.test.ts +84 -0
  189. package/quality/runtimeMarkerReach.ts +255 -0
  190. package/quality/runtimeModuleFacts.ts +290 -0
  191. package/quality/runtimeNameTable.test.ts +172 -0
  192. package/quality/runtimeNameTable.ts +477 -0
  193. package/quality/runtimeScopeReport.test.ts +123 -0
  194. package/quality/runtimeScopeReport.ts +167 -0
  195. package/quality/runtimeSliceKey.ts +269 -0
  196. package/quality/runtimeSyntax.ts +133 -0
  197. package/quality/runtimeTable.fixture.ts +189 -0
  198. package/quality/runtimeUse.test.ts +737 -0
  199. package/quality/runtimeUse.ts +696 -0
  200. package/quality/runtimeUseReadable.test.ts +393 -0
  201. package/quality/ssrScanner.test.ts +13 -0
  202. package/quality/ssrScanner.ts +1 -1
  203. package/quality/translatorBindings.ts +187 -0
  204. package/test/fakeTerminal.ts +45 -0
  205. package/test/secretEnvFixture.ts +134 -0
  206. package/test/testHelpers.ts +11 -0
  207. package/transforms/barrelAnalyzer.ts +24 -2
  208. package/transforms/barrelImportsPlugin.ts +121 -32
  209. package/transforms/exportReach.test.ts +162 -0
  210. package/transforms/exportReach.ts +308 -0
  211. package/transforms/frameworkObjects.fixture.tsx +58 -0
  212. package/transforms/frameworkObjects.test.ts +54 -0
  213. package/transforms/modelReference.test.ts +196 -0
  214. package/transforms/modelReference.ts +39 -0
  215. package/transforms/moduleParts.test.ts +225 -0
  216. package/transforms/moduleParts.ts +418 -0
  217. package/transforms/objectImportEdits.ts +150 -0
  218. package/transforms/objectMemberImports.test.ts +633 -0
  219. package/transforms/objectMemberImports.ts +571 -0
  220. package/transforms/objectMemberLookup.ts +150 -0
  221. package/transforms/objectModule.test.ts +307 -0
  222. package/transforms/objectModule.ts +482 -0
  223. package/transforms/objectModuleAnalyzer.ts +104 -0
  224. package/transforms/partImports.test.ts +76 -0
  225. package/transforms/partImports.ts +110 -0
  226. package/transforms/partModules.test.ts +187 -0
  227. package/transforms/partModules.ts +90 -0
  228. package/transforms/partPurity.ts +124 -0
  229. package/transforms/reactIconImports.test.ts +231 -0
  230. package/transforms/reactIconImports.ts +325 -0
  231. package/transforms/routeConstants.ts +122 -0
  232. package/transforms/routeRuntime.test.ts +835 -0
  233. package/transforms/routeRuntime.ts +703 -0
  234. package/transforms/routeRuntimeEdits.ts +92 -0
  235. package/transforms/routeRuntimeGraph.ts +66 -0
  236. package/transforms/routeRuntimePlan.ts +244 -0
  237. package/transforms/secretEnvDeclaration.test.ts +208 -0
  238. package/transforms/secretEnvDeclaration.ts +213 -0
  239. package/transforms/secretEnvFile.test.ts +117 -0
  240. package/transforms/secretEnvFile.ts +113 -0
  241. package/transforms/secretEnvName.test.ts +54 -0
  242. package/transforms/secretEnvName.ts +29 -0
  243. package/transforms/secretEnvSource.test.ts +148 -0
  244. package/transforms/secretEnvSource.ts +166 -0
  245. package/transforms/serverEnvEvaluationError.ts +11 -0
  246. package/transforms/serverEnvPlugin.test.ts +2 -1
  247. package/transforms/serverEnvPlugin.ts +13 -0
  248. package/transforms/serverEnvProfile.test.ts +129 -2
  249. package/transforms/serverEnvProfile.ts +126 -40
  250. package/transforms/serverEnvSecrets.test.ts +292 -0
  251. package/transforms/signalDescriptors.test.ts +280 -0
  252. package/transforms/signalDescriptors.ts +227 -0
  253. package/transforms/thisFreeExports.ts +87 -0
  254. package/transforms/transforms.test.ts +177 -0
  255. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  256. package/tunnel/createTunnel.ts +5 -1
  257. package/tunnel/ssh2Module.test.ts +37 -0
  258. package/tunnel/ssh2Module.ts +28 -0
  259. package/tunnel/sshTunnel.ts +4 -2
  260. package/typecheck/projectTypecheck.test.ts +32 -1
  261. package/typecheck/projectTypecheck.ts +3 -3
  262. package/typecheck/typeChecker.test.ts +49 -0
  263. package/typecheck/typeChecker.ts +9 -7
  264. package/typecheck/withheldDiagnostics.ts +41 -0
  265. package/util/devInstallCommand.ts +7 -0
  266. package/util/jsonFormatter.test.ts +13 -9
  267. package/workflow/executor.ts +6 -2
  268. package/workflow/index.ts +1 -0
  269. package/workflow/plan.ts +36 -7
  270. package/workflow/types.ts +1 -1
  271. package/workflow/uiTarget.ts +50 -0
  272. package/workspace/envSeed.test.ts +30 -1
  273. package/workspace/envSeed.ts +30 -1
  274. package/workspace/mainCheckout.test.ts +55 -0
  275. package/workspace/mainCheckout.ts +38 -0
  276. package/workspace/scanInfo.test.ts +39 -0
  277. package/workspace/scanInfo.ts +55 -6
  278. package/workspace/slicePlanner.ts +2 -1
  279. package/workspace/workspaceLayout.test.ts +22 -1
  280. package/workspace/workspaceLayout.ts +3 -3
  281. package/CHANGELOG.md +0 -2903
  282. package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
  283. package/codeAgent/agent/AkanCodeServices.ts +0 -122
  284. package/codeAgent/agent/AkanContextFiles.ts +0 -94
  285. package/codeAgent/agent/CodeAgent.ts +0 -626
  286. package/codeAgent/agent/CodeAgentAllowed.ts +0 -35
  287. package/codeAgent/agent/CodeAgentAsks.ts +0 -66
  288. package/codeAgent/agent/CodeAgentCommandLine.ts +0 -372
  289. package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
  290. package/codeAgent/agent/CodeAgentGate.ts +0 -258
  291. package/codeAgent/agent/CodeAgentProxy.ts +0 -83
  292. package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
  293. package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
  294. package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
  295. package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
  296. package/codeAgent/agent/CodeAgentUi.ts +0 -47
  297. package/codeAgent/agent/CodeMailbox.ts +0 -148
  298. package/codeAgent/agent/CodeSessionFork.ts +0 -56
  299. package/codeAgent/agent/CodeSessionIndex.ts +0 -78
  300. package/codeAgent/agent/SubagentPool.ts +0 -219
  301. package/codeAgent/agent/WorkspaceTrust.ts +0 -200
  302. package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
  303. package/codeAgent/agent/akanCodeModel.ts +0 -47
  304. package/codeAgent/agent/akanCodeServices.test.ts +0 -54
  305. package/codeAgent/agent/akanContextFiles.test.ts +0 -116
  306. package/codeAgent/agent/akanSystemPrompt.ts +0 -50
  307. package/codeAgent/agent/codeAgent.test.ts +0 -337
  308. package/codeAgent/agent/codeAgentCommandLine.test.ts +0 -212
  309. package/codeAgent/agent/codeAgentContract.test.ts +0 -755
  310. package/codeAgent/agent/codeAgentHosts.ts +0 -30
  311. package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
  312. package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
  313. package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
  314. package/codeAgent/agent/codeMailbox.test.ts +0 -76
  315. package/codeAgent/agent/codeSessionFork.test.ts +0 -58
  316. package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
  317. package/codeAgent/agent/consoleToStderr.ts +0 -8
  318. package/codeAgent/agent/jsonLines.ts +0 -29
  319. package/codeAgent/agent/stringArg.ts +0 -5
  320. package/codeAgent/feedback/DevLogFeedback.ts +0 -82
  321. package/codeAgent/feedback/PreviewFeedback.ts +0 -46
  322. package/codeAgent/feedback/TurnFeedback.ts +0 -98
  323. package/codeAgent/feedback/VerifyFeedback.ts +0 -39
  324. package/codeAgent/tools/AkanCli.ts +0 -51
  325. package/codeAgent/tools/AkanCodePlugins.ts +0 -142
  326. package/codeAgent/tools/AkanEditScope.ts +0 -53
  327. package/codeAgent/tools/AkanEnvKeys.ts +0 -50
  328. package/codeAgent/tools/AkanToolPack.ts +0 -86
  329. package/codeAgent/tools/AkanVerifier.ts +0 -30
  330. package/codeAgent/tools/AskToolPack.ts +0 -99
  331. package/codeAgent/tools/DeepSeekWeb.ts +0 -127
  332. package/codeAgent/tools/MailToolPack.ts +0 -76
  333. package/codeAgent/tools/McpClient.ts +0 -209
  334. package/codeAgent/tools/McpOAuth.ts +0 -233
  335. package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
  336. package/codeAgent/tools/McpServerConfig.ts +0 -131
  337. package/codeAgent/tools/McpSignIn.ts +0 -158
  338. package/codeAgent/tools/McpTokenStore.ts +0 -128
  339. package/codeAgent/tools/McpToolPack.ts +0 -206
  340. package/codeAgent/tools/SessionToolPack.ts +0 -91
  341. package/codeAgent/tools/WebToolPack.ts +0 -315
  342. package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
  343. package/codeAgent/tools/askToolPack.test.ts +0 -116
  344. package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
  345. package/codeAgent/tools/mcpOAuth.test.ts +0 -648
  346. package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
  347. package/piDependencyPins.test.ts +0 -45
@@ -0,0 +1,172 @@
1
+ import { beforeAll, describe, expect, test } from "bun:test";
2
+ import { type RuntimeFamily, RuntimeNameTable } from "./runtimeNameTable";
3
+ import { runtimeFixtureLayer, runtimeFixtureTables, runtimeUploadTable } from "./runtimeTable.fixture";
4
+
5
+ let demo: RuntimeNameTable;
6
+ let kit: RuntimeNameTable;
7
+
8
+ beforeAll(async () => {
9
+ ({ demo, kit } = await runtimeFixtureTables());
10
+ });
11
+
12
+ const entryOf = (table: RuntimeNameTable, family: RuntimeFamily, key: string) => {
13
+ const entry = table.lookup(family, key);
14
+ if (!entry) return null;
15
+ const ids = (owners: { scope: string; module: string }[]) => owners.map(({ scope, module }) => `${scope}/${module}`);
16
+ return { owners: ids(entry.owners), definedBy: ids(entry.definedBy), base: entry.base };
17
+ };
18
+
19
+ describe("RuntimeNameTable", () => {
20
+ test("gives a lib's name to the app module that extends it, and keeps the lib's own module when nothing does", () => {
21
+ expect(entryOf(demo, "st.use", "noteCount")).toEqual({
22
+ owners: ["apps/demo/note"],
23
+ definedBy: ["libs/kit/note"],
24
+ base: null,
25
+ });
26
+ expect(entryOf(demo, "st.do", "setBodyOnNote")?.owners).toEqual(["apps/demo/note"]);
27
+ expect(entryOf(demo, "st.slice", "noteInKit")?.owners).toEqual(["apps/demo/note"]);
28
+ expect(entryOf(demo, "fetch", "getNoteInitInKit")?.owners).toEqual(["apps/demo/note"]);
29
+ expect(entryOf(demo, "st.do", "pickLabel")?.owners).toEqual(["libs/kit/util"]);
30
+ expect(entryOf(kit, "st.use", "noteCount")?.owners).toEqual(["libs/kit/note"]);
31
+ expect(entryOf(kit, "st.do", "clearDraft")).toBeNull();
32
+ });
33
+
34
+ test("reads the generated store, form, slice and fetch names a module declares", () => {
35
+ const owned = (family: RuntimeFamily, keys: string[]) =>
36
+ keys.map((key) => entryOf(demo, family, key)?.owners.join(",") ?? `${family}.${key} missing`);
37
+ expect(owned("st.use", ["memo", "memoForm", "draft", "draftLength", "memoListInBoard"])).toEqual(
38
+ Array(5).fill("apps/demo/memo"),
39
+ );
40
+ expect(
41
+ owned("st.do", ["clearDraft", "setDraft", "setTitleOnMemo", "addTagsOnMemo", "setIdOnMemo", "initMemoInBoard"]),
42
+ ).toEqual(Array(6).fill("apps/demo/memo"));
43
+ expect(
44
+ owned("fetch", ["memoNote", "memoTyping", "listenMemoTyping", "subscribeMemoLiveInBoard", "lightMemo"]),
45
+ ).toEqual(Array(5).fill("apps/demo/memo"));
46
+ expect(owned("fetch.slice", ["memoInBoard"])).toEqual(["apps/demo/memo"]);
47
+ expect(owned("sig", ["memo"])).toEqual(["apps/demo/memo"]);
48
+ });
49
+
50
+ test("leaves out the fetch name of a verb the slice denies, not the store action", () => {
51
+ expect(entryOf(demo, "fetch", "removeMemo")).toBeNull();
52
+ expect(entryOf(demo, "fetch", "removeNote")?.owners).toEqual(["apps/demo/note"]);
53
+ expect(entryOf(demo, "st.do", "removeMemo")?.owners).toEqual(["apps/demo/memo"]);
54
+ });
55
+
56
+ test("marks the framework's own names with no owner", () => {
57
+ expect(entryOf(demo, "st.do", "setPath")).toEqual({ owners: [], definedBy: [], base: "store" });
58
+ expect(entryOf(demo, "fetch", "ping")).toEqual({ owners: [], definedBy: [], base: "descriptor" });
59
+ expect(entryOf(demo, "fetch.serializedSignal", "agent")?.base).toBe("descriptor");
60
+ });
61
+
62
+ test("says which names need their module's store and which only its descriptor", () => {
63
+ const needs = (family: RuntimeFamily, keys: string[]) => keys.map((key) => demo.lookup(family, key)?.needs);
64
+ expect(needs("fetch", ["memoNote", "listenMemoTyping", "memo", "lightMemo", "createMemo", "mergeMemo"])).toEqual(
65
+ Array(6).fill("descriptor"),
66
+ );
67
+ expect(
68
+ needs("fetch", [
69
+ "viewMemo",
70
+ "getMemoView",
71
+ "editMemo",
72
+ "getMemoEdit",
73
+ "memoListInBoard",
74
+ "memoInsightInBoard",
75
+ "initMemoInBoard",
76
+ "getMemoInitInBoard",
77
+ "subscribeMemoLiveInBoard",
78
+ ]),
79
+ ).toEqual(Array(9).fill("store"));
80
+ expect([
81
+ ...needs("st.do", ["clearDraft"]),
82
+ ...needs("fetch.slice", ["memoInBoard"]),
83
+ ...needs("sig", ["memo"]),
84
+ ...needs("fetch.serializedSignal", ["memo"]),
85
+ ]).toEqual(Array(4).fill("store"));
86
+ });
87
+
88
+ test("names the file-upload module an upload reads as it runs, and as a dependency of each store with a file field", async () => {
89
+ const fk = await runtimeUploadTable();
90
+ const usesOf = (family: RuntimeFamily, key: string) =>
91
+ fk.lookup(family, key)?.uses.map(({ scope, module }) => `${scope}/${module}`);
92
+ expect(usesOf("st.do", "uploadImageOnUser")).toEqual(["libs/fk/file"]);
93
+ expect(usesOf("fetch", "addUserFiles")).toEqual(["libs/fk/file"]);
94
+ expect(usesOf("st.do", "setImageOnUser")).toEqual([]);
95
+ expect(fk.dependenciesOf("libs/fk", "user")).toEqual([{ scope: "libs/fk", module: "file" }]);
96
+ expect(fk.dependenciesOf("libs/fk", "file")).toEqual([]);
97
+ expect(demo.dependenciesOf("apps/demo", "memo")).toEqual([]);
98
+ });
99
+
100
+ test("names the file-upload module as a dependency of an app store that extends a lib store and has no signal of its own", async () => {
101
+ const taleLib = runtimeFixtureLayer("libs/pk", {
102
+ "libs/pk/lib/tale/tale.constant.ts": `import { via } from "akanjs/constant";
103
+
104
+ export class TaleInput extends via((field) => ({ title: field(String) })) {}
105
+ export class TaleObject extends via(TaleInput, (field) => ({})) {}
106
+ export class LightTale extends via(TaleObject, ["title"] as const, (resolve) => ({})) {}
107
+ export class Tale extends via(TaleObject, LightTale, (resolve) => ({})) {}
108
+ `,
109
+ "libs/pk/lib/tale/tale.signal.ts": `import { Public, slice } from "akanjs/signal";
110
+
111
+ import * as srv from "../srv";
112
+
113
+ export class TaleSlice extends slice(srv.tale, { guards: { get: Public, cru: Public } }, () => ({})) {}
114
+ `,
115
+ "libs/pk/lib/tale/tale.store.ts": `import { store } from "akanjs/store";
116
+
117
+ import { sig } from "../useClient";
118
+
119
+ export class TaleStore extends store(sig.tale, () => ({})) {}
120
+ `,
121
+ });
122
+ const desk = runtimeFixtureLayer("apps/desk", {
123
+ "apps/desk/lib/tale/tale.constant.ts": `import { via } from "akanjs/constant";
124
+
125
+ import { tale } from "../__lib/lib.constant";
126
+ import { File } from "../cnst";
127
+
128
+ export class TaleInput extends via((field) => ({ cover: field(File) }), ...tale.inputs) {}
129
+ export class TaleObject extends via(TaleInput, (field) => ({}), ...tale.objects) {}
130
+ export class LightTale extends via(TaleObject, ["cover"] as const, (resolve) => ({}), ...tale.lights) {}
131
+ export class Tale extends via(TaleObject, LightTale, (resolve) => ({}), ...tale.models) {}
132
+ `,
133
+ "apps/desk/lib/tale/tale.store.ts": `import { store } from "akanjs/store";
134
+
135
+ import { tale } from "../__lib/lib.store";
136
+ import { sig } from "../useClient";
137
+
138
+ export class TaleStore extends store(sig.tale, () => ({ shelf: "" }), ...tale.stores) {}
139
+ `,
140
+ });
141
+ const table = await runtimeUploadTable([taleLib, desk]);
142
+ expect(table.dependenciesOf("apps/desk", "tale")).toEqual([{ scope: "libs/fk", module: "file" }]);
143
+ expect((await runtimeUploadTable([taleLib])).dependenciesOf("libs/pk", "tale")).toEqual([]);
144
+ });
145
+
146
+ test("names its scope and layers, innermost first, and reads no table for a scope with no generated runtime", async () => {
147
+ expect([demo.scope, ...demo.layers.map(({ scope }) => scope)]).toEqual(["apps/demo", "libs/kit", "apps/demo"]);
148
+ expect(demo.approximations).toEqual([]);
149
+ expect(await RuntimeNameTable.read(import.meta.dir, "apps/none")).toBeNull();
150
+ });
151
+
152
+ test("says which declarations it reads approximately", () => {
153
+ const layer = runtimeFixtureLayer("apps/odd", {
154
+ "apps/odd/lib/odd/odd.signal.ts": `import { endpoint, slice } from "akanjs/signal";
155
+
156
+ export class OddSlice extends slice(srv.odd, { guards: guardsOf("odd") }, (init) => ({ ...shared })) {}
157
+
158
+ export class OddEndpoint extends endpoint(srv.odd, ({ query }) => ({ [name]: query(String) })) {}
159
+ `,
160
+ "apps/odd/lib/odd/odd.store.ts": `import { store } from "akanjs/store";
161
+
162
+ export class OddStore extends store(sig.odd, () => ({ ...initial, count: 0 })) {}
163
+ `,
164
+ });
165
+ expect(layer.approximations).toEqual([
166
+ "apps/odd/lib/odd/odd.store.ts:3:55: a state key is spread or computed",
167
+ "apps/odd/lib/odd/odd.signal.ts:5:70: a signal key is spread or computed",
168
+ "apps/odd/lib/odd/odd.signal.ts:3:88: a signal key is spread or computed",
169
+ "apps/odd/lib/odd/odd.signal.ts:3:31: slice guards are not an object literal",
170
+ ]);
171
+ });
172
+ });
@@ -0,0 +1,477 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import {
4
+ capitalize,
5
+ databaseStateNames,
6
+ endpointNames,
7
+ formSetterNames,
8
+ modelNames,
9
+ sliceNames,
10
+ stateSetterName,
11
+ } from "akanjs/common";
12
+ import ts from "typescript";
13
+ import { type RuntimeConstantEntry, type RuntimeConstantFact, RuntimeConstantFacts } from "./runtimeConstantFacts";
14
+ import {
15
+ type RuntimeFieldFact,
16
+ type RuntimeLayer,
17
+ type RuntimeModuleFact,
18
+ RuntimeModuleFacts,
19
+ type RuntimeSourceFile,
20
+ type RuntimeVerbGuards,
21
+ } from "./runtimeModuleFacts";
22
+
23
+ export const runtimeFamilies = [
24
+ "st.do",
25
+ "st.use",
26
+ "st.slice",
27
+ "fetch",
28
+ "fetch.slice",
29
+ "sig",
30
+ "fetch.serializedSignal",
31
+ ] as const;
32
+ export type RuntimeFamily = (typeof runtimeFamilies)[number];
33
+
34
+ export interface RuntimeOwner {
35
+ scope: string;
36
+ module: string;
37
+ }
38
+
39
+ export type RuntimeNeed = "store" | "descriptor";
40
+
41
+ export interface RuntimeNameEntry {
42
+ owners: RuntimeOwner[];
43
+ definedBy: RuntimeOwner[];
44
+ base: RuntimeNeed | null;
45
+ needs: RuntimeNeed;
46
+ uses: RuntimeOwner[];
47
+ }
48
+
49
+ interface RuntimeAddOptions {
50
+ needs?: RuntimeNeed;
51
+ uses?: RuntimeOwner | null;
52
+ }
53
+
54
+ interface EffectiveSignal {
55
+ endpoints: { name: string; verb: string | null; by: RuntimeModuleFact }[];
56
+ slices: { suffix: string; live: boolean; by: RuntimeModuleFact }[] | null;
57
+ guards: RuntimeVerbGuards | null;
58
+ }
59
+
60
+ const modelActionRoles = [
61
+ "createModelInForm",
62
+ "updateModelInForm",
63
+ "checkModelSubmitable",
64
+ "submitModel",
65
+ "createModel",
66
+ "updateModel",
67
+ "removeModel",
68
+ "mergeModel",
69
+ "newModel",
70
+ "editModel",
71
+ "viewModel",
72
+ "setModel",
73
+ "resetModel",
74
+ "invalidateModel",
75
+ "loadModelFormDraft",
76
+ "restoreModelFormDraft",
77
+ "discardModelFormDraft",
78
+ "writeOnModel",
79
+ ] as const satisfies (keyof ReturnType<typeof modelNames>)[];
80
+
81
+ export const baseScope = "akanjs";
82
+
83
+ export class RuntimeNameTable {
84
+ readonly #entries = new Map<RuntimeFamily, Map<string, RuntimeNameEntry>>(
85
+ runtimeFamilies.map((family) => [family, new Map()]),
86
+ );
87
+ readonly #dependencies = new Map<string, RuntimeOwner[]>();
88
+ readonly #constants = new Map<string, Map<string, RuntimeConstantEntry | null>>();
89
+ readonly #file: { refName: string; owner: RuntimeOwner | null } | null;
90
+ readonly scope: string;
91
+ readonly layers: RuntimeLayer[];
92
+ readonly approximations: string[];
93
+
94
+ static async read(workspaceRoot: string, scope: string) {
95
+ const scopes = await RuntimeNameTable.#scopesOf(workspaceRoot, scope);
96
+ return scopes ? RuntimeNameTable.readScopes(workspaceRoot, scopes) : null;
97
+ }
98
+
99
+ //? `scopes` in load order, each lib before the scope mounting it: what `akan sync` knows before `lib/st.ts` exists.
100
+ static async readScopes(workspaceRoot: string, scopes: string[]) {
101
+ const layers = await Promise.all(
102
+ scopes.map((layerScope) => RuntimeNameTable.#readLayer(workspaceRoot, layerScope)),
103
+ );
104
+ return RuntimeNameTable.fromLayers(layers, await RuntimeNameTable.readBase(workspaceRoot));
105
+ }
106
+
107
+ static async readBase(workspaceRoot: string): Promise<RuntimeLayer> {
108
+ const akanjsRoot = path.dirname(Bun.resolveSync("akanjs/package.json", workspaceRoot));
109
+ const sourceOf = async (file: string) => RuntimeNameTable.#parse(file, path.join(akanjsRoot, file));
110
+ const [store, baseSignal, agentSignal] = await Promise.all(
111
+ ["store/baseSt.ts", "signal/base.signal.ts", "signal/agent.signal.ts"].map(sourceOf),
112
+ );
113
+ const approximations: string[] = [];
114
+ const baseStore = RuntimeModuleFacts.storeOf(store, approximations);
115
+ const signalOf = (source: RuntimeSourceFile, refName: string) =>
116
+ RuntimeModuleFacts.signalOf(source, refName, approximations);
117
+ return {
118
+ scope: baseScope,
119
+ modules: [
120
+ {
121
+ scope: baseScope,
122
+ module: "agent",
123
+ kind: "service",
124
+ signal: signalOf(agentSignal, "agent"),
125
+ store: null,
126
+ model: null,
127
+ },
128
+ {
129
+ scope: baseScope,
130
+ module: "base",
131
+ kind: "service",
132
+ signal: signalOf(baseSignal, "base"),
133
+ store: baseStore,
134
+ model: null,
135
+ },
136
+ ],
137
+ approximations,
138
+ };
139
+ }
140
+
141
+ static fromLayers(layers: RuntimeLayer[], base: RuntimeLayer) {
142
+ return new RuntimeNameTable(layers, base);
143
+ }
144
+
145
+ private constructor(layers: RuntimeLayer[], base: RuntimeLayer) {
146
+ this.scope = layers.at(-1)?.scope ?? baseScope;
147
+ this.layers = layers;
148
+ this.approximations = [...base.approximations, ...layers.flatMap((layer) => layer.approximations)];
149
+ const ordered = [base, ...layers];
150
+ const fileRefName = RuntimeNameTable.#fileUploadRefNameOf(ordered);
151
+ this.#file = fileRefName
152
+ ? { refName: fileRefName, owner: RuntimeNameTable.#outermostOf(ordered, fileRefName, "signal") }
153
+ : null;
154
+ ordered.forEach((layer, index) => {
155
+ for (const module of layer.modules) this.#addModule(ordered, index, module);
156
+ });
157
+ for (const layer of layers) this.#constants.set(layer.scope, RuntimeNameTable.#constantNamesOf(layer, layers));
158
+ }
159
+
160
+ constantOf(scope: string, name: string): RuntimeConstantEntry | null {
161
+ return this.#constants.get(scope)?.get(name) ?? null;
162
+ }
163
+
164
+ constantsOf(scope: string): RuntimeConstantFact[] {
165
+ return this.layers.find((layer) => layer.scope === scope)?.constants ?? [];
166
+ }
167
+
168
+ static #constantNamesOf(layer: RuntimeLayer, layers: RuntimeLayer[]) {
169
+ const names = new Map<string, RuntimeConstantEntry | null>();
170
+ //? `export *` of two constant files naming one value exports neither, so the name is left unanswered.
171
+ for (const fact of layer.constants ?? [])
172
+ for (const name of fact.exports) names.set(name, names.has(name) ? null : { type: "export", fact });
173
+ for (const fact of layer.constants ?? []) names.set(fact.module, { type: "model", fact });
174
+ for (const lib of layer.constantLibs ?? [])
175
+ if (layers.some(({ scope }) => scope === `libs/${lib}`))
176
+ names.set(lib, { type: "namespace", scope: `libs/${lib}` });
177
+ return names;
178
+ }
179
+
180
+ get modules() {
181
+ return this.layers.flatMap((layer) => layer.modules);
182
+ }
183
+
184
+ lookup(family: RuntimeFamily, key: string): RuntimeNameEntry | null {
185
+ return this.#entries.get(family)?.get(key) ?? null;
186
+ }
187
+
188
+ keysOf(family: RuntimeFamily) {
189
+ return [...(this.#entries.get(family)?.keys() ?? [])].sort();
190
+ }
191
+
192
+ //? `store()` picks upload setters from the file module's descriptor when the class is defined, so it loads first.
193
+ dependenciesOf(scope: string, module: string): RuntimeOwner[] {
194
+ return this.#dependencies.get(`${scope}/${module}`) ?? [];
195
+ }
196
+
197
+ #addModule(ordered: RuntimeLayer[], index: number, module: RuntimeModuleFact) {
198
+ const definer = RuntimeNameTable.#definerOf(module);
199
+ if (module.signal)
200
+ this.#add(
201
+ "fetch.serializedSignal",
202
+ module.module,
203
+ definer,
204
+ RuntimeNameTable.#outermostOf(ordered, module.module, "signal"),
205
+ );
206
+ if (module.store) this.#addStore(ordered, index, module);
207
+ if (module.signal && index === RuntimeNameTable.#outermostIndexOf(ordered, module.module, "signal"))
208
+ this.#addSignal(ordered, index, module);
209
+ }
210
+
211
+ #addStore(ordered: RuntimeLayer[], index: number, module: RuntimeModuleFact) {
212
+ const store = module.store;
213
+ if (!store) return;
214
+ const definer = RuntimeNameTable.#definerOf(module);
215
+ const owner = RuntimeNameTable.#headOf(ordered, index, module.module, "store");
216
+ const state = this.#storeState(ordered, index, module);
217
+ const derived = new Set(store.derived);
218
+ const setters = state.filter((key) => !derived.has(key)).map(stateSetterName);
219
+ for (const key of state) this.#add("st.use", key, definer, owner);
220
+ for (const key of [...setters, ...store.actions]) this.#add("st.do", key, definer, owner);
221
+ if (!store.signal) return;
222
+ const { actions, uploads } = this.#generatedActions(ordered, index, module);
223
+ const uses = this.#fileOwnerFor(module);
224
+ if (uploads.length && uses) this.#dependencies.set(`${module.scope}/${module.module}`, [uses]);
225
+ if (!module.signal) return;
226
+ for (const key of actions) this.#add("st.do", key, definer, owner);
227
+ for (const key of uploads) this.#add("st.do", key, definer, owner, { uses });
228
+ //? The root store keeps one slice map per model, the outermost store's.
229
+ if (index !== RuntimeNameTable.#outermostIndexOf(ordered, module.module, "store")) return;
230
+ for (const { suffix, by } of RuntimeNameTable.#effectiveSignalOf(ordered, index, module.module).slices ?? [])
231
+ this.#add("st.slice", sliceNames(module.module, suffix).slice, RuntimeNameTable.#definerOf(by), owner);
232
+ }
233
+
234
+ #addSignal(ordered: RuntimeLayer[], index: number, module: RuntimeModuleFact) {
235
+ const owner = RuntimeNameTable.#outermostOf(ordered, module.module, "signal");
236
+ const definer = RuntimeNameTable.#definerOf(module);
237
+ const effective = RuntimeNameTable.#effectiveSignalOf(ordered, index, module.module);
238
+ for (const { name, verb, by } of effective.endpoints) {
239
+ const endpointDefiner = RuntimeNameTable.#definerOf(by);
240
+ const plain = { needs: "descriptor" } as const;
241
+ this.#add("fetch", verb === "pubsub" ? endpointNames(name).subscribe : name, endpointDefiner, owner, plain);
242
+ if (verb === "message") this.#add("fetch", endpointNames(name).listen, endpointDefiner, owner, plain);
243
+ }
244
+ if (!effective.slices || !effective.guards) return;
245
+ if (module.kind === "database") this.#add("sig", module.module, definer, owner);
246
+ const names = modelNames(module.module);
247
+ const mounted = (verb: keyof RuntimeVerbGuards) => !!effective.guards?.[verb]?.some((guard) => guard !== "None");
248
+ const write = mounted("create") || mounted("update") || mounted("remove");
249
+ const requests = [
250
+ ...(mounted("get") ? [names.model, names.lightModel] : []),
251
+ ...(mounted("create") ? [names.createModel] : []),
252
+ ...(mounted("update") ? [names.updateModel, names.mergeModel] : []),
253
+ ...(mounted("remove") ? [names.removeModel] : []),
254
+ ];
255
+ const handles = [
256
+ ...(mounted("get") ? [names.viewModel, names.getModelView] : []),
257
+ ...(mounted("get") && write ? [names.editModel, names.getModelEdit] : []),
258
+ ];
259
+ for (const key of requests) this.#add("fetch", key, definer, owner, { needs: "descriptor" });
260
+ for (const key of handles) this.#add("fetch", key, definer, owner);
261
+ const uses = this.#fileOwnerFor(module);
262
+ this.#add("fetch", names.addModelFiles, definer, owner, { needs: "descriptor", uses });
263
+ for (const { suffix, live, by } of effective.slices) {
264
+ const sliceDefiner = RuntimeNameTable.#definerOf(by);
265
+ const { slice, endpoint } = sliceNames(module.module, suffix);
266
+ for (const key of [endpoint.list, endpoint.insight, endpoint.init, endpoint.getInit])
267
+ this.#add("fetch", key, sliceDefiner, owner);
268
+ if (live) this.#add("fetch", endpoint.subscribeLive, sliceDefiner, owner);
269
+ this.#add("fetch.slice", slice, sliceDefiner, owner);
270
+ }
271
+ }
272
+
273
+ #storeState(ordered: RuntimeLayer[], index: number, module: RuntimeModuleFact) {
274
+ const store = module.store;
275
+ if (!store) return [];
276
+ const generated: string[] = [];
277
+ if (store.signal && module.signal) {
278
+ const { defaultModel: _, ...database } = databaseStateNames(module.module);
279
+ generated.push(...Object.values(database));
280
+ for (const { suffix } of RuntimeNameTable.#effectiveSignalOf(ordered, index, module.module).slices ?? [])
281
+ generated.push(...Object.values(sliceNames(module.module, suffix).state));
282
+ }
283
+ return [...store.state, ...generated, ...store.derived];
284
+ }
285
+
286
+ #fileOwnerFor(module: RuntimeModuleFact) {
287
+ const owner = this.#file?.owner;
288
+ return owner && owner.module !== module.module ? owner : null;
289
+ }
290
+
291
+ #generatedActions(ordered: RuntimeLayer[], index: number, module: RuntimeModuleFact) {
292
+ const fileRefName = this.#file?.refName;
293
+ const names = modelNames(module.module);
294
+ const className = capitalize(module.module);
295
+ const fileTypes = fileRefName
296
+ ? new Set(
297
+ ["", "Light"].flatMap((prefix) =>
298
+ ["", "Input", "Object", "Insight"].map((suffix) => `${prefix}${capitalize(fileRefName)}${suffix}`),
299
+ ),
300
+ )
301
+ : new Set<string>();
302
+ const fields = RuntimeNameTable.#fieldsOf(ordered, module.module);
303
+ const setters = fields.flatMap(({ name, array }) => {
304
+ const field = formSetterNames(className, name);
305
+ return [
306
+ field.setFieldOnModel,
307
+ ...(array ? [field.addFieldOnModel, field.subFieldOnModel, field.addOrSubFieldOnModel] : []),
308
+ ];
309
+ });
310
+ const uploads = fields
311
+ .filter(({ type }) => type && fileTypes.has(type))
312
+ .map(({ name }) => formSetterNames(className, name).uploadFieldOnModel);
313
+ const sliceActions = (RuntimeNameTable.#effectiveSignalOf(ordered, index, module.module).slices ?? []).flatMap(
314
+ ({ suffix }) => Object.values(sliceNames(module.module, suffix).action),
315
+ );
316
+ return { actions: [...setters, ...modelActionRoles.map((role) => names[role]), ...sliceActions], uploads };
317
+ }
318
+
319
+ #add(
320
+ family: RuntimeFamily,
321
+ key: string,
322
+ definedBy: RuntimeOwner | null,
323
+ owner: RuntimeOwner | null,
324
+ { needs = "store", uses = null }: RuntimeAddOptions = {},
325
+ ) {
326
+ const entries = this.#entries.get(family);
327
+ if (!entries) return;
328
+ const entry = entries.get(key) ?? { owners: [], definedBy: [], base: null, needs, uses: [] };
329
+ if (!definedBy) entry.base = family.startsWith("st.") ? "store" : "descriptor";
330
+ if (needs === "store") entry.needs = "store";
331
+ const has = (list: RuntimeOwner[], target: RuntimeOwner) =>
332
+ list.some(({ scope, module }) => scope === target.scope && module === target.module);
333
+ if (definedBy && !has(entry.definedBy, definedBy)) entry.definedBy.push(definedBy);
334
+ if (owner && !has(entry.owners, owner)) entry.owners.push(owner);
335
+ if (uses && !has(entry.uses, uses)) entry.uses.push(uses);
336
+ entries.set(key, entry);
337
+ }
338
+
339
+ //? A module's whole model reaches every layer: an app's fields land on the lib's full model class too.
340
+ static #fieldsOf(ordered: RuntimeLayer[], refName: string) {
341
+ const baseFields = ["id", "createdAt", "updatedAt", "removedAt"].map(
342
+ (name): RuntimeFieldFact => ({
343
+ name,
344
+ type: null,
345
+ array: false,
346
+ }),
347
+ );
348
+ const fields = new Map(baseFields.map((field) => [field.name, field]));
349
+ for (const layer of ordered)
350
+ for (const module of layer.modules)
351
+ if (module.module === refName)
352
+ for (const field of module.model?.fields ?? []) if (!fields.has(field.name)) fields.set(field.name, field);
353
+ return [...fields.values()];
354
+ }
355
+
356
+ //? The first `fileUpload: true` endpoint in load order wins, as `resolveFileUploadCapability` picks it at runtime.
357
+ static #fileUploadRefNameOf(ordered: RuntimeLayer[]) {
358
+ for (const layer of ordered)
359
+ for (const kind of ["database", "service"] as const)
360
+ for (const module of layer.modules)
361
+ if (module.kind === kind && module.signal?.endpoints.some(({ fileUpload }) => fileUpload))
362
+ return module.module;
363
+ return null;
364
+ }
365
+
366
+ static #effectiveSignalOf(ordered: RuntimeLayer[], index: number, refName: string): EffectiveSignal {
367
+ const endpoints: EffectiveSignal["endpoints"] = [];
368
+ const slices: NonNullable<EffectiveSignal["slices"]> = [];
369
+ let guards: RuntimeVerbGuards | null = null;
370
+ let hasSlice = false;
371
+ for (let at = index; at >= 0; at--) {
372
+ const module = ordered[at]?.modules.find((candidate) => candidate.module === refName && candidate.signal);
373
+ if (!module?.signal) continue;
374
+ const own = at === index;
375
+ for (const { name, verb } of module.signal.endpoints)
376
+ if (!endpoints.some((endpoint) => endpoint.name === name)) endpoints.push({ name, verb, by: module });
377
+ if (module.signal.slice) {
378
+ hasSlice = true;
379
+ if (own) guards = module.signal.slice.guards;
380
+ if (own && module.signal.slice.guards.root !== null && !slices.some(({ suffix }) => suffix === ""))
381
+ slices.push({ suffix: "", live: false, by: module });
382
+ for (const { name, live } of module.signal.slice.keys)
383
+ if (!slices.some(({ suffix }) => suffix === name)) slices.push({ suffix: name, live, by: module });
384
+ }
385
+ if (!module.signal.extendsLib) break;
386
+ }
387
+ return { endpoints, slices: hasSlice ? slices : null, guards };
388
+ }
389
+
390
+ static #outermostIndexOf(ordered: RuntimeLayer[], refName: string, kind: "store" | "signal") {
391
+ return ordered.findLastIndex((layer) => layer.modules.some((module) => module.module === refName && module[kind]));
392
+ }
393
+
394
+ static #outermostOf(ordered: RuntimeLayer[], refName: string, kind: "store" | "signal") {
395
+ const module = ordered[RuntimeNameTable.#outermostIndexOf(ordered, refName, kind)]?.modules.find(
396
+ (candidate) => candidate.module === refName && candidate[kind],
397
+ );
398
+ return module ? RuntimeNameTable.#definerOf(module) : null;
399
+ }
400
+
401
+ //? An outer module that spreads its lib's declarations loads them, so it answers for the lib's names too.
402
+ static #headOf(ordered: RuntimeLayer[], index: number, refName: string, kind: "store" | "signal") {
403
+ let head = ordered[index]?.modules.find((module) => module.module === refName && module[kind]);
404
+ for (let at = index + 1; at < ordered.length && head; at++) {
405
+ const outer = ordered[at]?.modules.find((module) => module.module === refName && module[kind]);
406
+ if (!outer) continue;
407
+ if (!(kind === "store" ? outer.store?.extendsLib : outer.signal?.extendsLib)) break;
408
+ head = outer;
409
+ }
410
+ return head ? RuntimeNameTable.#definerOf(head) : null;
411
+ }
412
+
413
+ static #definerOf(module: RuntimeModuleFact): RuntimeOwner | null {
414
+ return module.scope === baseScope ? null : { scope: module.scope, module: module.module };
415
+ }
416
+
417
+ static async #scopesOf(workspaceRoot: string, scope: string, seen = new Set<string>()): Promise<string[] | null> {
418
+ if (seen.has(scope)) return [];
419
+ seen.add(scope);
420
+ const storeFile = Bun.file(path.join(workspaceRoot, scope, "lib/st.ts"));
421
+ if (!(await storeFile.exists())) return null;
422
+ const libs = [...(await storeFile.text()).matchAll(/from\s+["']@libs\/([^/"']+)\/client["']/g)].map(
423
+ ([, lib]) => lib,
424
+ );
425
+ const ordered: string[] = [];
426
+ for (const lib of libs.filter((lib): lib is string => !!lib)) {
427
+ const inner = await RuntimeNameTable.#scopesOf(workspaceRoot, `libs/${lib}`, seen);
428
+ if (!inner) return null;
429
+ ordered.push(...inner);
430
+ }
431
+ return [...ordered, scope];
432
+ }
433
+
434
+ static async #readLayer(workspaceRoot: string, scope: string) {
435
+ const libDir = path.join(workspaceRoot, scope, "lib");
436
+ const dirs = (await readdir(libDir, { withFileTypes: true }))
437
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith("__"))
438
+ .map((entry) => entry.name)
439
+ .sort();
440
+ const files = await Promise.all(
441
+ dirs.flatMap((dir) =>
442
+ ["signal", "store", "constant"].map(async (role) => {
443
+ const file = `${scope}/lib/${dir}/${dir.replace(/^_/, "")}.${role}.ts`;
444
+ const absolute = path.join(workspaceRoot, file);
445
+ return (await Bun.file(absolute).exists()) ? RuntimeNameTable.#parse(file, absolute) : null;
446
+ }),
447
+ ),
448
+ );
449
+ const scalarDir = path.join(libDir, "__scalar");
450
+ const scalars = await Promise.all(
451
+ (await readdir(scalarDir, { withFileTypes: true }).catch(() => []))
452
+ .filter((entry) => entry.isDirectory())
453
+ .map(async ({ name }) => {
454
+ const file = `${scope}/lib/__scalar/${name}/${name}.constant.ts`;
455
+ const absolute = path.join(workspaceRoot, file);
456
+ return (await Bun.file(absolute).exists()) ? RuntimeNameTable.#parse(file, absolute) : null;
457
+ }),
458
+ );
459
+ const read = files.filter((file): file is RuntimeSourceFile => !!file);
460
+ const constants = [...read, ...scalars.filter((file): file is RuntimeSourceFile => !!file)]
461
+ .map((source) => RuntimeConstantFacts.of(source))
462
+ .filter((fact): fact is RuntimeConstantFact => !!fact)
463
+ .sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
464
+ const cnstFile = Bun.file(path.join(libDir, "cnst.ts"));
465
+ const constantLibs = (await cnstFile.exists())
466
+ ? [...(await cnstFile.text()).matchAll(/export\s*\{\s*cnst\s+as\s+(\w+)\s*\}\s*from\s*["']@libs\/(\w+)["']/g)]
467
+ .filter(([, name, lib]) => name === lib)
468
+ .map(([, name]) => name as string)
469
+ : [];
470
+ return { ...RuntimeModuleFacts.layerOf(scope, read), constants, constantLibs };
471
+ }
472
+
473
+ static async #parse(file: string, absolute: string): Promise<RuntimeSourceFile> {
474
+ const text = await Bun.file(absolute).text();
475
+ return { file, sourceFile: ts.createSourceFile(absolute, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS) };
476
+ }
477
+ }