akanjs 3.0.2 → 3.1.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 (378) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/base/baseEnv.ts +0 -4
  3. package/base/primitiveRegistry.ts +2 -2
  4. package/client/cookie.ts +5 -1
  5. package/client/csrLocation.ts +122 -0
  6. package/client/csrTypes.ts +32 -4
  7. package/client/device.ts +2 -1
  8. package/client/frameConfig.ts +78 -7
  9. package/client/index.ts +3 -0
  10. package/client/makePageProto.tsx +3 -2
  11. package/client/native/external-view.ts +1 -0
  12. package/client/route/RootLayoutDefinition.ts +7 -1
  13. package/client/route/RouteHead.ts +108 -0
  14. package/client/route/index.ts +1 -0
  15. package/client/router.ts +36 -23
  16. package/client/rscNavigation.ts +8 -2
  17. package/client/viewportMeta.ts +60 -0
  18. package/client/webManifest.ts +18 -0
  19. package/common/Logger.ts +7 -2
  20. package/common/PipelineNames.ts +31 -0
  21. package/common/PipelinePattern.ts +70 -0
  22. package/common/PipelinePlanSchema.ts +490 -0
  23. package/common/backoff.ts +14 -0
  24. package/common/index.ts +39 -0
  25. package/common/pipelinePlan.ts +259 -0
  26. package/common/routeConvention.ts +1 -0
  27. package/common/types.ts +17 -0
  28. package/constant/constantRegistry.ts +26 -6
  29. package/dictionary/base.dictionary.ts +8 -0
  30. package/dictionary/trans.ts +9 -1
  31. package/document/into.ts +5 -0
  32. package/fetch/client/fetchClient.ts +135 -31
  33. package/fetch/client/httpClient.ts +45 -0
  34. package/fetch/client/wsClient.ts +125 -16
  35. package/fetch/fetchType/buildFetch.type.ts +1 -0
  36. package/index.ts +243 -10
  37. package/package.json +1 -5
  38. package/server/akanApp.ts +5 -2
  39. package/server/akanServer.ts +44 -8
  40. package/server/artifact/builderRpc.ts +8 -3
  41. package/server/artifact/ipcTypes.ts +5 -2
  42. package/server/di/diLifecycle.ts +39 -3
  43. package/server/di/utils.ts +28 -1
  44. package/server/ed25519Key.ts +48 -0
  45. package/server/index.ts +1 -0
  46. package/server/machine/index.ts +2 -0
  47. package/server/machine/machineAccount.ts +27 -0
  48. package/server/machine/machineToken.ts +151 -0
  49. package/server/mcp/McpApps.ts +256 -0
  50. package/server/mcp/McpDispatcher.ts +31 -7
  51. package/server/mcp/McpRouter.ts +209 -46
  52. package/server/ops/opsToken.ts +3 -10
  53. package/server/resolver/database.resolver.ts +3 -0
  54. package/server/resolver/signal.resolver.ts +40 -3
  55. package/server/routeElementComposer.tsx +78 -2
  56. package/server/routeState.ts +6 -0
  57. package/server/routeTreeBuilder.ts +26 -9
  58. package/server/routing/apiRouter.ts +6 -3
  59. package/server/routing/roomReplay.ts +88 -0
  60. package/server/rscClient.tsx +53 -8
  61. package/server/rscWorker.tsx +141 -27
  62. package/server/rscWorkerHost.ts +18 -5
  63. package/server/sitemap.ts +14 -0
  64. package/server/ssrFromRscRenderer.tsx +12 -6
  65. package/server/ssrTypes.ts +3 -1
  66. package/server/systemPageDocument.tsx +38 -30
  67. package/server/types.tsx +2 -0
  68. package/server/webRouter.ts +74 -5
  69. package/service/injectInfo.ts +9 -1
  70. package/service/ipcTypes.ts +2 -1
  71. package/service/predefinedAdaptor/database.adaptor.ts +1 -146
  72. package/service/predefinedAdaptor/queue.adaptor.ts +44 -6
  73. package/service/predefinedAdaptor/queueBackoff.ts +12 -0
  74. package/service/predefinedAdaptor/solidQueue.adaptor.ts +17 -13
  75. package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +44 -2
  76. package/service/predefinedAdaptor/sql/dialect/postgres.ts +3 -0
  77. package/service/predefinedAdaptor/sql/dialect/sqlite.ts +5 -2
  78. package/service/predefinedAdaptor/sql/search/fts5.ts +1 -1
  79. package/service/predefinedAdaptor/sql/types.ts +8 -6
  80. package/service/predefinedAdaptor/sql/values.ts +0 -23
  81. package/service/serve.ts +5 -1
  82. package/signal/agent.signal.ts +1 -1
  83. package/signal/base.signal.ts +2 -2
  84. package/signal/endpointIdempotency.ts +53 -0
  85. package/signal/internalArg.ts +14 -0
  86. package/signal/mcp/McpDocument.ts +38 -1
  87. package/signal/mcp/mcpProtocol.ts +18 -0
  88. package/signal/signalContext.ts +58 -30
  89. package/signal/signalRegistry.ts +14 -4
  90. package/signal/types.ts +18 -3
  91. package/store/agent/StoreSurfaceSource.ts +1 -1
  92. package/store/agentic/StToolBuilder.ts +3 -0
  93. package/test/conformance.ts +9 -33
  94. package/types/base/baseEnv.d.ts +0 -4
  95. package/types/base/primitiveRegistry.d.ts +1 -1
  96. package/types/client/csrLocation.d.ts +32 -0
  97. package/types/client/csrTypes.d.ts +40 -4
  98. package/types/client/frameConfig.d.ts +14 -2
  99. package/types/client/index.d.ts +3 -0
  100. package/types/client/native/external-view.d.ts +1 -0
  101. package/types/client/route/RootLayoutDefinition.d.ts +2 -1
  102. package/types/client/route/RouteHead.d.ts +13 -0
  103. package/types/client/route/index.d.ts +1 -0
  104. package/types/client/router.d.ts +6 -0
  105. package/types/client/rscNavigation.d.ts +4 -0
  106. package/types/client/viewportMeta.d.ts +18 -0
  107. package/types/client/webManifest.d.ts +4 -0
  108. package/types/common/PipelineNames.d.ts +6 -0
  109. package/types/common/PipelinePattern.d.ts +14 -0
  110. package/types/common/PipelinePlanSchema.d.ts +9 -0
  111. package/types/common/backoff.d.ts +10 -0
  112. package/types/common/index.d.ts +5 -0
  113. package/types/common/pipelinePlan.d.ts +224 -0
  114. package/types/common/types.d.ts +16 -0
  115. package/types/constant/constantRegistry.d.ts +5 -2
  116. package/types/dictionary/base.dictionary.d.ts +1 -1
  117. package/types/dictionary/dictionary.d.ts +8 -8
  118. package/types/document/into.d.ts +9 -0
  119. package/types/fetch/client/fetchClient.d.ts +31 -4
  120. package/types/fetch/client/httpClient.d.ts +8 -0
  121. package/types/fetch/client/wsClient.d.ts +26 -2
  122. package/types/fetch/fetchType/buildFetch.type.d.ts +1 -0
  123. package/types/index.d.ts +230 -9
  124. package/types/server/akanServer.d.ts +16 -1
  125. package/types/server/artifact/builderRpc.d.ts +7 -2
  126. package/types/server/artifact/ipcTypes.d.ts +5 -1
  127. package/types/server/di/utils.d.ts +1 -0
  128. package/types/server/ed25519Key.d.ts +13 -0
  129. package/types/server/index.d.ts +1 -0
  130. package/types/server/machine/index.d.ts +2 -0
  131. package/types/server/machine/machineAccount.d.ts +5 -0
  132. package/types/server/machine/machineToken.d.ts +29 -0
  133. package/types/server/machine.d.ts +1 -0
  134. package/types/server/mcp/McpApps.d.ts +50 -0
  135. package/types/server/mcp/McpDispatcher.d.ts +4 -1
  136. package/types/server/mcp/McpRouter.d.ts +4 -0
  137. package/types/server/resolver/signal.resolver.d.ts +2 -1
  138. package/types/server/routeElementComposer.d.ts +24 -4
  139. package/types/server/routeState.d.ts +4 -1
  140. package/types/server/routing/roomReplay.d.ts +24 -0
  141. package/types/server/rscWorkerHost.d.ts +5 -2
  142. package/types/server/sitemap.d.ts +2 -0
  143. package/types/server/ssrFromRscRenderer.d.ts +3 -3
  144. package/types/server/ssrTypes.d.ts +4 -1
  145. package/types/server/systemPageDocument.d.ts +2 -0
  146. package/types/server/types.d.ts +4 -1
  147. package/types/server/webRouter.d.ts +3 -1
  148. package/types/service/ipcTypes.d.ts +2 -0
  149. package/types/service/predefinedAdaptor/database.adaptor.d.ts +1 -24
  150. package/types/service/predefinedAdaptor/queue.adaptor.d.ts +10 -3
  151. package/types/service/predefinedAdaptor/queueBackoff.d.ts +4 -0
  152. package/types/service/predefinedAdaptor/solidQueue.adaptor.d.ts +3 -3
  153. package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +6 -1
  154. package/types/service/predefinedAdaptor/sql/dialect/postgres.d.ts +1 -0
  155. package/types/service/predefinedAdaptor/sql/dialect/sqlite.d.ts +1 -0
  156. package/types/service/predefinedAdaptor/sql/search/fts5.d.ts +1 -1
  157. package/types/service/predefinedAdaptor/sql/types.d.ts +9 -5
  158. package/types/service/predefinedAdaptor/sql/values.d.ts +0 -3
  159. package/types/service/serve.d.ts +3 -0
  160. package/types/signal/endpointIdempotency.d.ts +7 -0
  161. package/types/signal/internalArg.d.ts +10 -0
  162. package/types/signal/mcp/McpDocument.d.ts +8 -0
  163. package/types/signal/mcp/mcpProtocol.d.ts +17 -0
  164. package/types/signal/signalContext.d.ts +5 -3
  165. package/types/signal/signalRegistry.d.ts +4 -4
  166. package/types/signal/types.d.ts +21 -1
  167. package/types/store/agentic/StToolBuilder.d.ts +2 -0
  168. package/types/test/conformance.d.ts +7 -10
  169. package/types/ui/Agent/Chat.d.ts +5 -1
  170. package/types/ui/Agent/EmbedApproval.d.ts +1 -0
  171. package/types/ui/Agent/index.d.ts +3 -0
  172. package/types/ui/Agent/useKeyboardFrame.d.ts +2 -0
  173. package/types/ui/Agent/useScreenActions.d.ts +18 -0
  174. package/types/ui/BottomSheet.d.ts +1 -0
  175. package/types/ui/Constant/Doc.d.ts +11 -17
  176. package/types/ui/Constant/index.d.ts +7 -2
  177. package/types/ui/Constant/schemaDoc.d.ts +11 -0
  178. package/types/ui/Dialog/Modal.d.ts +6 -1
  179. package/types/ui/Dialog/index.d.ts +1 -1
  180. package/types/ui/Dialog/modalSurface.d.ts +12 -0
  181. package/types/ui/Layout/BottomTab.d.ts +11 -2
  182. package/types/ui/Layout/FrameSlotFallback.d.ts +9 -0
  183. package/types/ui/Layout/Navbar.d.ts +4 -1
  184. package/types/ui/Layout/TopInset.d.ts +1 -1
  185. package/types/ui/Layout/index.d.ts +3 -3
  186. package/types/ui/Link/Action.d.ts +5 -1
  187. package/types/ui/Link/Anchor.d.ts +5 -3
  188. package/types/ui/Link/activePath.d.ts +13 -0
  189. package/types/ui/Link/index.d.ts +1 -1
  190. package/types/ui/Modal.d.ts +6 -1
  191. package/types/ui/Model/EditModal.d.ts +6 -1
  192. package/types/ui/Model/New.d.ts +6 -1
  193. package/types/ui/Model/ViewEditModal.d.ts +6 -1
  194. package/types/ui/Model/ViewModal.d.ts +6 -1
  195. package/types/ui/Model/newFormOrigin.d.ts +7 -0
  196. package/types/ui/Portal.d.ts +3 -1
  197. package/types/ui/Reference/origin.d.ts +12 -0
  198. package/types/ui/Signal/Doc.d.ts +23 -18
  199. package/types/ui/Signal/Listener.d.ts +2 -6
  200. package/types/ui/Signal/Object.d.ts +6 -10
  201. package/types/ui/Signal/Response.d.ts +3 -6
  202. package/types/ui/Signal/RestApi.d.ts +11 -15
  203. package/types/ui/Signal/WebSocket.d.ts +11 -21
  204. package/types/ui/Signal/endpointEntries.d.ts +8 -0
  205. package/types/ui/Signal/index.d.ts +35 -12
  206. package/types/ui/Signal/signalText.d.ts +178 -0
  207. package/types/ui/System/CSR.d.ts +2 -2
  208. package/types/ui/System/Client.d.ts +4 -3
  209. package/types/ui/System/Common.d.ts +27 -6
  210. package/types/ui/System/SSR.d.ts +6 -6
  211. package/types/ui/Tooltip.d.ts +4 -2
  212. package/types/ui/index.d.ts +2 -1
  213. package/types/ui/overlayLayer.d.ts +6 -0
  214. package/types/ui/overlayPosition.d.ts +17 -0
  215. package/types/vendor/@akanjs/native/packages/cli/src/api.d.ts +14 -3
  216. package/types/vendor/@akanjs/native/packages/cli/src/commands/update.d.ts +1 -1
  217. package/types/vendor/@akanjs/native/packages/cli/src/config.d.ts +30 -5
  218. package/types/vendor/@akanjs/native/packages/cli/src/lib/compat.d.ts +8 -0
  219. package/types/vendor/@akanjs/native/packages/cli/src/lib/desktop-server.d.ts +5 -0
  220. package/types/vendor/@akanjs/native/packages/cli/src/lib/distribution.d.ts +22 -0
  221. package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
  222. package/types/vendor/@akanjs/native/packages/cli/src/lib/publish.d.ts +16 -10
  223. package/types/vendor/@akanjs/native/packages/cli/src/lib/updates.d.ts +51 -7
  224. package/types/vendor/@akanjs/native/packages/cli/src/lib/vectors.d.ts +1 -1
  225. package/types/vendor/@akanjs/native/packages/cli/src/platforms/windows-installer.d.ts +7 -0
  226. package/types/vendor/@akanjs/native/packages/cli/src/platforms/windows.d.ts +5 -0
  227. package/types/vendor/@akanjs/native/packages/core/src/kernel.d.ts +36 -0
  228. package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +2 -0
  229. package/types/vendor/@akanjs/native/packages/desktop/src/server.d.ts +11 -0
  230. package/types/vendor/@akanjs/native/plugins/external-view/src/desktop.d.ts +17 -0
  231. package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +132 -0
  232. package/types/vendor/@akanjs/native/plugins/external-view/src.d.ts +1 -0
  233. package/types/vendor/@akanjs/native/plugins/updates/src/index.d.ts +8 -0
  234. package/types/vendor/@akanjs/native/plugins/window/src/desktop.d.ts +4 -1
  235. package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +49 -0
  236. package/types/vendor/use-agentic/types.d.ts +2 -0
  237. package/types/webkit/CsrStack.d.ts +1 -1
  238. package/types/webkit/McpAppAgent.d.ts +14 -0
  239. package/types/webkit/McpAppApprovals.d.ts +8 -0
  240. package/types/webkit/McpAppBridge.d.ts +101 -0
  241. package/types/webkit/McpAppView.d.ts +21 -0
  242. package/types/webkit/index.d.ts +1 -0
  243. package/types/webkit/useLocation.d.ts +1 -1
  244. package/types/webkit/useVisualViewportFrame.d.ts +13 -0
  245. package/ui/Agent/Chat.tsx +29 -10
  246. package/ui/Agent/Composer.tsx +2 -1
  247. package/ui/Agent/EmbedApproval.tsx +17 -0
  248. package/ui/Agent/RichInput.tsx +1 -1
  249. package/ui/Agent/index.ts +2 -0
  250. package/ui/Agent/useKeyboardFrame.ts +10 -0
  251. package/ui/Agent/useScreenActions.ts +45 -0
  252. package/ui/BottomSheet.tsx +82 -53
  253. package/ui/Constant/Doc.tsx +113 -60
  254. package/ui/Constant/index.ts +2 -2
  255. package/ui/Constant/schemaDoc.ts +86 -26
  256. package/ui/Dialog/LegacyModal.tsx +53 -52
  257. package/ui/Dialog/Modal.tsx +93 -49
  258. package/ui/Dialog/modalSurface.ts +61 -0
  259. package/ui/DragAction.tsx +1 -1
  260. package/ui/DraggableList.tsx +1 -1
  261. package/ui/Dropdown.tsx +4 -6
  262. package/ui/KeyboardAvoiding.tsx +1 -1
  263. package/ui/Layout/BottomInset.tsx +20 -14
  264. package/ui/Layout/BottomTab.tsx +42 -16
  265. package/ui/Layout/FrameSlotFallback.tsx +59 -0
  266. package/ui/Layout/Navbar.tsx +37 -11
  267. package/ui/Layout/Sider.tsx +1 -1
  268. package/ui/Layout/TopInset.tsx +15 -14
  269. package/ui/Link/Action.tsx +15 -5
  270. package/ui/Link/Anchor.tsx +25 -13
  271. package/ui/Link/activePath.ts +25 -0
  272. package/ui/Link/index.tsx +1 -1
  273. package/ui/Load/Pagination.tsx +1 -1
  274. package/ui/Load/Units.tsx +1 -1
  275. package/ui/Loading/ProgressBar.tsx +1 -1
  276. package/ui/Modal.tsx +9 -0
  277. package/ui/Model/EditModal.tsx +16 -1
  278. package/ui/Model/New.tsx +25 -2
  279. package/ui/Model/NewWrapper_Client.tsx +2 -0
  280. package/ui/Model/ViewEditModal.tsx +9 -0
  281. package/ui/Model/ViewModal.tsx +16 -1
  282. package/ui/Model/newFormOrigin.ts +45 -0
  283. package/ui/Popconfirm.tsx +5 -7
  284. package/ui/Portal.tsx +4 -7
  285. package/ui/Reference/origin.ts +31 -0
  286. package/ui/ScreenNavigator.tsx +1 -1
  287. package/ui/Select.tsx +2 -7
  288. package/ui/Signal/Arg.tsx +2 -2
  289. package/ui/Signal/Doc.tsx +125 -63
  290. package/ui/Signal/Endpoint.tsx +11 -10
  291. package/ui/Signal/Listener.tsx +7 -10
  292. package/ui/Signal/Object.tsx +7 -14
  293. package/ui/Signal/Response.tsx +24 -24
  294. package/ui/Signal/RestApi.tsx +63 -52
  295. package/ui/Signal/WebSocket.tsx +65 -72
  296. package/ui/Signal/endpointEntries.ts +25 -0
  297. package/ui/Signal/index.ts +23 -6
  298. package/ui/Signal/signalText.ts +59 -0
  299. package/ui/System/CSR.tsx +34 -8
  300. package/ui/System/Client.tsx +36 -5
  301. package/ui/System/Common.tsx +76 -32
  302. package/ui/System/SSR.tsx +73 -31
  303. package/ui/Toast.tsx +1 -1
  304. package/ui/Tooltip.tsx +84 -30
  305. package/ui/index.ts +11 -1
  306. package/ui/overlayLayer.ts +25 -2
  307. package/ui/overlayPosition.ts +90 -0
  308. package/ui/recipe/inputRecipe.ts +8 -1
  309. package/ui/styles.css +152 -0
  310. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +22 -2
  311. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeKernel.kt +37 -0
  312. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeUpdateReports.kt +169 -0
  313. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeUpdates.kt +110 -38
  314. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeVectors.kt +20 -0
  315. package/vendor/@akanjs/native/native/desktop/Cargo.lock +16 -16
  316. package/vendor/@akanjs/native/native/desktop/src/external.rs +651 -0
  317. package/vendor/@akanjs/native/native/desktop/src/json.rs +23 -0
  318. package/vendor/@akanjs/native/native/desktop/src/lib.rs +228 -5
  319. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeApp.swift +2 -1
  320. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeKernel.swift +47 -1
  321. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeUpdateReports.swift +145 -0
  322. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeUpdates.swift +112 -43
  323. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeVectors.swift +18 -0
  324. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +24 -2
  325. package/vendor/@akanjs/native/packages/cli/src/api.ts +22 -6
  326. package/vendor/@akanjs/native/packages/cli/src/commands/build.ts +24 -8
  327. package/vendor/@akanjs/native/packages/cli/src/commands/update.ts +11 -9
  328. package/vendor/@akanjs/native/packages/cli/src/config.ts +35 -7
  329. package/vendor/@akanjs/native/packages/cli/src/lib/compat.ts +2 -0
  330. package/vendor/@akanjs/native/packages/cli/src/lib/configkeys.ts +6 -4
  331. package/vendor/@akanjs/native/packages/cli/src/lib/desktop-server.ts +11 -1
  332. package/vendor/@akanjs/native/packages/cli/src/lib/distribution.ts +73 -0
  333. package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +15 -3
  334. package/vendor/@akanjs/native/packages/cli/src/lib/publish.ts +70 -23
  335. package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +159 -23
  336. package/vendor/@akanjs/native/packages/cli/src/lib/vectors.ts +2 -0
  337. package/vendor/@akanjs/native/packages/cli/src/platforms/android.ts +9 -4
  338. package/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.ts +1 -1
  339. package/vendor/@akanjs/native/packages/cli/src/platforms/desktop.ts +4 -2
  340. package/vendor/@akanjs/native/packages/cli/src/platforms/ios.ts +9 -4
  341. package/vendor/@akanjs/native/packages/cli/src/platforms/windows-installer.ts +25 -11
  342. package/vendor/@akanjs/native/packages/cli/src/platforms/windows.ts +14 -3
  343. package/vendor/@akanjs/native/packages/core/src/kernel.ts +49 -0
  344. package/vendor/@akanjs/native/packages/core/vectors/updates.json +31 -0
  345. package/vendor/@akanjs/native/packages/desktop/src/main.ts +3 -0
  346. package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +2 -0
  347. package/vendor/@akanjs/native/packages/desktop/src/server.ts +70 -6
  348. package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +23 -0
  349. package/vendor/@akanjs/native/plugins/external-view/src/desktop.ts +321 -0
  350. package/vendor/@akanjs/native/plugins/external-view/src/index.ts +106 -0
  351. package/vendor/@akanjs/native/plugins/updates/android/UpdatesPlugin.kt +133 -41
  352. package/vendor/@akanjs/native/plugins/updates/ios/UpdatesPlugin.swift +101 -36
  353. package/vendor/@akanjs/native/plugins/updates/native-plugin.json +4 -2
  354. package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +15 -1
  355. package/vendor/@akanjs/native/plugins/updates/src/index.ts +7 -1
  356. package/vendor/@akanjs/native/plugins/window/native-plugin.json +4 -0
  357. package/vendor/@akanjs/native/plugins/window/src/desktop.ts +68 -1
  358. package/vendor/@akanjs/native/plugins/window/src/index.ts +47 -0
  359. package/vendor/use-agentic/ToolRunner.ts +8 -1
  360. package/vendor/use-agentic/types.ts +2 -0
  361. package/webkit/CsrRouteTable.ts +1 -0
  362. package/webkit/CsrStack.ts +9 -2
  363. package/webkit/McpAppAgent.ts +138 -0
  364. package/webkit/McpAppApprovals.ts +56 -0
  365. package/webkit/McpAppBridge.ts +291 -0
  366. package/webkit/McpAppView.ts +258 -0
  367. package/webkit/bootCsr.tsx +54 -5
  368. package/webkit/index.ts +1 -0
  369. package/webkit/useCsrValues.ts +16 -10
  370. package/webkit/useFrameRuntime.ts +10 -1
  371. package/webkit/useLocation.ts +4 -3
  372. package/webkit/useVisualViewportFrame.tsx +52 -0
  373. package/service/predefinedAdaptor/sql/driver/libsql.ts +0 -45
  374. package/types/service/predefinedAdaptor/sql/driver/libsql.d.ts +0 -20
  375. package/types/ui/Agent/useKeyboardInset.d.ts +0 -1
  376. package/types/ui/ServerPortal.d.ts +0 -15
  377. package/ui/Agent/useKeyboardInset.ts +0 -19
  378. package/ui/ServerPortal.tsx +0 -49
@@ -1,19 +1,21 @@
1
1
  "use client";
2
2
  import { useDrag } from "@use-gesture/react";
3
3
  import { cn } from "akanjs/client";
4
- import { st } from "akanjs/store";
5
- import { animated } from "akanjs/ui";
6
- import { useEscapeKey } from "akanjs/webkit";
4
+ import { useBodyScrollLock, useEscapeKey } from "akanjs/webkit";
7
5
  import { forwardRef, type ReactNode, useEffect, useImperativeHandle, useRef, useState } from "react";
6
+ import { createPortal } from "react-dom";
8
7
  import { BiX } from "react-icons/bi";
9
8
  import { config, useSpring } from "react-spring";
9
+ import { animated } from "./animated";
10
10
  import { buttonRecipe } from "./Button";
11
+ import { overlayZ, useOverlayLayerProps, useOverlayPortal } from "./overlayLayer";
11
12
 
12
13
  interface BottomSheetProps {
13
14
  className?: string;
14
15
  bodyClassName?: string;
15
16
  /** Left out, the sheet opens from its own trigger and handle. */
16
17
  open?: boolean;
18
+ /** Called once when the person dismisses the sheet: the backdrop, Escape, a drag down, or the close button. */
17
19
  onCancel?: () => void;
18
20
  trigger?: ReactNode;
19
21
  /** Whole top row of the sheet, replacing the drag handle or the close row. */
@@ -50,44 +52,51 @@ export const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
50
52
  bottomSheetRef,
51
53
  ) => {
52
54
  const ref = useRef<HTMLDivElement>(null);
53
- const pageState = st.use.pageState({ agent: false });
55
+ const shown = useRef(false);
56
+ const portal = useOverlayPortal();
57
+ const overlayLayerProps = useOverlayLayerProps();
54
58
  const [selfOpen, setSelfOpen] = useState(false);
55
59
  const isOpen = open ?? selfOpen;
56
60
 
57
61
  const [{ y, opacity }, api] = useSpring(() => ({ y: OFFSCREEN, opacity: 0 }));
58
62
 
59
- const openModal = async () => {
60
- setSelfOpen(true);
63
+ const show = async () => {
64
+ shown.current = true;
61
65
  await Promise.all(api.start({ y: 0, opacity: 1, immediate: false, config: config.default }));
62
66
  };
63
- const closeModal = async () => {
67
+ const hide = async () => {
64
68
  const height = ref.current?.clientHeight ?? OFFSCREEN;
65
69
  await Promise.all(
66
70
  api.start({ y: height, opacity: 0, immediate: false, config: { ...config.stiff, velocity: 0 } }),
67
71
  );
68
- setSelfOpen(false);
72
+ };
73
+
74
+ const dismiss = () => {
75
+ if (open === undefined) setSelfOpen(false);
69
76
  onCancel?.();
70
77
  };
71
78
 
72
79
  const bind = useDrag(({ down, movement: [, my] }) => {
73
80
  const height = ref.current?.clientHeight ?? OFFSCREEN;
74
81
  if (down) void api.start({ y: Math.max(0, my), immediate: true });
75
- else if (my > height / 3) void closeModal();
76
- else void openModal();
82
+ else if (my > height / 3) dismiss();
83
+ else void show();
77
84
  });
78
85
 
79
86
  useImperativeHandle(bottomSheetRef, () => ({
80
- open: openModal,
81
- close: closeModal,
87
+ open: () => {
88
+ setSelfOpen(true);
89
+ void show();
90
+ },
91
+ close: dismiss,
82
92
  }));
83
93
 
84
- useEscapeKey(isOpen, () => {
85
- void closeModal();
86
- });
94
+ useEscapeKey(isOpen, dismiss);
95
+ useBodyScrollLock(isOpen);
87
96
 
88
97
  useEffect(() => {
89
- if (isOpen) void openModal();
90
- else void closeModal();
98
+ if (isOpen) void show();
99
+ else if (shown.current) void hide();
91
100
  }, [isOpen]);
92
101
 
93
102
  return (
@@ -102,43 +111,63 @@ export const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
102
111
  {trigger}
103
112
  </div>
104
113
  ) : null}
105
- <animated.div
106
- style={{ opacity }}
107
- onClick={() => void closeModal()}
108
- className={cn("fixed inset-0 bg-black/50 backdrop-blur-sm", isOpen ? "z-50" : "-z-[1]")}
109
- />
110
- <animated.div
111
- ref={ref}
112
- style={{ y, paddingTop: type === "full" ? pageState.topSafeArea : 0 }}
113
- className={cn(
114
- "fixed bottom-0 left-0 z-[101] flex w-full flex-col bg-card text-card-foreground",
115
- type === "half" && "h-[90dvh] rounded-t-box border-border border-t shadow-2xl",
116
- type === "full" && "h-[100dvh]",
117
- className,
118
- )}
119
- >
120
- {header ??
121
- (type === "half" ? (
122
- <animated.div {...bind()} className="flex shrink-0 cursor-grab touch-pan-y justify-center py-3">
123
- {handle ?? <div className="h-1 w-10 rounded-full bg-foreground/15" />}
124
- </animated.div>
125
- ) : (
126
- <div className="flex shrink-0 justify-end p-2" style={{ paddingTop: pageState.topSafeArea }}>
127
- <div className="contents" onClick={() => void closeModal()}>
128
- {close ?? (
129
- <button
130
- aria-label="Close"
131
- className={buttonRecipe({ variant: "ghost", size: "icon" }, "rounded-full text-foreground/50")}
132
- type="button"
133
- >
134
- <BiX className="text-2xl" />
135
- </button>
114
+ {portal
115
+ ? createPortal(
116
+ <>
117
+ <animated.div
118
+ {...overlayLayerProps}
119
+ style={{ opacity, zIndex: overlayZ.modal, pointerEvents: isOpen ? "auto" : "none" }}
120
+ onClick={dismiss}
121
+ className="fixed inset-0 bg-black/50 backdrop-blur-sm"
122
+ />
123
+ <animated.div
124
+ {...overlayLayerProps}
125
+ ref={ref}
126
+ style={{ y, zIndex: overlayZ.modal }}
127
+ className={cn(
128
+ "fixed bottom-0 left-0 flex w-full flex-col bg-card text-card-foreground",
129
+ type === "half" && "h-[90dvh] rounded-t-box border-border border-t shadow-2xl",
130
+ type === "full" &&
131
+ "h-[100dvh] pt-[max(var(--akan-top-safe-area,0px),env(safe-area-inset-top,0px))]",
132
+ className,
136
133
  )}
137
- </div>
138
- </div>
139
- ))}
140
- <div className={cn("scrollbar-thin min-h-0 flex-1 overflow-y-auto px-4 pb-4", bodyClassName)}>{children}</div>
141
- </animated.div>
134
+ >
135
+ {header ??
136
+ (type === "half" ? (
137
+ <animated.div {...bind()} className="flex shrink-0 cursor-grab touch-pan-y justify-center py-3">
138
+ {handle ?? <div className="h-1 w-10 rounded-full bg-foreground/15" />}
139
+ </animated.div>
140
+ ) : (
141
+ <div className="flex shrink-0 justify-end p-2">
142
+ <div className="contents" onClick={dismiss}>
143
+ {close ?? (
144
+ <button
145
+ aria-label="Close"
146
+ className={buttonRecipe(
147
+ { variant: "ghost", size: "icon" },
148
+ "rounded-full text-foreground/50",
149
+ )}
150
+ type="button"
151
+ >
152
+ <BiX className="text-2xl" />
153
+ </button>
154
+ )}
155
+ </div>
156
+ </div>
157
+ ))}
158
+ <div
159
+ className={cn(
160
+ "scrollbar-thin min-h-0 flex-1 overflow-y-auto px-4 pb-[calc(1rem+max(var(--akan-bottom-safe-area,0px),env(safe-area-inset-bottom,0px)))]",
161
+ bodyClassName,
162
+ )}
163
+ >
164
+ {children}
165
+ </div>
166
+ </animated.div>
167
+ </>,
168
+ portal,
169
+ )
170
+ : null}
142
171
  </>
143
172
  );
144
173
  },
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { usePage } from "akanjs/client";
4
4
  import { capitalize } from "akanjs/common";
5
- import { useMemo, useState } from "react";
5
+ import { Fragment, useMemo, useState } from "react";
6
6
  import { AiOutlineInfoCircle, AiOutlineSearch } from "react-icons/ai";
7
7
  import { BiNetworkChart, BiTable } from "react-icons/bi";
8
8
 
@@ -24,12 +24,16 @@ import {
24
24
  SummaryGrid,
25
25
  Toolbar,
26
26
  } from "../Reference";
27
+ import { originText, ownerOf } from "../Reference/origin";
27
28
  import { Graph } from "./Graph";
28
29
  import {
30
+ type ConstantSchemaOptions,
29
31
  type DatabaseModelVariant,
30
32
  type DatabaseSchema,
31
33
  databaseModelVariants,
34
+ type EnumSchema,
32
35
  type FieldSchema,
36
+ getConstantOwnerOrder,
33
37
  getConstantSchemaDoc,
34
38
  getDefaultVariant,
35
39
  getVariantTitle,
@@ -37,10 +41,6 @@ import {
37
41
  } from "./schemaDoc";
38
42
  import type { SchemaGraphEdge, SchemaGraphNode, SchemaNodeKind } from "./schemaGraph";
39
43
 
40
- export default function Doc() {
41
- return <div />;
42
- }
43
-
44
44
  const docText = {
45
45
  pageTitle: { en: "Constant Schema Docs", ko: "Constant 스키마 문서" },
46
46
  printTitle: { en: "Constant Schema Definition", ko: "Constant 스키마 정의서" },
@@ -77,6 +77,7 @@ const docText = {
77
77
  selectedModel: { en: "Selected Model", ko: "선택한 모델" },
78
78
  external: { en: "External", ko: "외부" },
79
79
  selectNode: { en: "Select a node in the diagram.", ko: "다이어그램에서 노드를 선택하세요." },
80
+ unknownOrigin: { en: "Unknown library", ko: "출처 미상" },
80
81
  } as const;
81
82
 
82
83
  const fieldCountText = (count: number) => ({ en: `${count} fields`, ko: `필드 ${count}개` });
@@ -97,16 +98,17 @@ const headsOf = (l: ReturnType<typeof usePage>["l"], keys: (keyof typeof docText
97
98
 
98
99
  const printTable = "print:overflow-visible print:rounded-none print:border-0";
99
100
 
100
- interface ZoneProps {
101
- models?: string[];
102
- scalars?: string[];
103
- enums?: string[];
101
+ export interface ZoneProps extends ConstantSchemaOptions {
104
102
  openAll?: boolean;
103
+ groupBy?: "lib";
105
104
  }
106
105
 
107
- const Zone = ({ models, scalars, enums, openAll }: ZoneProps) => {
106
+ export const Zone = ({ models, scalars, enums, include, exclude, libs, openAll, groupBy }: ZoneProps) => {
108
107
  const { l } = usePage();
109
- const schemaDoc = useMemo(() => getConstantSchemaDoc({ models, scalars, enums }), [models, scalars, enums]);
108
+ const schemaDoc = useMemo(
109
+ () => getConstantSchemaDoc({ models, scalars, enums, include, exclude, libs }),
110
+ [models, scalars, enums, include, exclude, libs],
111
+ );
110
112
  const viewItems = [
111
113
  { key: "table", label: l.trans(docText.table), icon: <BiTable /> },
112
114
  { key: "diagram", label: l.trans(docText.diagram), icon: <BiNetworkChart /> },
@@ -128,6 +130,19 @@ const Zone = ({ models, scalars, enums, openAll }: ZoneProps) => {
128
130
  ),
129
131
  [schemaDoc.enums, query],
130
132
  );
133
+ const groups = useMemo(() => {
134
+ const owners = groupBy === "lib" ? [...getConstantOwnerOrder(), ""] : [null];
135
+ const inGroup = (owner: string | null) => (entry: { origin: string[] }) =>
136
+ owner === null || (ownerOf(entry.origin) ?? "") === owner;
137
+ return owners
138
+ .map((owner) => ({
139
+ owner,
140
+ databases: filteredDatabases.filter(inGroup(owner)),
141
+ scalars: filteredScalars.filter(inGroup(owner)),
142
+ enums: filteredEnums.filter(inGroup(owner)),
143
+ }))
144
+ .filter((group) => group.owner === null || group.databases.length + group.scalars.length + group.enums.length);
145
+ }, [groupBy, filteredDatabases, filteredScalars, filteredEnums]);
131
146
  return (
132
147
  <div className="flex break-after-page flex-col gap-6">
133
148
  <div className="flex flex-col gap-1">
@@ -152,45 +167,81 @@ const Zone = ({ models, scalars, enums, openAll }: ZoneProps) => {
152
167
  />
153
168
  <Segmented className="ml-auto" items={viewItems} onChange={setViewMode} value={viewMode} />
154
169
  </Toolbar>
155
- {viewMode === "diagram" ? (
156
- <Diagram databases={filteredDatabases} scalars={filteredScalars} />
157
- ) : (
158
- <div className="flex flex-col gap-6">
159
- <Section title={l.trans(docText.databaseModels)}>
160
- {filteredDatabases.length ? (
161
- <div className="flex flex-col gap-2">
162
- {filteredDatabases.map((database) => (
163
- <Model key={database.refName} database={database} openAll={openAll} />
164
- ))}
165
- </div>
166
- ) : (
167
- <div className={docUi.emptyPanel}>{l.trans(docText.noDatabaseMatch)}</div>
168
- )}
169
- </Section>
170
- {filteredScalars.length ? (
171
- <Section title={l.trans(docText.scalarModels)}>
172
- <div className="flex flex-col gap-2">
173
- {filteredScalars.map((scalar) => (
174
- <Scalar key={scalar.refName} scalar={scalar} openAll={openAll} />
175
- ))}
176
- </div>
177
- </Section>
178
- ) : null}
179
- {filteredEnums.length ? (
180
- <Section title={l.trans(docText.enums)}>
181
- <EnumList enums={filteredEnums} />
182
- </Section>
183
- ) : null}
184
- </div>
185
- )}
170
+ {groups.map(({ owner, databases, scalars: groupScalars, enums: groupEnums }) => {
171
+ const body =
172
+ viewMode === "diagram" ? (
173
+ <Diagram databases={databases} scalars={groupScalars} />
174
+ ) : (
175
+ <SchemaTables
176
+ databases={databases}
177
+ scalars={groupScalars}
178
+ enums={groupEnums}
179
+ openAll={openAll}
180
+ showEmpty={owner === null}
181
+ />
182
+ );
183
+ if (owner === null) return <Fragment key="all">{body}</Fragment>;
184
+ return (
185
+ <section className="flex flex-col gap-4" key={owner}>
186
+ <h2 className="border-border border-b pb-2 font-bold font-mono text-2xl">
187
+ {owner || l.trans(docText.unknownOrigin)}
188
+ </h2>
189
+ {body}
190
+ </section>
191
+ );
192
+ })}
186
193
  </div>
187
194
  );
188
195
  };
189
- Doc.Zone = Zone;
190
196
 
191
- const Print = ({ models, scalars, enums }: ZoneProps) => {
197
+ interface SchemaTablesProps {
198
+ databases: DatabaseSchema[];
199
+ scalars: ScalarSchema[];
200
+ enums: EnumSchema[];
201
+ openAll?: boolean;
202
+ showEmpty: boolean;
203
+ }
204
+ const SchemaTables = ({ databases, scalars, enums, openAll, showEmpty }: SchemaTablesProps) => {
192
205
  const { l } = usePage();
193
- const schemaDoc = useMemo(() => getConstantSchemaDoc({ models, scalars, enums }), [models, scalars, enums]);
206
+ return (
207
+ <div className="flex flex-col gap-6">
208
+ {databases.length || showEmpty ? (
209
+ <Section title={l.trans(docText.databaseModels)}>
210
+ {databases.length ? (
211
+ <div className="flex flex-col gap-2">
212
+ {databases.map((database) => (
213
+ <Model key={database.refName} database={database} openAll={openAll} />
214
+ ))}
215
+ </div>
216
+ ) : (
217
+ <div className={docUi.emptyPanel}>{l.trans(docText.noDatabaseMatch)}</div>
218
+ )}
219
+ </Section>
220
+ ) : null}
221
+ {scalars.length ? (
222
+ <Section title={l.trans(docText.scalarModels)}>
223
+ <div className="flex flex-col gap-2">
224
+ {scalars.map((scalar) => (
225
+ <Scalar key={scalar.refName} scalar={scalar} openAll={openAll} />
226
+ ))}
227
+ </div>
228
+ </Section>
229
+ ) : null}
230
+ {enums.length ? (
231
+ <Section title={l.trans(docText.enums)}>
232
+ <EnumList enums={enums} />
233
+ </Section>
234
+ ) : null}
235
+ </div>
236
+ );
237
+ };
238
+
239
+ export const Print = ({ models, scalars, enums, include, exclude, libs }: ZoneProps) => {
240
+ const { l } = usePage();
241
+ const schemaDoc = useMemo(
242
+ () => getConstantSchemaDoc({ models, scalars, enums, include, exclude, libs }),
243
+ [models, scalars, enums, include, exclude, libs],
244
+ );
194
245
  return (
195
246
  <div className="flex flex-col gap-10 bg-background text-foreground print:bg-white print:text-black">
196
247
  <div className="break-after-page">
@@ -223,17 +274,17 @@ const Print = ({ models, scalars, enums }: ZoneProps) => {
223
274
  </div>
224
275
  );
225
276
  };
226
- Doc.Print = Print;
227
-
228
- interface ModelProps {
277
+ export interface ModelProps {
229
278
  refName?: string;
230
279
  database?: DatabaseSchema;
231
280
  openAll?: boolean;
232
281
  }
233
282
 
234
- const Model = ({ refName, database: databaseProp, openAll }: ModelProps) => {
283
+ export const Model = ({ refName, database: databaseProp, openAll }: ModelProps) => {
235
284
  const database = useMemo(
236
- () => databaseProp ?? getConstantSchemaDoc({ models: refName ? [refName] : [] }).databases.at(0),
285
+ () =>
286
+ databaseProp ??
287
+ getConstantSchemaDoc({ models: refName ? [refName] : [], scalars: [], enums: [] }).databases.at(0),
237
288
  [databaseProp, refName],
238
289
  );
239
290
  const [variant, setVariant] = useState<DatabaseModelVariant>("full");
@@ -248,6 +299,9 @@ const Model = ({ refName, database: databaseProp, openAll }: ModelProps) => {
248
299
  <div className="flex flex-wrap items-center gap-2">
249
300
  <span className="font-bold text-lg">{database.modelName}</span>
250
301
  <span className={docPill("info", "font-mono")}>{database.refName}</span>
302
+ {database.origin.length ? (
303
+ <span className={docPill("muted", "font-mono")}>{l.trans(originText(database.origin))}</span>
304
+ ) : null}
251
305
  </div>
252
306
  <div className="text-foreground/55 text-sm">{l._(`${database.refName}.modelDesc`)}</div>
253
307
  </div>
@@ -258,17 +312,16 @@ const Model = ({ refName, database: databaseProp, openAll }: ModelProps) => {
258
312
  </Collapse>
259
313
  );
260
314
  };
261
- Doc.Model = Model;
262
-
263
- interface ScalarProps {
315
+ export interface ScalarProps {
264
316
  refName?: string;
265
317
  scalar?: ScalarSchema;
266
318
  openAll?: boolean;
267
319
  }
268
320
 
269
- const Scalar = ({ refName, scalar: scalarProp, openAll }: ScalarProps) => {
321
+ export const Scalar = ({ refName, scalar: scalarProp, openAll }: ScalarProps) => {
270
322
  const scalar = useMemo(
271
- () => scalarProp ?? getConstantSchemaDoc({ scalars: refName ? [refName] : [] }).scalars.at(0),
323
+ () =>
324
+ scalarProp ?? getConstantSchemaDoc({ models: [], scalars: refName ? [refName] : [], enums: [] }).scalars.at(0),
272
325
  [scalarProp, refName],
273
326
  );
274
327
  const { l } = usePage();
@@ -281,6 +334,9 @@ const Scalar = ({ refName, scalar: scalarProp, openAll }: ScalarProps) => {
281
334
  <div className="flex flex-wrap items-center gap-2">
282
335
  <span className="font-bold text-lg">{scalar.modelName}</span>
283
336
  <span className={docPill("muted", "font-mono")}>{scalar.refName}</span>
337
+ {scalar.origin.length ? (
338
+ <span className={docPill("muted", "font-mono")}>{l.trans(originText(scalar.origin))}</span>
339
+ ) : null}
284
340
  </div>
285
341
  <div className="text-foreground/55 text-sm">{l._(`${scalar.refName}.modelDesc`)}</div>
286
342
  </div>
@@ -290,13 +346,11 @@ const Scalar = ({ refName, scalar: scalarProp, openAll }: ScalarProps) => {
290
346
  </Collapse>
291
347
  );
292
348
  };
293
- Doc.Scalar = Scalar;
294
-
295
- interface EnumProps {
349
+ export interface EnumProps {
296
350
  enums?: ReturnType<typeof getConstantSchemaDoc>["enums"];
297
351
  }
298
352
 
299
- const EnumList = ({ enums = getConstantSchemaDoc().enums }: EnumProps) => {
353
+ export const EnumList = ({ enums = getConstantSchemaDoc().enums }: EnumProps) => {
300
354
  const { l } = usePage();
301
355
  return (
302
356
  <DocTable head={headsOf(l, ["enum", "type", "values", "usedBy"])}>
@@ -343,7 +397,6 @@ const EnumList = ({ enums = getConstantSchemaDoc().enums }: EnumProps) => {
343
397
  </DocTable>
344
398
  );
345
399
  };
346
- Doc.Enum = EnumList;
347
400
 
348
401
  const ModelVariantTable = ({ variant }: { variant: ReturnType<typeof getDefaultVariant> }) => {
349
402
  const { l } = usePage();
@@ -1,7 +1,7 @@
1
- import Doc from "./Doc";
1
+ import { EnumList, Model, Print, Scalar, Zone } from "./Doc";
2
2
  import { Graph } from "./Graph";
3
3
 
4
4
  export * from "./schemaDoc";
5
5
  export * from "./schemaGraph";
6
6
 
7
- export const Constant = { Doc, Graph };
7
+ export const Constant = { Doc: { Zone, Print, Model, Scalar, Enum: EnumList }, Graph };
@@ -11,17 +11,26 @@ import {
11
11
  type ConstantCls,
12
12
  type ConstantField,
13
13
  type ConstantModel,
14
+ type ConstantOriginKind,
14
15
  ConstantRegistry,
15
16
  type TextFieldRole,
16
17
  } from "akanjs/constant";
18
+ import { ownerOf, ownerOrderOf } from "../Reference/origin";
17
19
 
18
20
  export const databaseModelVariants = ["input", "object", "full", "light", "insight"] as const;
19
21
  export type DatabaseModelVariant = (typeof databaseModelVariants)[number];
20
22
 
23
+ /**
24
+ * `undefined` is "every registered one" and `[]` is "none". Once any option narrows the scope, scalars default to
25
+ * the ones the shown models embed and enums to the ones the shown models and scalars use.
26
+ */
21
27
  export interface ConstantSchemaOptions {
22
28
  models?: string[];
23
29
  scalars?: string[];
24
30
  enums?: string[];
31
+ include?: string[];
32
+ exclude?: string[];
33
+ libs?: string[];
25
34
  }
26
35
 
27
36
  export interface ConstantSchemaDoc {
@@ -34,6 +43,7 @@ export interface ConstantSchemaDoc {
34
43
  export interface DatabaseSchema {
35
44
  kind: "database";
36
45
  refName: string;
46
+ origin: string[];
37
47
  modelName: string;
38
48
  variants: Record<DatabaseModelVariant, ModelVariantSchema>;
39
49
  }
@@ -41,6 +51,7 @@ export interface DatabaseSchema {
41
51
  export interface ScalarSchema {
42
52
  kind: "scalar";
43
53
  refName: string;
54
+ origin: string[];
44
55
  modelName: string;
45
56
  modelRef: ConstantCls;
46
57
  fields: FieldSchema[];
@@ -57,6 +68,7 @@ export interface ModelVariantSchema {
57
68
  export interface EnumSchema {
58
69
  key: string;
59
70
  refName: string;
71
+ origin: string[];
60
72
  typeName: string;
61
73
  values: (string | number)[];
62
74
  enumRef: EnumInstance;
@@ -105,33 +117,80 @@ export interface FieldSchema {
105
117
  }
106
118
 
107
119
  export const getConstantSchemaDoc = (options: ConstantSchemaOptions = {}): ConstantSchemaDoc => {
108
- const databases = getSelectedEntries(ConstantRegistry.database, options.models).map(([refName, model]) =>
109
- buildDatabaseSchema(refName, model),
110
- );
111
- const scalars = getSelectedEntries(ConstantRegistry.scalar, options.scalars).map(([refName, scalar]) => {
112
- const modelRef = scalar.model;
113
- return {
114
- kind: "scalar" as const,
115
- refName,
116
- modelName: getModelName(modelRef, refName),
117
- modelRef,
118
- fields: getFields(modelRef, "scalar"),
119
- };
120
- });
121
- const selectedEnums = getSelectedEntries(ConstantRegistry.enum, options.enums);
120
+ const { models, scalars: scalarKeys, enums: enumKeys, include, exclude, libs } = options;
121
+ const isScoped = [models, scalarKeys, enumKeys, include, exclude, libs].some((option) => option !== undefined);
122
+ const keeps = (kind: ConstantOriginKind) => (key: string) =>
123
+ !exclude?.includes(key) && (!libs || libs.includes(ownerOf(ConstantRegistry.getOrigin(kind, key)) ?? ""));
124
+ const isRoot = (key: string) => keeps("database")(key) && (!include || include.includes(key));
125
+ const databases = selectKeys(ConstantRegistry.database, models)
126
+ .filter(isRoot)
127
+ .map((refName) => buildDatabaseSchema(refName, ConstantRegistry.getDatabase(refName)));
128
+ const scalars = (
129
+ scalarKeys !== undefined
130
+ ? selectKeys(ConstantRegistry.scalar, scalarKeys).filter(keeps("scalar"))
131
+ : isScoped
132
+ ? collectEmbeddedScalars(
133
+ databases,
134
+ include ? selectKeys(ConstantRegistry.scalar, include).filter(keeps("scalar")) : [],
135
+ keeps("scalar"),
136
+ )
137
+ : selectKeys(ConstantRegistry.scalar)
138
+ ).map(buildScalarSchema);
122
139
  const enumUsages = collectEnumUsages(databases, scalars);
123
- const enums = selectedEnums.map(([key, enumRef]) => ({
140
+ const enums = selectKeys(ConstantRegistry.enum, enumKeys)
141
+ .filter(keeps("enum"))
142
+ .map((key) => buildEnumSchema(key, enumUsages))
143
+ .filter((enumSchema) => enumKeys !== undefined || !isScoped || enumSchema.usedBy.length);
144
+ const relations = collectRelations(databases, scalars);
145
+ return { databases, scalars, enums, relations };
146
+ };
147
+
148
+ const buildScalarSchema = (refName: string): ScalarSchema => {
149
+ const modelRef = ConstantRegistry.getScalar(refName).model;
150
+ return {
151
+ kind: "scalar",
152
+ refName,
153
+ origin: ConstantRegistry.getOrigin("scalar", refName),
154
+ modelName: getModelName(modelRef, refName),
155
+ modelRef,
156
+ fields: getFields(modelRef, "scalar"),
157
+ };
158
+ };
159
+
160
+ const buildEnumSchema = (key: string, enumUsages: Map<EnumInstance, EnumUsage[]>): EnumSchema => {
161
+ const enumRef = ConstantRegistry.enum.get(key) as EnumInstance;
162
+ return {
124
163
  key,
125
164
  refName: enumRef.refName,
165
+ origin: ConstantRegistry.getOrigin("enum", key),
126
166
  typeName: PrimitiveRegistry.getName(enumRef.type as typeof PrimitiveScalar),
127
167
  values: [...enumRef.values] as (string | number)[],
128
168
  enumRef,
129
169
  usedBy: enumUsages.get(enumRef) ?? [],
130
- }));
131
- const relations = collectRelations(databases, scalars);
132
- return { databases, scalars, enums, relations };
170
+ };
171
+ };
172
+
173
+ const collectEmbeddedScalars = (
174
+ databases: DatabaseSchema[],
175
+ rootScalars: string[],
176
+ isKept: (key: string) => boolean,
177
+ ) => {
178
+ const found = new Set(rootScalars);
179
+ const visit = (fields: FieldSchema[]) => {
180
+ for (const field of fields) {
181
+ const refName = field.typeRefName;
182
+ if (!refName || found.has(refName) || !isKept(refName) || !ConstantRegistry.scalar.has(refName)) continue;
183
+ found.add(refName);
184
+ visit(getFields(ConstantRegistry.getScalar(refName).model, "scalar"));
185
+ }
186
+ };
187
+ for (const database of databases) for (const variant of Object.values(database.variants)) visit(variant.fields);
188
+ for (const refName of rootScalars) visit(getFields(ConstantRegistry.getScalar(refName).model, "scalar"));
189
+ return [...found].sort((a, b) => a.localeCompare(b));
133
190
  };
134
191
 
192
+ export const getConstantOwnerOrder = () => ownerOrderOf([...ConstantRegistry.origin.values()]);
193
+
135
194
  export const getDefaultVariant = (database: DatabaseSchema): ModelVariantSchema => database.variants.full;
136
195
 
137
196
  export const getVariantTitle = (variant: DatabaseModelVariant | "scalar") => {
@@ -155,7 +214,13 @@ const buildDatabaseSchema = (refName: string, model: ConstantModel): DatabaseSch
155
214
  ];
156
215
  }),
157
216
  ) as Record<DatabaseModelVariant, ModelVariantSchema>;
158
- return { kind: "database", refName, modelName: ConstantRegistry.getModelName(model.full), variants };
217
+ return {
218
+ kind: "database",
219
+ refName,
220
+ origin: ConstantRegistry.getOrigin("database", refName),
221
+ modelName: ConstantRegistry.getModelName(model.full),
222
+ variants,
223
+ };
159
224
  };
160
225
 
161
226
  const getFields = (modelRef: ConstantCls, variant: DatabaseModelVariant | "scalar"): FieldSchema[] =>
@@ -265,13 +330,8 @@ const getConstraints = (props: ReturnType<ConstantField["getProps"]>) =>
265
330
  props.accumulate ? "accumulate" : null,
266
331
  ].filter((constraint): constraint is string => !!constraint);
267
332
 
268
- const getSelectedEntries = <Value>(map: Map<string, Value>, selected?: string[]): [string, Value][] => {
269
- if (!selected?.length) return [...map.entries()].sort(([a], [b]) => a.localeCompare(b));
270
- return selected.flatMap((key) => {
271
- const value = map.get(key);
272
- return value ? ([[key, value]] as [string, Value][]) : [];
273
- });
274
- };
333
+ const selectKeys = (map: Map<string, unknown>, selected?: string[]) =>
334
+ selected ? selected.filter((key) => map.has(key)) : [...map.keys()].sort((a, b) => a.localeCompare(b));
275
335
 
276
336
  const collectEnumUsages = (databases: DatabaseSchema[], scalars: ScalarSchema[]) => {
277
337
  const usages = new Map<EnumInstance, EnumUsage[]>();