@medyll/idae-machine 0.129.0 → 0.136.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (405) hide show
  1. package/README.md +462 -300
  2. package/cli.cjs +22 -0
  3. package/dist/__fixtures__/demoModel.d.ts +79 -0
  4. package/dist/__fixtures__/demoModel.js +146 -0
  5. package/dist/ai/frame/AiChatSession.svelte +152 -0
  6. package/dist/ai/frame/AiChatSession.svelte.d.ts +7 -0
  7. package/dist/ai/frame/index.d.ts +1 -0
  8. package/dist/ai/frame/index.js +2 -0
  9. package/dist/ai/index.d.ts +9 -0
  10. package/dist/ai/index.js +12 -0
  11. package/dist/ai/schema/ai-catalogs.d.ts +2 -0
  12. package/dist/ai/schema/ai-catalogs.js +86 -0
  13. package/dist/ai/schema/ai-chat-session.d.ts +2 -0
  14. package/dist/ai/schema/ai-chat-session.js +35 -0
  15. package/dist/ai/schema/ai-companion.d.ts +2 -0
  16. package/dist/ai/schema/ai-companion.js +25 -0
  17. package/dist/ai/schema/ai-message.d.ts +2 -0
  18. package/dist/ai/schema/ai-message.js +20 -0
  19. package/dist/ai/schema/ai-tool-call.d.ts +2 -0
  20. package/dist/ai/schema/ai-tool-call.js +18 -0
  21. package/dist/ai/schema/ai-user-prompt.d.ts +2 -0
  22. package/dist/ai/schema/ai-user-prompt.js +17 -0
  23. package/dist/ai/schema/tag.d.ts +2 -0
  24. package/dist/ai/schema/tag.js +14 -0
  25. package/dist/ai/streamIntoRecord.d.ts +31 -0
  26. package/dist/ai/streamIntoRecord.js +79 -0
  27. package/dist/config.d.ts +17 -0
  28. package/dist/config.js +19 -0
  29. package/dist/data-ui/controls/AlphabetFilter.svelte +114 -0
  30. package/dist/data-ui/controls/AlphabetFilter.svelte.d.ts +10 -0
  31. package/dist/data-ui/controls/ButtonAction.svelte +151 -0
  32. package/dist/data-ui/controls/ButtonAction.svelte.d.ts +18 -0
  33. package/dist/data-ui/controls/DataFind.svelte +174 -0
  34. package/dist/data-ui/controls/DataFind.svelte.d.ts +10 -0
  35. package/dist/data-ui/controls/DataGroup.svelte +150 -0
  36. package/dist/data-ui/controls/DataGroup.svelte.d.ts +7 -0
  37. package/dist/data-ui/controls/DataSort.svelte +78 -0
  38. package/dist/data-ui/controls/DataSort.svelte.d.ts +9 -0
  39. package/dist/data-ui/controls/DataToolbar.svelte +67 -0
  40. package/dist/data-ui/controls/DataToolbar.svelte.d.ts +11 -0
  41. package/dist/data-ui/controls/Find.svelte +38 -0
  42. package/dist/data-ui/controls/Find.svelte.d.ts +9 -0
  43. package/dist/data-ui/controls/FkFilter.svelte +94 -0
  44. package/dist/data-ui/controls/FkFilter.svelte.d.ts +11 -0
  45. package/dist/data-ui/controls/Group.svelte +36 -0
  46. package/dist/data-ui/controls/Group.svelte.d.ts +8 -0
  47. package/dist/data-ui/controls/ListMode.svelte +79 -0
  48. package/dist/data-ui/controls/ListMode.svelte.d.ts +10 -0
  49. package/dist/data-ui/controls/Sort.svelte +100 -0
  50. package/dist/data-ui/controls/Sort.svelte.d.ts +8 -0
  51. package/dist/data-ui/data/DataCount.svelte +67 -0
  52. package/dist/data-ui/data/DataCount.svelte.d.ts +36 -0
  53. package/dist/data-ui/data/DataFk.svelte +54 -0
  54. package/dist/data-ui/data/DataFk.svelte.d.ts +11 -0
  55. package/dist/data-ui/data/DataForm.svelte +191 -0
  56. package/dist/data-ui/data/DataForm.svelte.d.ts +15 -0
  57. package/dist/data-ui/data/DataList.svelte +645 -0
  58. package/dist/data-ui/data/DataList.svelte.d.ts +75 -0
  59. package/dist/data-ui/data/DataListFk.svelte +111 -0
  60. package/dist/data-ui/data/DataListFk.svelte.d.ts +13 -0
  61. package/dist/data-ui/data/DataListRfk.svelte +111 -0
  62. package/dist/data-ui/data/DataListRfk.svelte.d.ts +13 -0
  63. package/dist/data-ui/data/DataRecord.svelte +167 -0
  64. package/dist/data-ui/data/DataRecord.svelte.d.ts +22 -0
  65. package/dist/data-ui/data/DataRfk.svelte +73 -0
  66. package/dist/data-ui/data/DataRfk.svelte.d.ts +15 -0
  67. package/dist/data-ui/data/index.d.ts +7 -0
  68. package/dist/data-ui/data/index.js +8 -0
  69. package/dist/data-ui/field/DataField.svelte +343 -0
  70. package/dist/data-ui/field/DataField.svelte.d.ts +33 -0
  71. package/dist/data-ui/field/DataFieldEdit.svelte +103 -0
  72. package/dist/data-ui/field/DataFieldEdit.svelte.d.ts +14 -0
  73. package/dist/data-ui/field/index.d.ts +2 -0
  74. package/dist/data-ui/field/index.js +3 -0
  75. package/dist/data-ui/field/snippets/FieldAiPrompt.svelte +145 -0
  76. package/dist/data-ui/field/snippets/FieldAiPrompt.svelte.d.ts +14 -0
  77. package/dist/data-ui/field/snippets/FieldBoolean.svelte +43 -0
  78. package/dist/data-ui/field/snippets/FieldBoolean.svelte.d.ts +12 -0
  79. package/dist/data-ui/field/snippets/FieldColor.svelte +48 -0
  80. package/dist/data-ui/field/snippets/FieldColor.svelte.d.ts +10 -0
  81. package/dist/data-ui/field/snippets/FieldCurrency.svelte +105 -0
  82. package/dist/data-ui/field/snippets/FieldCurrency.svelte.d.ts +15 -0
  83. package/dist/data-ui/field/snippets/FieldEmail.svelte +77 -0
  84. package/dist/data-ui/field/snippets/FieldEmail.svelte.d.ts +14 -0
  85. package/dist/data-ui/field/snippets/FieldIcon.svelte +73 -0
  86. package/dist/data-ui/field/snippets/FieldIcon.svelte.d.ts +11 -0
  87. package/dist/data-ui/field/snippets/FieldSelect.svelte +71 -0
  88. package/dist/data-ui/field/snippets/FieldSelect.svelte.d.ts +15 -0
  89. package/dist/data-ui/field/snippets/FieldText.svelte +52 -0
  90. package/dist/data-ui/field/snippets/FieldText.svelte.d.ts +13 -0
  91. package/dist/data-ui/field/snippets/FieldTextarea.svelte +50 -0
  92. package/dist/data-ui/field/snippets/FieldTextarea.svelte.d.ts +13 -0
  93. package/dist/data-ui/field/snippets/index.d.ts +9 -0
  94. package/dist/data-ui/field/snippets/index.js +10 -0
  95. package/dist/data-ui/fragments/ContextMenu.svelte +109 -0
  96. package/dist/data-ui/fragments/ContextMenu.svelte.d.ts +4 -0
  97. package/dist/data-ui/fragments/ContextMenuContent.svelte +275 -0
  98. package/dist/data-ui/fragments/ContextMenuContent.svelte.d.ts +8 -0
  99. package/dist/data-ui/fragments/Frame.svelte +43 -0
  100. package/dist/data-ui/fragments/Frame.svelte.d.ts +10 -0
  101. package/dist/data-ui/fragments/InfoLine.svelte +123 -0
  102. package/dist/data-ui/fragments/InfoLine.svelte.d.ts +12 -0
  103. package/dist/data-ui/fragments/Selector.svelte +56 -0
  104. package/dist/data-ui/fragments/Selector.svelte.d.ts +10 -0
  105. package/dist/{fragments → data-ui/fragments}/Skeleton.svelte +3 -3
  106. package/dist/data-ui/fragments/Tile.svelte +126 -0
  107. package/dist/data-ui/fragments/Tile.svelte.d.ts +14 -0
  108. package/dist/data-ui/fragments/contextMenu.svelte.d.ts +22 -0
  109. package/dist/data-ui/fragments/contextMenu.svelte.js +31 -0
  110. package/dist/data-ui/fragments/dialog/Dialog.svelte +185 -0
  111. package/dist/data-ui/fragments/dialog/Dialog.svelte.d.ts +29 -0
  112. package/dist/data-ui/fragments/dialog/dialog.svelte.d.ts +27 -0
  113. package/dist/data-ui/fragments/dialog/dialog.svelte.js +41 -0
  114. package/dist/data-ui/fragments/index.d.ts +11 -0
  115. package/dist/data-ui/fragments/index.js +11 -0
  116. package/dist/data-ui/utils/__tests__/HostProbe.svelte +18 -0
  117. package/dist/data-ui/utils/__tests__/HostProbe.svelte.d.ts +8 -0
  118. package/dist/data-ui/utils/data-utils.d.ts +29 -0
  119. package/dist/data-ui/utils/data-utils.js +83 -0
  120. package/dist/data-ui/utils/dataRelationUtils.d.ts +37 -0
  121. package/dist/data-ui/utils/dataRelationUtils.js +125 -0
  122. package/dist/data-ui/utils/diagramUtils.d.ts +6 -0
  123. package/dist/data-ui/utils/diagramUtils.js +131 -0
  124. package/dist/data-ui/utils/draggable.d.ts +15 -0
  125. package/dist/data-ui/utils/draggable.js +61 -0
  126. package/dist/data-ui/utils/menuPrefs.d.ts +80 -0
  127. package/dist/data-ui/utils/menuPrefs.js +119 -0
  128. package/dist/data-ui/utils/useMachinePrefs.svelte.d.ts +38 -0
  129. package/dist/data-ui/utils/useMachinePrefs.svelte.js +117 -0
  130. package/dist/data-ui/utils/useMenuTree.svelte.d.ts +26 -0
  131. package/dist/data-ui/utils/useMenuTree.svelte.js +68 -0
  132. package/dist/data-ui/utils/useRecordData.svelte.d.ts +22 -0
  133. package/dist/data-ui/utils/useRecordData.svelte.js +50 -0
  134. package/dist/data-ui/utils/useViewFields.svelte.d.ts +22 -0
  135. package/dist/data-ui/utils/useViewFields.svelte.js +59 -0
  136. package/dist/demo/.gitkeep +0 -0
  137. package/dist/demo/demo-status.json +9 -0
  138. package/dist/idae/boot.d.ts +28 -0
  139. package/dist/idae/boot.js +43 -0
  140. package/dist/idae/bridge/register.d.ts +4 -0
  141. package/dist/idae/bridge/register.js +15 -0
  142. package/dist/idae/capabilities/Capabilities.d.ts +10 -0
  143. package/dist/idae/capabilities/Capabilities.js +34 -0
  144. package/dist/idae/codefield/CodeFieldConvention.d.ts +3 -0
  145. package/dist/idae/codefield/CodeFieldConvention.js +25 -0
  146. package/dist/idae/fieldcatalog/defaultFieldTypesDef.d.ts +2 -0
  147. package/dist/idae/fieldcatalog/defaultFieldTypesDef.js +104 -0
  148. package/dist/idae/frames/FrameCatalog.d.ts +31 -0
  149. package/dist/idae/frames/FrameCatalog.js +31 -0
  150. package/dist/idae/index.d.ts +14 -0
  151. package/dist/idae/index.js +13 -0
  152. package/dist/idae/menu/IdaeMenuManager.d.ts +79 -0
  153. package/dist/idae/menu/IdaeMenuManager.js +108 -0
  154. package/dist/idae/menu/IdaeMenuStore.d.ts +77 -0
  155. package/dist/idae/menu/IdaeMenuStore.js +68 -0
  156. package/dist/idae/menu/menuSnapshot.d.ts +30 -0
  157. package/dist/idae/menu/menuSnapshot.js +30 -0
  158. package/dist/idae/meta/MetaModelProvider.d.ts +11 -0
  159. package/dist/idae/meta/MetaModelProvider.js +43 -0
  160. package/dist/idae/relations/RelationPolicy.d.ts +19 -0
  161. package/dist/idae/relations/RelationPolicy.js +125 -0
  162. package/dist/idae/rights/RightsPolicy.d.ts +16 -0
  163. package/dist/idae/rights/RightsPolicy.js +80 -0
  164. package/dist/idae/userscope/UserScopePolicy.d.ts +9 -0
  165. package/dist/idae/userscope/UserScopePolicy.js +42 -0
  166. package/dist/idae/userscope/navTracking.d.ts +11 -0
  167. package/dist/idae/userscope/navTracking.js +15 -0
  168. package/dist/index.d.ts +68 -43
  169. package/dist/index.js +82 -44
  170. package/dist/main/__tests__/_relationTestUtils.d.ts +12 -0
  171. package/dist/main/__tests__/_relationTestUtils.js +53 -0
  172. package/dist/main/__tests__/helpers/mockCollection.d.ts +21 -0
  173. package/dist/main/__tests__/helpers/mockCollection.js +27 -0
  174. package/dist/main/api/types.d.ts +29 -0
  175. package/dist/main/ext/hooks.d.ts +32 -0
  176. package/dist/main/ext/hooks.js +31 -0
  177. package/dist/main/ext/interfaces.d.ts +69 -0
  178. package/dist/main/ext/interfaces.js +3 -0
  179. package/dist/main/ext/registry.d.ts +29 -0
  180. package/dist/main/ext/registry.js +30 -0
  181. package/dist/main/frame/MachineFrameManager.d.ts +187 -0
  182. package/dist/main/frame/MachineFrameManager.js +403 -0
  183. package/dist/main/frame/contextMenuSetup.d.ts +9 -0
  184. package/dist/main/frame/contextMenuSetup.js +42 -0
  185. package/dist/main/frame/frameUrl.d.ts +1 -0
  186. package/dist/main/frame/frameUrl.js +8 -0
  187. package/dist/main/frame/frameUtils.d.ts +16 -0
  188. package/dist/main/frame/frameUtils.js +26 -0
  189. package/dist/main/frame/linkParser.d.ts +9 -0
  190. package/dist/main/frame/linkParser.js +15 -0
  191. package/dist/main/index.d.ts +15 -0
  192. package/dist/main/index.js +19 -0
  193. package/dist/main/machine/MachineAction.d.ts +62 -0
  194. package/dist/main/machine/MachineAction.js +96 -0
  195. package/dist/main/machine/MachineError.d.ts +33 -0
  196. package/dist/main/machine/MachineError.js +49 -0
  197. package/dist/main/machine/MachineErrorValidation.d.ts +19 -0
  198. package/dist/main/machine/MachineErrorValidation.js +24 -0
  199. package/dist/main/machine/MachineFieldType.d.ts +140 -0
  200. package/dist/main/machine/MachineFieldType.js +341 -0
  201. package/dist/main/machine/MachineFkFold.d.ts +34 -0
  202. package/dist/main/machine/MachineFkFold.js +57 -0
  203. package/dist/main/machine/MachineRecordIdentity.d.ts +26 -0
  204. package/dist/main/machine/MachineRecordIdentity.js +44 -0
  205. package/dist/main/machine/MachineRights.d.ts +50 -0
  206. package/dist/main/machine/MachineRights.js +133 -0
  207. package/dist/main/machine/MachineRouter.d.ts +56 -0
  208. package/dist/main/machine/MachineRouter.js +250 -0
  209. package/dist/main/machine/MachineScheme.d.ts +54 -0
  210. package/dist/main/machine/MachineScheme.js +159 -0
  211. package/dist/main/machine/MachineSchemeField.js +67 -0
  212. package/dist/main/machine/MachineSchemeFieldForge.d.ts +84 -0
  213. package/dist/main/machine/MachineSchemeFieldForge.js +140 -0
  214. package/dist/main/machine/MachineSchemeFieldValues.d.ts +68 -0
  215. package/dist/main/machine/MachineSchemeFieldValues.js +97 -0
  216. package/dist/main/machine/MachineSchemeValidate.d.ts +107 -0
  217. package/dist/main/machine/MachineSchemeValidate.js +247 -0
  218. package/dist/main/machine/MachineSchemeValues.d.ts +120 -0
  219. package/dist/main/machine/MachineSchemeValues.js +306 -0
  220. package/dist/main/machine/SchemeFieldDefaultValues.d.ts +76 -0
  221. package/dist/main/machine/SchemeFieldDefaultValues.js +104 -0
  222. package/dist/main/machine/authState.svelte.d.ts +11 -0
  223. package/dist/main/machine/authState.svelte.js +17 -0
  224. package/dist/main/machine/fieldBuilder.d.ts +23 -0
  225. package/dist/main/machine/fieldBuilder.d.ts.map +1 -0
  226. package/dist/main/machine/fieldBuilder.js +10 -0
  227. package/dist/main/machine/fieldBuilder.js.map +1 -0
  228. package/dist/main/machine/machineLabel.d.ts +11 -0
  229. package/dist/main/machine/machineLabel.js +23 -0
  230. package/dist/main/machine/validateRules.d.ts +38 -0
  231. package/dist/main/machine/validateRules.js +109 -0
  232. package/dist/main/machine.d.ts +227 -61
  233. package/dist/main/machine.js +503 -86
  234. package/dist/main/machineDb.d.ts +25 -54
  235. package/dist/main/machineDb.js +40 -94
  236. package/dist/main/machineIdbAdapter.d.ts +83 -0
  237. package/dist/main/machineIdbAdapter.js +347 -0
  238. package/dist/main/machineModelBuilder.d.ts +31 -0
  239. package/dist/main/machineModelBuilder.js +58 -0
  240. package/dist/main/machineParserForge.d.ts +38 -0
  241. package/dist/main/machineParserForge.js +168 -0
  242. package/dist/main/machineSchemaCache.d.ts +8 -0
  243. package/dist/main/machineSchemaCache.js +58 -0
  244. package/dist/main/machineSchemaDoctor.d.ts +17 -0
  245. package/dist/main/machineSchemaDoctor.js +73 -0
  246. package/dist/main/machineSchemaLoader.d.ts +18 -0
  247. package/dist/main/machineSchemaLoader.js +43 -0
  248. package/dist/main/machineSeed.d.ts +21 -0
  249. package/dist/main/machineSeed.js +44 -0
  250. package/dist/main/router/componentRegistry.d.ts +35 -0
  251. package/dist/main/router/componentRegistry.js +35 -0
  252. package/dist/main/router/urlParser.d.ts +17 -0
  253. package/dist/main/router/urlParser.js +41 -0
  254. package/dist/main/warmupUtils.d.ts +40 -0
  255. package/dist/main/warmupUtils.js +73 -0
  256. package/dist/mcp/MachineMcpClient.d.ts +43 -0
  257. package/dist/mcp/MachineMcpClient.js +175 -0
  258. package/dist/shell/Frame.svelte +67 -0
  259. package/dist/shell/Frame.svelte.d.ts +11 -0
  260. package/dist/shell/auth/Login.svelte +244 -0
  261. package/dist/shell/auth/Login.svelte.d.ts +3 -0
  262. package/dist/shell/frame/dashboard/Dashboard.svelte +0 -0
  263. package/dist/shell/frame/dashboard/Dashboard.svelte.d.ts +26 -0
  264. package/dist/shell/frame/diagram/Diagram.svelte +244 -0
  265. package/dist/shell/frame/diagram/Diagram.svelte.d.ts +9 -0
  266. package/dist/shell/frame/explorer/Explorer.svelte +86 -0
  267. package/dist/shell/frame/explorer/Explorer.svelte.d.ts +29 -0
  268. package/dist/shell/frame/explorer/ExplorerContent.svelte +126 -0
  269. package/dist/shell/frame/explorer/ExplorerContent.svelte.d.ts +32 -0
  270. package/dist/shell/frame/index.d.ts +8 -0
  271. package/dist/shell/frame/index.js +9 -0
  272. package/dist/shell/frame/main-menu-content/MainMenuContent.svelte +100 -0
  273. package/dist/shell/frame/main-menu-content/MainMenuContent.svelte.d.ts +6 -0
  274. package/dist/shell/frame/planning/Planning.svelte +426 -0
  275. package/dist/shell/frame/planning/Planning.svelte.d.ts +12 -0
  276. package/dist/shell/frame/rbac/RbacMatrix.svelte +197 -0
  277. package/dist/shell/frame/rbac/RbacMatrix.svelte.d.ts +7 -0
  278. package/dist/shell/frame/space/Space.svelte +554 -0
  279. package/dist/shell/frame/space/Space.svelte.d.ts +8 -0
  280. package/dist/shell/frame/synthesis/Synthesis.svelte +383 -0
  281. package/dist/shell/frame/synthesis/Synthesis.svelte.d.ts +8 -0
  282. package/dist/shell/frame/today/Today.svelte +174 -0
  283. package/dist/shell/frame/today/Today.svelte.d.ts +3 -0
  284. package/dist/shell/layout/App.svelte +30 -0
  285. package/dist/shell/layout/App.svelte.d.ts +3 -0
  286. package/dist/shell/layout/Breadcrumb.svelte +67 -0
  287. package/dist/shell/layout/Breadcrumb.svelte.d.ts +12 -0
  288. package/dist/shell/layout/Columner.svelte +214 -0
  289. package/dist/shell/layout/Columner.svelte.d.ts +16 -0
  290. package/dist/shell/layout/DevResetPanel.svelte +194 -0
  291. package/dist/shell/layout/DevResetPanel.svelte.d.ts +7 -0
  292. package/dist/shell/layout/Fiche.svelte +111 -0
  293. package/dist/shell/layout/Fiche.svelte.d.ts +7 -0
  294. package/dist/shell/layout/FicheUpdate.svelte +53 -0
  295. package/dist/shell/layout/FicheUpdate.svelte.d.ts +7 -0
  296. package/dist/shell/layout/MainMenu.svelte +256 -0
  297. package/dist/shell/layout/MainMenu.svelte.d.ts +6 -0
  298. package/dist/shell/layout/MenuSettings.svelte +182 -0
  299. package/dist/shell/layout/MenuSettings.svelte.d.ts +6 -0
  300. package/dist/shell/layout/RecordTimeline.svelte +199 -0
  301. package/dist/shell/layout/RecordTimeline.svelte.d.ts +8 -0
  302. package/dist/shell/layout/RecordToolbar.svelte +39 -0
  303. package/dist/shell/layout/RecordToolbar.svelte.d.ts +7 -0
  304. package/dist/shell/layout/TaskBar.svelte +118 -0
  305. package/dist/shell/layout/TaskBar.svelte.d.ts +7 -0
  306. package/dist/shell/layout/TemplateShell.svelte +48 -0
  307. package/dist/shell/layout/TemplateShell.svelte.d.ts +15 -0
  308. package/dist/shell/layout/ThemeToggle.svelte +46 -0
  309. package/dist/shell/layout/ThemeToggle.svelte.d.ts +3 -0
  310. package/dist/shell/layout/index.d.ts +8 -0
  311. package/dist/shell/layout/index.js +9 -0
  312. package/dist/storage/ApiStorageAdapter.d.ts +41 -0
  313. package/dist/storage/ApiStorageAdapter.js +111 -0
  314. package/dist/storage/IdbStorageAdapter.d.ts +31 -0
  315. package/dist/storage/IdbStorageAdapter.js +72 -0
  316. package/dist/storage/MemoryStorageAdapter.d.ts +33 -0
  317. package/dist/storage/MemoryStorageAdapter.js +132 -0
  318. package/dist/storage/README.md +222 -0
  319. package/dist/storage/StorageAdapter.d.ts +75 -0
  320. package/dist/storage/StorageAdapter.js +7 -0
  321. package/dist/storage/demo/storage-demo.d.ts +22 -0
  322. package/dist/storage/demo/storage-demo.js +107 -0
  323. package/dist/storage/index.d.ts +9 -0
  324. package/dist/storage/index.js +9 -0
  325. package/dist/types/entity-types.d.ts +444 -0
  326. package/dist/types/entity-types.js +16 -0
  327. package/dist/types/index.d.ts +7 -0
  328. package/dist/types/index.js +6 -0
  329. package/dist/types/machine-model.d.ts +198 -0
  330. package/dist/types/machine-model.js +5 -0
  331. package/dist/types/qoolie-svelte.d.ts +11 -0
  332. package/dist/types/schema-utils.d.ts +32 -0
  333. package/dist/types/schema-utils.js +103 -0
  334. package/dist/utils/generateCode.d.ts +5 -0
  335. package/dist/utils/generateCode.js +9 -0
  336. package/dist/utils/logger.d.ts +10 -0
  337. package/dist/utils/logger.js +20 -0
  338. package/package.json +70 -31
  339. package/dist/db/CrudService.d.ts +0 -9
  340. package/dist/db/CrudService.js +0 -45
  341. package/dist/db/dbSchema.d.ts +0 -201
  342. package/dist/db/dbSchema.js +0 -205
  343. package/dist/db/fieldTypes.d.ts +0 -13
  344. package/dist/db/fieldTypes.js +0 -67
  345. package/dist/db/types.d.ts +0 -124
  346. package/dist/demo/form/CreateUpdate.svelte +0 -198
  347. package/dist/demo/form/CreateUpdate.svelte.d.ts +0 -29
  348. package/dist/demo/form/CrudZone.svelte +0 -22
  349. package/dist/demo/form/CrudZone.svelte.d.ts +0 -29
  350. package/dist/demo/form/DataProvider.svelte +0 -20
  351. package/dist/demo/form/DataProvider.svelte.d.ts +0 -9
  352. package/dist/demo/form/FieldInPlace.svelte +0 -49
  353. package/dist/demo/form/FieldInPlace.svelte.d.ts +0 -11
  354. package/dist/demo/form/FieldValue.svelte +0 -212
  355. package/dist/demo/form/FieldValue.svelte.d.ts +0 -35
  356. package/dist/demo/form/types.d.ts +0 -17
  357. package/dist/demo/form/types.js +0 -1
  358. package/dist/demo/testDbSchema.d.ts +0 -6
  359. package/dist/demo/testDbSchema.js +0 -58
  360. package/dist/demo/types.d.ts +0 -140
  361. package/dist/demo/types.js +0 -1
  362. package/dist/fragments/Confirm.svelte +0 -58
  363. package/dist/fragments/Confirm.svelte.d.ts +0 -11
  364. package/dist/fragments/Frame.svelte +0 -19
  365. package/dist/fragments/Frame.svelte.d.ts +0 -32
  366. package/dist/fragments/InfoLine.svelte +0 -21
  367. package/dist/fragments/InfoLine.svelte.d.ts +0 -35
  368. package/dist/fragments/List.svelte +0 -21
  369. package/dist/fragments/List.svelte.d.ts +0 -38
  370. package/dist/fragments/Selector.svelte +0 -26
  371. package/dist/fragments/Selector.svelte.d.ts +0 -38
  372. package/dist/main/machine/IDbCollection.d.ts +0 -69
  373. package/dist/main/machine/IDbCollection.js +0 -98
  374. package/dist/main/machine/IDbCollectionFieldForge.d.ts +0 -42
  375. package/dist/main/machine/IDbCollectionFieldForge.js +0 -74
  376. package/dist/main/machine/IDbCollectionFieldValues.d.ts +0 -46
  377. package/dist/main/machine/IDbCollectionFieldValues.js +0 -62
  378. package/dist/main/machine/IDbCollectionValues.d.ts +0 -78
  379. package/dist/main/machine/IDbCollectionValues.js +0 -203
  380. package/dist/main/machine/IDbError.d.ts +0 -6
  381. package/dist/main/machine/IDbError.js +0 -61
  382. package/dist/main/machine/IDbFormValidate.d.ts +0 -55
  383. package/dist/main/machine/IDbFormValidate.js +0 -183
  384. package/dist/main/machine/IDbValidationError.d.ts +0 -19
  385. package/dist/main/machine/IDbValidationError.js +0 -24
  386. package/dist/main/machine/types.d.ts +0 -1
  387. package/dist/main/machine/types.js +0 -1
  388. package/dist/main/machineForge.d.ts +0 -57
  389. package/dist/main/machineForge.js +0 -105
  390. package/dist/types/appschemeTypes.d.ts +0 -71
  391. package/dist/types/appschemeTypes.js +0 -83
  392. package/dist/ui/CollectionButton.svelte +0 -26
  393. package/dist/ui/CollectionButton.svelte.d.ts +0 -29
  394. package/dist/ui/CollectionFieldGuess.svelte +0 -29
  395. package/dist/ui/CollectionFieldGuess.svelte.d.ts +0 -11
  396. package/dist/ui/CollectionFks.svelte +0 -24
  397. package/dist/ui/CollectionFks.svelte.d.ts +0 -9
  398. package/dist/ui/CollectionList.svelte +0 -95
  399. package/dist/ui/CollectionList.svelte.d.ts +0 -37
  400. package/dist/ui/CollectionListMenu.svelte +0 -47
  401. package/dist/ui/CollectionListMenu.svelte.d.ts +0 -34
  402. package/dist/ui/CollectionReverseFks.svelte +0 -56
  403. package/dist/ui/CollectionReverseFks.svelte.d.ts +0 -18
  404. /package/dist/{fragments → data-ui/fragments}/Skeleton.svelte.d.ts +0 -0
  405. /package/dist/{db → main/api}/types.js +0 -0
@@ -0,0 +1,347 @@
1
+ /**
2
+ * machineIdbAdapter.ts
3
+ * IndexedDB introspection and upgrade utilities.
4
+ *
5
+ * Core principle: MongoDB appscheme_* = source of truth.
6
+ * IDB = cache/replica that auto-adapts when server schema changes.
7
+ *
8
+ * Architecture note: Qoolie is now the sole IDB opener/creator (see IDB.md §5b).
9
+ * This module provides read-only introspection and drift detection.
10
+ * Never calls indexedDB.open() with a version - that's Qoolie's responsibility.
11
+ *
12
+ * Constraint: Machine supports only one live Qoolie instance at a time due to
13
+ * shared idbEventBus in Qoolie. Multiple concurrent instances would cause
14
+ * reactive-read collisions. boot() destroys old instance before creating new one.
15
+ */
16
+ const INTERNAL_STORES = new Set(['__outbox__', '__schema_meta__', '__migrations__']);
17
+ /** True for internal stores that must never be deleted. */
18
+ export function isProtectedStore(name) {
19
+ return name.startsWith('__') && name.endsWith('__');
20
+ }
21
+ /**
22
+ * Translate a Dexie-style keyPath config ('++id', 'id', '&code', 'a, b, ++id')
23
+ * into native createObjectStore options. Mirrors qoolie's IdbSchema.createSchema:
24
+ * native IDB rejects '++id' ("keyPath is not a valid key path") — the '++' prefix
25
+ * means autoIncrement on the bare field name.
26
+ */
27
+ export function nativeStoreOptions(config) {
28
+ const fields = (config ?? '++id').split(',').map((f) => f.trim());
29
+ const incrementField = fields.find((f) => f.startsWith('++'))?.replace('++', '');
30
+ const declaredIndex = fields.find((f) => f.startsWith('&'))?.replace('&', '');
31
+ const keyPath = incrementField || declaredIndex || fields[0];
32
+ return { keyPath, autoIncrement: Boolean(incrementField) };
33
+ }
34
+ /**
35
+ * Detect drift between expected schema and actual IDB stores.
36
+ * Returns PendingIdbUpgrade (with bumped version) if drift found, null if schema is current.
37
+ */
38
+ export async function detectSchemaDrift(dbName, version, effectiveModel) {
39
+ if (!dbName || !version)
40
+ return null;
41
+ const expectedStores = Object.keys(effectiveModel);
42
+ const expectedHash = computeSchemaHash(expectedStores);
43
+ let storedHash;
44
+ try {
45
+ storedHash = await getStoredSchemaHash(dbName);
46
+ }
47
+ catch (err) {
48
+ console.warn('[idae-machine] Could not read stored schema hash:', err);
49
+ storedHash = null;
50
+ }
51
+ if (storedHash === expectedHash)
52
+ return null;
53
+ let actualStores;
54
+ try {
55
+ actualStores = await getCurrentIdbStores(dbName);
56
+ }
57
+ catch (err) {
58
+ console.warn('[idae-machine] Could not read IDB stores for drift detection:', err);
59
+ return null;
60
+ }
61
+ const toCreate = expectedStores.filter((s) => !actualStores.has(s));
62
+ const toDelete = [...actualStores].filter((s) => !expectedStores.includes(s));
63
+ if (toCreate.length === 0 && toDelete.length === 0) {
64
+ // Stores match but hash differs — just persist hash, no version bump needed
65
+ try {
66
+ await storeSchemaHash(dbName, expectedHash);
67
+ }
68
+ catch (err) {
69
+ console.warn('[idae-machine] Could not persist schema hash (will retry on next start):', err);
70
+ }
71
+ return null;
72
+ }
73
+ return { toCreate, toDelete, expectedHash, newVersion: version + 1 };
74
+ }
75
+ /**
76
+ * Detect potential store renames: deleted store keyPath matches created store.
77
+ */
78
+ function detectStoreRenames(db, upgrade, effectiveModel) {
79
+ const renames = [];
80
+ for (const deletedName of upgrade.toDelete) {
81
+ if (isProtectedStore(deletedName))
82
+ continue;
83
+ if (!db.objectStoreNames.contains(deletedName))
84
+ continue;
85
+ const deletedStore = db.objectStore(deletedName);
86
+ const deletedKeyPath = deletedStore.keyPath;
87
+ for (const createdName of upgrade.toCreate) {
88
+ const colDef = effectiveModel[createdName];
89
+ const createdKeyPath = colDef?.keyPath ?? '++id';
90
+ if (deletedKeyPath === createdKeyPath || (deletedKeyPath === null && createdKeyPath === '++id')) {
91
+ renames.push({ from: deletedName, to: createdName, keyPath: createdKeyPath });
92
+ break;
93
+ }
94
+ }
95
+ }
96
+ return renames;
97
+ }
98
+ /**
99
+ * Perform IDB schema upgrade: handle store renames and deletions.
100
+ * Called after detectSchemaDrift() returned a pending upgrade.
101
+ *
102
+ * Qoolie now handles all store creation (including __schema_meta__) in its onupgradeneeded handler.
103
+ * This method only handles:
104
+ * - Store renames: copies data from old → new store when keyPath matches
105
+ * - Store deletions: removes orphaned stores (excluding protected stores)
106
+ * - Store creation: only for stores not created by Qoolie (fallback)
107
+ *
108
+ * Edge cases handled:
109
+ * - __outbox__ / internal stores: never deleted
110
+ * - Rename detection: copies data from old → new store when keyPath matches
111
+ */
112
+ export async function performIdbUpgrade(dbName, version, upgrade, effectiveModel) {
113
+ // Qoolie now handles all store creation in its onupgradeneeded handler,
114
+ // including __schema_meta__. This method only handles renames and deletions.
115
+ // Pure-creation case (toDelete empty): skip — qoolie's single open creates
116
+ // everything (business stores + __schema_meta__ + __outbox__ + indexes).
117
+ // Doing our own versioned open here would consume the version bump and
118
+ // starve qoolie's onupgradeneeded (same-version reopen never fires it).
119
+ if (upgrade.toCreate.length > 0 && upgrade.toDelete.length === 0)
120
+ return;
121
+ await new Promise((resolve, reject) => {
122
+ if (typeof indexedDB === 'undefined') {
123
+ resolve();
124
+ return;
125
+ }
126
+ const req = indexedDB.open(dbName, version);
127
+ req.onupgradeneeded = (e) => {
128
+ const db = e.target.result;
129
+ const renames = detectStoreRenames(db, upgrade, effectiveModel);
130
+ for (const { from, to, keyPath } of renames) {
131
+ if (!db.objectStoreNames.contains(from))
132
+ continue;
133
+ const oldStore = db.objectStore(from);
134
+ const newStore = db.createObjectStore(to, nativeStoreOptions(keyPath));
135
+ const cursor = oldStore.openCursor();
136
+ cursor.onsuccess = () => {
137
+ const c = cursor.result;
138
+ if (c) {
139
+ newStore.add(c.value);
140
+ c.continue();
141
+ }
142
+ };
143
+ db.deleteObjectStore(from);
144
+ }
145
+ const renamedFrom = new Set(renames.map((r) => r.from));
146
+ for (const name of upgrade.toDelete) {
147
+ if (renamedFrom.has(name) || isProtectedStore(name))
148
+ continue;
149
+ if (db.objectStoreNames.contains(name))
150
+ db.deleteObjectStore(name);
151
+ }
152
+ const renamedTo = new Set(renames.map((r) => r.to));
153
+ for (const name of upgrade.toCreate) {
154
+ if (renamedTo.has(name) || db.objectStoreNames.contains(name))
155
+ continue;
156
+ db.createObjectStore(name, nativeStoreOptions(effectiveModel[name]?.keyPath));
157
+ }
158
+ };
159
+ req.onsuccess = () => { req.result.close(); resolve(); };
160
+ req.onerror = () => reject(req.error);
161
+ // Versioned open blocks when another connection holds the DB at a lower version
162
+ // (e.g. a second app tab in Edge). Without this handler the open never settles →
163
+ // boot hangs forever on the splash. Reject so the caller surfaces a real error.
164
+ req.onblocked = () => reject(new Error('IndexedDB upgrade blocked — another tab holds the database open. Close other tabs and reload.'));
165
+ });
166
+ // NOTE: schema-hash persistence is intentionally NOT done here. __schema_meta__ is
167
+ // created by qoolie's versioned open, which runs AFTER this function in createStore().
168
+ // The caller (machine.createStore) persists the hash once qoolie is ready.
169
+ }
170
+ /**
171
+ * Deterministic hash of expected store names — sorted join, order-independent.
172
+ */
173
+ export function computeSchemaHash(storeNames) {
174
+ return [...storeNames].sort().join(',');
175
+ }
176
+ /**
177
+ * Opens IDB briefly to read actual object store names.
178
+ * Excludes internal stores (__outbox__, __schema_meta__, __migrations__).
179
+ * Returns empty Set if database doesn't exist (to avoid creating it with no-version open).
180
+ */
181
+ export function getCurrentIdbStores(dbName) {
182
+ return new Promise((resolve, reject) => {
183
+ if (typeof indexedDB === 'undefined') {
184
+ resolve(new Set());
185
+ return;
186
+ }
187
+ // Fix for D1: Avoid creating DB with no-version open.
188
+ // Check if database exists. If not, return empty Set.
189
+ // This prevents interfering with Qoolie's proper versioned creation.
190
+ const req = indexedDB.open(dbName);
191
+ req.onsuccess = (e) => {
192
+ const db = e.target.result;
193
+ // Fix for D1: If version is 0, DB was just created by this no-version open.
194
+ // Return empty Set to avoid interfering with Qoolie's proper versioned creation.
195
+ if (db.version === 0) {
196
+ db.close();
197
+ resolve(new Set());
198
+ return;
199
+ }
200
+ const stores = new Set();
201
+ for (let i = 0; i < db.objectStoreNames.length; i++) {
202
+ const name = db.objectStoreNames.item(i);
203
+ if (name && !INTERNAL_STORES.has(name))
204
+ stores.add(name);
205
+ }
206
+ db.close();
207
+ resolve(stores);
208
+ };
209
+ req.onerror = () => {
210
+ // If we can't open the database, it likely doesn't exist
211
+ // Return empty Set instead of rejecting to avoid creating it
212
+ resolve(new Set());
213
+ };
214
+ // Blocked (rare for a no-version open) → degrade to empty rather than hang.
215
+ req.onblocked = () => resolve(new Set());
216
+ });
217
+ }
218
+ /**
219
+ * Returns the actual current version of the IDB database, or 0 if it doesn't exist.
220
+ * Used to prevent version downgrade when re-opening after a drift-triggered increment.
221
+ * Returns 0 if database doesn't exist (to avoid creating it with no-version open).
222
+ */
223
+ export function getActualIdbVersion(dbName) {
224
+ return new Promise((resolve) => {
225
+ if (typeof indexedDB === 'undefined') {
226
+ resolve(0);
227
+ return;
228
+ }
229
+ const req = indexedDB.open(dbName);
230
+ req.onsuccess = (e) => {
231
+ const db = e.target.result;
232
+ // If version is 0, the database was just created by this open call
233
+ // In this case, return 0 to avoid interfering with proper creation
234
+ if (db.version === 0) {
235
+ db.close();
236
+ resolve(0);
237
+ return;
238
+ }
239
+ const version = db.version;
240
+ db.close();
241
+ resolve(version);
242
+ };
243
+ req.onerror = () => {
244
+ // If we can't open the database, it likely doesn't exist
245
+ // Return 0 instead of rejecting to avoid creating it
246
+ resolve(0);
247
+ };
248
+ req.onblocked = () => resolve(0);
249
+ });
250
+ }
251
+ /**
252
+ * Read the persisted schema hash from __schema_meta__ store.
253
+ * Returns null if the store doesn't exist or no hash is stored.
254
+ * Returns null if database doesn't exist (to avoid creating it with no-version open).
255
+ */
256
+ export function getStoredSchemaHash(dbName) {
257
+ return new Promise((resolve) => {
258
+ if (typeof indexedDB === 'undefined') {
259
+ resolve(null);
260
+ return;
261
+ }
262
+ const req = indexedDB.open(dbName);
263
+ req.onsuccess = (e) => {
264
+ const db = e.target.result;
265
+ // If version is 0, the database was just created by this open call
266
+ // In this case, return null to avoid interfering with proper creation
267
+ if (db.version === 0) {
268
+ db.close();
269
+ resolve(null);
270
+ return;
271
+ }
272
+ if (!db.objectStoreNames.contains('__schema_meta__')) {
273
+ db.close();
274
+ resolve(null);
275
+ return;
276
+ }
277
+ const tx = db.transaction('__schema_meta__', 'readonly');
278
+ const store = tx.objectStore('__schema_meta__');
279
+ const getReq = store.get('schema_hash');
280
+ getReq.onsuccess = () => {
281
+ db.close();
282
+ resolve(getReq.result?.hash ?? null);
283
+ };
284
+ getReq.onerror = () => {
285
+ db.close();
286
+ resolve(null);
287
+ };
288
+ };
289
+ req.onerror = () => {
290
+ // If we can't open the database, it likely doesn't exist
291
+ // Return null instead of rejecting to avoid creating it
292
+ resolve(null);
293
+ };
294
+ req.onblocked = () => resolve(null);
295
+ });
296
+ }
297
+ /**
298
+ * Persist the schema hash into __schema_meta__ store.
299
+ * Auto-creates the store if it doesn't exist (requires version bump via upgradeIdb).
300
+ */
301
+ export function storeSchemaHash(dbName, hash) {
302
+ return new Promise((resolve, reject) => {
303
+ if (typeof indexedDB === 'undefined') {
304
+ resolve();
305
+ return;
306
+ }
307
+ const req = indexedDB.open(dbName);
308
+ req.onsuccess = (e) => {
309
+ const db = e.target.result;
310
+ if (!db.objectStoreNames.contains('__schema_meta__')) {
311
+ db.close();
312
+ // Need version bump to create store — caller should handle via upgradeIdb
313
+ reject(new Error('__schema_meta__ store not found — call upgradeIdb first'));
314
+ return;
315
+ }
316
+ const tx = db.transaction('__schema_meta__', 'readwrite');
317
+ const store = tx.objectStore('__schema_meta__');
318
+ store.put({ id: 'schema_hash', hash });
319
+ tx.oncomplete = () => {
320
+ db.close();
321
+ resolve();
322
+ };
323
+ tx.onerror = () => {
324
+ db.close();
325
+ reject(tx.error);
326
+ };
327
+ };
328
+ req.onerror = () => reject(req.error);
329
+ req.onblocked = () => reject(new Error('IndexedDB blocked while persisting schema hash — close other tabs.'));
330
+ });
331
+ }
332
+ /**
333
+ * Delete an IDB database entirely — dev tool, irreversible.
334
+ * Does NOT reload the page — caller decides.
335
+ */
336
+ export function deleteIdbDatabase(dbName) {
337
+ return new Promise((resolve, reject) => {
338
+ if (typeof indexedDB === 'undefined') {
339
+ resolve();
340
+ return;
341
+ }
342
+ const req = indexedDB.deleteDatabase(dbName);
343
+ req.onsuccess = () => resolve();
344
+ req.onerror = () => reject(req.error);
345
+ req.onblocked = () => reject(new Error('IDB delete blocked — close other tabs'));
346
+ });
347
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * machineModelBuilder.ts
3
+ * Pure merge of `core` and `business` MachineModels — no system baseline injection.
4
+ *
5
+ * The system baseline (appscheme_*, appuser_*, …) is the server's responsibility:
6
+ * MongoDB `appscheme_*` rows are deployed from `idaeModelCore`
7
+ * (server/src/idae/idae-model-core.ts) at server bootstrap, and the
8
+ * client receives them through `machine.boot({ sync: { databaseHost } })`. Reading
9
+ * `idaeModelCore` directly on the client is forbidden (see header in that file
10
+ * and BACK-07).
11
+ */
12
+ import type { MachineModel } from '../types/index.js';
13
+ /**
14
+ * Ensure every collection declares a `code` field (semantic key, sibling of `id`).
15
+ * Delegates to the domain bridge if registered; falls back to inline implementation.
16
+ */
17
+ export declare function ensureCodeField(model: MachineModel): MachineModel;
18
+ /**
19
+ * Merge an optional core MachineModel with an optional business MachineModel.
20
+ * Priority on key collision: business > core. Guarantees the `code` invariant.
21
+ *
22
+ * FK relations stay in the structured `fks` block (MachineFkDef) — they are NOT
23
+ * folded into `fields`. Resolution reads the `fks` block directly (findFkField,
24
+ * descriptor, useViewFields); the legacy synthesized `fk-X.code` field is
25
+ * deprecated (see SCHEMA-CONVENTIONS.md §FK resolution).
26
+ *
27
+ * @param core Optional framework collections (rarely set directly — usually the
28
+ * server-delivered schema covers everything).
29
+ * @param business Optional application-specific collections.
30
+ */
31
+ export declare function buildEffectiveModel(core?: MachineModel, business?: MachineModel): MachineModel;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * machineModelBuilder.ts
3
+ * Pure merge of `core` and `business` MachineModels — no system baseline injection.
4
+ *
5
+ * The system baseline (appscheme_*, appuser_*, …) is the server's responsibility:
6
+ * MongoDB `appscheme_*` rows are deployed from `idaeModelCore`
7
+ * (server/src/idae/idae-model-core.ts) at server bootstrap, and the
8
+ * client receives them through `machine.boot({ sync: { databaseHost } })`. Reading
9
+ * `idaeModelCore` directly on the client is forbidden (see header in that file
10
+ * and BACK-07).
11
+ */
12
+ import { getCodeFieldConvention } from './ext/hooks.js';
13
+ import { field } from './machine/fieldBuilder.js';
14
+ /**
15
+ * Ensure every collection declares a `code` field (semantic key, sibling of `id`).
16
+ * Delegates to the domain bridge if registered; falls back to inline implementation.
17
+ */
18
+ export function ensureCodeField(model) {
19
+ const convention = getCodeFieldConvention();
20
+ if (convention) {
21
+ return convention.ensureCodeField(model);
22
+ }
23
+ // Fallback: inline implementation (domain not yet registered)
24
+ const out = {};
25
+ for (const [name, col] of Object.entries(model)) {
26
+ const fields = col.fields ?? {};
27
+ if ('code' in fields) {
28
+ out[name] = col;
29
+ continue;
30
+ }
31
+ const rebuilt = {};
32
+ for (const [fn, fd] of Object.entries(fields)) {
33
+ rebuilt[fn] = fd;
34
+ if (fn === 'id')
35
+ rebuilt.code = field('text');
36
+ }
37
+ if (!('code' in rebuilt))
38
+ rebuilt.code = field('text');
39
+ out[name] = { ...col, fields: rebuilt };
40
+ }
41
+ return out;
42
+ }
43
+ /**
44
+ * Merge an optional core MachineModel with an optional business MachineModel.
45
+ * Priority on key collision: business > core. Guarantees the `code` invariant.
46
+ *
47
+ * FK relations stay in the structured `fks` block (MachineFkDef) — they are NOT
48
+ * folded into `fields`. Resolution reads the `fks` block directly (findFkField,
49
+ * descriptor, useViewFields); the legacy synthesized `fk-X.code` field is
50
+ * deprecated (see SCHEMA-CONVENTIONS.md §FK resolution).
51
+ *
52
+ * @param core Optional framework collections (rarely set directly — usually the
53
+ * server-delivered schema covers everything).
54
+ * @param business Optional application-specific collections.
55
+ */
56
+ export function buildEffectiveModel(core, business) {
57
+ return ensureCodeField({ ...(core ?? {}), ...(business ?? {}) });
58
+ }
@@ -0,0 +1,38 @@
1
+ import type { TplFieldRules, IDbForge } from '../types/index.js';
2
+ /**
3
+ * Utility class for parsing and constructing database field definitions (IDbForge).
4
+ * Provides methods to analyze field rules and extract type information for schema generation.
5
+ */
6
+ export declare class MachineParserForge {
7
+ #private;
8
+ /**
9
+ * Create a new MachineParserForge instance.
10
+ */
11
+ constructor();
12
+ /**
13
+ * Test if a field rule matches a specific type (array, object, fk, primitive).
14
+ * Accepts both legacy string rules ('text-long (required)') and new object rules ({ type: 'text', required: true }).
15
+ * @param what - The type to test for ("array", "object", "fk", "primitive").
16
+ * @param fieldRule - The field rule (string or object) to analyze.
17
+ * @returns Partial IDbForge object if the rule matches, otherwise undefined.
18
+ */
19
+ testIs(what: 'array' | 'object' | 'fk' | 'primitive', fieldRule: TplFieldRules | string): Partial<IDbForge> | undefined;
20
+ /**
21
+ * Returns a partial IDbForge object for the given type and field rule.
22
+ * @param what - The type to extract ("array", "object", "fk", "primitive").
23
+ * @param fieldRule - The field rule string to analyze.
24
+ * @returns Partial IDbForge object with extracted type info.
25
+ */
26
+ is(what: 'array' | 'object' | 'fk' | 'primitive', fieldRule: string): Partial<IDbForge>;
27
+ /**
28
+ * Extracts type, rule, and argument information from a string field rule.
29
+ * Only called after object rules are handled by #fromObjectRule.
30
+ */
31
+ extract(type: 'array' | 'object' | 'fk' | 'primitive', fieldRule: string): Partial<IDbForge>;
32
+ /**
33
+ * Constructs an IDbForge object from its components.
34
+ * @param params - The components of the IDbForge object.
35
+ * @returns A complete IDbForge object.
36
+ */
37
+ forge(input: IDbForge): IDbForge;
38
+ }
@@ -0,0 +1,168 @@
1
+ import { MachineError } from './machine/MachineError.js';
2
+ /**
3
+ * Utility class for parsing and constructing database field definitions (IDbForge).
4
+ * Provides methods to analyze field rules and extract type information for schema generation.
5
+ */
6
+ export class MachineParserForge {
7
+ /**
8
+ * Create a new MachineParserForge instance.
9
+ */
10
+ constructor() { }
11
+ /**
12
+ * Test if a field rule matches a specific type (array, object, fk, primitive).
13
+ * Accepts both legacy string rules ('text-long (required)') and new object rules ({ type: 'text', required: true }).
14
+ * @param what - The type to test for ("array", "object", "fk", "primitive").
15
+ * @param fieldRule - The field rule (string or object) to analyze.
16
+ * @returns Partial IDbForge object if the rule matches, otherwise undefined.
17
+ */
18
+ testIs(what, fieldRule) {
19
+ // New world: object-based field rule
20
+ if (typeof fieldRule === 'object' && fieldRule !== null) {
21
+ return this.#fromObjectRule(what, fieldRule);
22
+ }
23
+ // Legacy: string-based field rule
24
+ const typeMappings = {
25
+ fk: 'fk-',
26
+ array: 'array-of-',
27
+ object: 'object-',
28
+ primitive: ''
29
+ };
30
+ const prefix = typeMappings[what];
31
+ // For primitive, ensure it does not start with any other type prefix
32
+ if (what === 'primitive') {
33
+ if (!fieldRule.startsWith('array-of-') &&
34
+ !fieldRule.startsWith('object-') &&
35
+ !fieldRule.startsWith('fk-')) {
36
+ return this.is(what, fieldRule);
37
+ }
38
+ return undefined;
39
+ }
40
+ // For other types, check if the rule starts with the expected prefix
41
+ if (fieldRule.startsWith(prefix)) {
42
+ return this.is(what, fieldRule);
43
+ }
44
+ return undefined;
45
+ }
46
+ /**
47
+ * Parse a new-world object field rule into IDbForge format.
48
+ * Only returns a value when `what` matches the actual type of the rule.
49
+ */
50
+ #fromObjectRule(what, rule) {
51
+ // Fallback mirrors publishModel.ts's `fd.type ?? 'text'` — type is resolved
52
+ // catalog-first server-side (FieldList, ADR-field-type-source.md); a bare
53
+ // `{ required, readonly }` field (core convention) has no type here either.
54
+ const type = rule.type ?? 'text';
55
+ const isArray = type.startsWith('array-of-');
56
+ const isObject = type.startsWith('object-');
57
+ const isFk = type.startsWith('fk-');
58
+ const isPrimitive = !isArray && !isObject && !isFk;
59
+ const matches = {
60
+ array: isArray, object: isObject, fk: isFk, primitive: isPrimitive
61
+ };
62
+ if (!matches[what])
63
+ return undefined;
64
+ const fieldArgs = this.#argsFromObject(rule);
65
+ // Pass through any extra display/forge options (presets, preset, free, maxSize, etc.).
66
+ // `group` is scheme metadata, not part of IDbForge, so it's stripped along with the
67
+ // other known base keys.
68
+ const { type: _t, required: _req, readonly: _ro, private: _priv, group: _grp, ...extras } = rule;
69
+ return {
70
+ fieldType: type,
71
+ fieldArgs,
72
+ is: what,
73
+ ...extras,
74
+ ...(type === 'image' ? { accept: 'image/*' } : {}),
75
+ };
76
+ }
77
+ /**
78
+ * Extract fieldArgs array from an object rule's boolean flags.
79
+ */
80
+ #argsFromObject(rule) {
81
+ const args = [];
82
+ if (rule.required)
83
+ args.push('required');
84
+ if (rule.readonly)
85
+ args.push('readonly');
86
+ if (rule.private)
87
+ args.push('private');
88
+ return args.length ? args : undefined;
89
+ }
90
+ /**
91
+ * Returns a partial IDbForge object for the given type and field rule.
92
+ * @param what - The type to extract ("array", "object", "fk", "primitive").
93
+ * @param fieldRule - The field rule string to analyze.
94
+ * @returns Partial IDbForge object with extracted type info.
95
+ */
96
+ is(what, fieldRule) {
97
+ return this.extract(what, fieldRule);
98
+ }
99
+ /**
100
+ * Extracts type, rule, and argument information from a string field rule.
101
+ * Only called after object rules are handled by #fromObjectRule.
102
+ */
103
+ extract(type, fieldRule) {
104
+ /**
105
+ * Helper to extract the substring after a given pattern, before any arguments.
106
+ * @param pattern - The prefix pattern to remove.
107
+ * @param source - The field rule string.
108
+ * @returns The substring after the pattern.
109
+ */
110
+ function extractAfter(pattern, source) {
111
+ const reg = source?.split('(')?.[0];
112
+ const after = reg.split(pattern)[1];
113
+ return (after?.split('(')?.[0]?.trim() ?? '');
114
+ }
115
+ /**
116
+ * Helper to extract the main type and argument list from a field rule string.
117
+ * @param source - The field rule string.
118
+ * @returns Object with the main type (piece) and argument array (args).
119
+ */
120
+ function extractArgs(source) {
121
+ const [piece, remaining] = source.split('(');
122
+ if (!remaining)
123
+ return { piece: piece.trim() };
124
+ let central;
125
+ if (remaining !== undefined) {
126
+ [central] = remaining.split(')');
127
+ }
128
+ const args = central
129
+ ? central
130
+ .split(' ')
131
+ .map((s) => s.trim())
132
+ .filter(Boolean)
133
+ : undefined;
134
+ return { piece: piece.trim(), args };
135
+ }
136
+ const extractedArgs = extractArgs(fieldRule);
137
+ let fieldType;
138
+ const fieldArgs = extractedArgs?.args;
139
+ switch (type) {
140
+ case 'array':
141
+ fieldType = extractAfter('array-of-', fieldRule);
142
+ break;
143
+ case 'object':
144
+ fieldType = extractAfter('object-', fieldRule);
145
+ break;
146
+ case 'fk':
147
+ fieldType = 'fk-' + extractAfter('fk-', fieldRule);
148
+ break;
149
+ case 'primitive':
150
+ fieldType = extractedArgs?.piece;
151
+ break;
152
+ }
153
+ const result = {
154
+ fieldType,
155
+ fieldArgs,
156
+ is: type
157
+ };
158
+ return result;
159
+ }
160
+ /**
161
+ * Constructs an IDbForge object from its components.
162
+ * @param params - The components of the IDbForge object.
163
+ * @returns A complete IDbForge object.
164
+ */
165
+ forge(input) {
166
+ return { ...input };
167
+ }
168
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * IDB-backed schema cache for remote schema loading during machine.boot().
3
+ * Stores raw IdbqModel JSON keyed by URL in a dedicated _schema store.
4
+ * Uses stale-while-revalidate: serve cache immediately, refresh in background.
5
+ */
6
+ export declare function readSchemaCache(url: string): Promise<unknown | null>;
7
+ export declare function clearSchemaCache(): Promise<void>;
8
+ export declare function writeSchemaCache(url: string, data: unknown): Promise<void>;