@medyll/idae-machine 0.135.2 → 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 (375) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +555 -360
  3. package/cli.cjs +22 -0
  4. package/dist/__fixtures__/demoModel.d.ts +79 -0
  5. package/dist/__fixtures__/demoModel.js +146 -0
  6. package/dist/ai/frame/AiChatSession.svelte +152 -0
  7. package/dist/ai/frame/AiChatSession.svelte.d.ts +7 -0
  8. package/dist/ai/frame/index.d.ts +1 -0
  9. package/dist/ai/frame/index.js +2 -0
  10. package/dist/ai/index.d.ts +9 -0
  11. package/dist/ai/index.js +12 -0
  12. package/dist/ai/schema/ai-catalogs.d.ts +2 -0
  13. package/dist/ai/schema/ai-catalogs.js +86 -0
  14. package/dist/ai/schema/ai-chat-session.d.ts +2 -0
  15. package/dist/ai/schema/ai-chat-session.js +35 -0
  16. package/dist/ai/schema/ai-companion.d.ts +2 -0
  17. package/dist/ai/schema/ai-companion.js +25 -0
  18. package/dist/ai/schema/ai-message.d.ts +2 -0
  19. package/dist/ai/schema/ai-message.js +20 -0
  20. package/dist/ai/schema/ai-tool-call.d.ts +2 -0
  21. package/dist/ai/schema/ai-tool-call.js +18 -0
  22. package/dist/ai/schema/ai-user-prompt.d.ts +2 -0
  23. package/dist/ai/schema/ai-user-prompt.js +17 -0
  24. package/dist/ai/schema/tag.d.ts +2 -0
  25. package/dist/ai/schema/tag.js +14 -0
  26. package/dist/ai/streamIntoRecord.d.ts +31 -0
  27. package/dist/ai/streamIntoRecord.js +79 -0
  28. package/dist/config.d.ts +17 -0
  29. package/dist/config.js +19 -0
  30. package/dist/data-ui/controls/AlphabetFilter.svelte +114 -0
  31. package/dist/data-ui/controls/AlphabetFilter.svelte.d.ts +10 -0
  32. package/dist/data-ui/controls/ButtonAction.svelte +151 -0
  33. package/dist/data-ui/controls/ButtonAction.svelte.d.ts +18 -0
  34. package/dist/data-ui/controls/DataFind.svelte +174 -0
  35. package/dist/data-ui/controls/DataFind.svelte.d.ts +10 -0
  36. package/dist/data-ui/controls/DataGroup.svelte +150 -0
  37. package/dist/data-ui/controls/DataGroup.svelte.d.ts +7 -0
  38. package/dist/data-ui/controls/DataSort.svelte +78 -0
  39. package/dist/data-ui/controls/DataSort.svelte.d.ts +9 -0
  40. package/dist/data-ui/controls/DataToolbar.svelte +67 -0
  41. package/dist/data-ui/controls/DataToolbar.svelte.d.ts +11 -0
  42. package/dist/data-ui/controls/Find.svelte +38 -0
  43. package/dist/data-ui/controls/Find.svelte.d.ts +9 -0
  44. package/dist/data-ui/controls/FkFilter.svelte +94 -0
  45. package/dist/data-ui/controls/FkFilter.svelte.d.ts +11 -0
  46. package/dist/data-ui/controls/Group.svelte +36 -0
  47. package/dist/data-ui/controls/Group.svelte.d.ts +8 -0
  48. package/dist/data-ui/controls/ListMode.svelte +79 -0
  49. package/dist/data-ui/controls/ListMode.svelte.d.ts +10 -0
  50. package/dist/data-ui/controls/Sort.svelte +100 -0
  51. package/dist/data-ui/controls/Sort.svelte.d.ts +8 -0
  52. package/dist/data-ui/data/DataCount.svelte +67 -0
  53. package/dist/data-ui/data/DataCount.svelte.d.ts +36 -0
  54. package/dist/data-ui/data/DataFk.svelte +54 -0
  55. package/dist/data-ui/data/DataFk.svelte.d.ts +11 -0
  56. package/dist/data-ui/data/DataForm.svelte +191 -0
  57. package/dist/data-ui/data/DataForm.svelte.d.ts +15 -0
  58. package/dist/data-ui/data/DataList.svelte +645 -0
  59. package/dist/data-ui/data/DataList.svelte.d.ts +75 -0
  60. package/dist/data-ui/data/DataListFk.svelte +111 -0
  61. package/dist/data-ui/data/DataListFk.svelte.d.ts +13 -0
  62. package/dist/data-ui/data/DataListRfk.svelte +111 -0
  63. package/dist/data-ui/data/DataListRfk.svelte.d.ts +13 -0
  64. package/dist/data-ui/data/DataRecord.svelte +167 -0
  65. package/dist/data-ui/data/DataRecord.svelte.d.ts +22 -0
  66. package/dist/data-ui/data/DataRfk.svelte +73 -0
  67. package/dist/data-ui/data/DataRfk.svelte.d.ts +15 -0
  68. package/dist/data-ui/data/index.d.ts +7 -0
  69. package/dist/data-ui/data/index.js +8 -0
  70. package/dist/data-ui/field/DataField.svelte +343 -0
  71. package/dist/data-ui/field/DataField.svelte.d.ts +33 -0
  72. package/dist/{form/FieldInPlace.svelte → data-ui/field/DataFieldEdit.svelte} +103 -98
  73. package/dist/{form/FieldInPlace.svelte.d.ts → data-ui/field/DataFieldEdit.svelte.d.ts} +5 -5
  74. package/dist/data-ui/field/index.d.ts +2 -0
  75. package/dist/data-ui/field/index.js +3 -0
  76. package/dist/data-ui/field/snippets/FieldAiPrompt.svelte +145 -0
  77. package/dist/data-ui/field/snippets/FieldAiPrompt.svelte.d.ts +14 -0
  78. package/dist/data-ui/field/snippets/FieldBoolean.svelte +43 -0
  79. package/dist/data-ui/field/snippets/FieldBoolean.svelte.d.ts +12 -0
  80. package/dist/data-ui/field/snippets/FieldColor.svelte +48 -0
  81. package/dist/data-ui/field/snippets/FieldColor.svelte.d.ts +10 -0
  82. package/dist/data-ui/field/snippets/FieldCurrency.svelte +105 -0
  83. package/dist/data-ui/field/snippets/FieldCurrency.svelte.d.ts +15 -0
  84. package/dist/data-ui/field/snippets/FieldEmail.svelte +77 -0
  85. package/dist/data-ui/field/snippets/FieldEmail.svelte.d.ts +14 -0
  86. package/dist/data-ui/field/snippets/FieldIcon.svelte +73 -0
  87. package/dist/data-ui/field/snippets/FieldIcon.svelte.d.ts +11 -0
  88. package/dist/data-ui/field/snippets/FieldSelect.svelte +71 -0
  89. package/dist/data-ui/field/snippets/FieldSelect.svelte.d.ts +15 -0
  90. package/dist/data-ui/field/snippets/FieldText.svelte +52 -0
  91. package/dist/data-ui/field/snippets/FieldText.svelte.d.ts +13 -0
  92. package/dist/data-ui/field/snippets/FieldTextarea.svelte +50 -0
  93. package/dist/data-ui/field/snippets/FieldTextarea.svelte.d.ts +13 -0
  94. package/dist/data-ui/field/snippets/index.d.ts +9 -0
  95. package/dist/data-ui/field/snippets/index.js +10 -0
  96. package/dist/data-ui/fragments/ContextMenu.svelte +109 -0
  97. package/dist/data-ui/fragments/ContextMenu.svelte.d.ts +4 -0
  98. package/dist/data-ui/fragments/ContextMenuContent.svelte +275 -0
  99. package/dist/data-ui/fragments/ContextMenuContent.svelte.d.ts +8 -0
  100. package/dist/data-ui/fragments/Frame.svelte +43 -0
  101. package/dist/data-ui/fragments/Frame.svelte.d.ts +10 -0
  102. package/dist/data-ui/fragments/InfoLine.svelte +123 -0
  103. package/dist/data-ui/fragments/InfoLine.svelte.d.ts +12 -0
  104. package/dist/data-ui/fragments/Selector.svelte +56 -0
  105. package/dist/data-ui/fragments/Selector.svelte.d.ts +10 -0
  106. package/dist/{fragments → data-ui/fragments}/Skeleton.svelte +21 -21
  107. package/dist/data-ui/fragments/Tile.svelte +126 -0
  108. package/dist/data-ui/fragments/Tile.svelte.d.ts +14 -0
  109. package/dist/data-ui/fragments/contextMenu.svelte.d.ts +22 -0
  110. package/dist/data-ui/fragments/contextMenu.svelte.js +31 -0
  111. package/dist/data-ui/fragments/dialog/Dialog.svelte +185 -0
  112. package/dist/data-ui/fragments/dialog/Dialog.svelte.d.ts +29 -0
  113. package/dist/data-ui/fragments/dialog/dialog.svelte.d.ts +27 -0
  114. package/dist/data-ui/fragments/dialog/dialog.svelte.js +41 -0
  115. package/dist/data-ui/fragments/index.d.ts +11 -0
  116. package/dist/data-ui/fragments/index.js +11 -0
  117. package/dist/data-ui/utils/__tests__/HostProbe.svelte +18 -0
  118. package/dist/data-ui/utils/__tests__/HostProbe.svelte.d.ts +8 -0
  119. package/dist/data-ui/utils/data-utils.d.ts +29 -0
  120. package/dist/data-ui/utils/data-utils.js +83 -0
  121. package/dist/data-ui/utils/dataRelationUtils.d.ts +37 -0
  122. package/dist/data-ui/utils/dataRelationUtils.js +125 -0
  123. package/dist/data-ui/utils/diagramUtils.d.ts +6 -0
  124. package/dist/data-ui/utils/diagramUtils.js +131 -0
  125. package/dist/data-ui/utils/draggable.d.ts +15 -0
  126. package/dist/data-ui/utils/draggable.js +61 -0
  127. package/dist/data-ui/utils/menuPrefs.d.ts +80 -0
  128. package/dist/data-ui/utils/menuPrefs.js +119 -0
  129. package/dist/data-ui/utils/useMachinePrefs.svelte.d.ts +38 -0
  130. package/dist/data-ui/utils/useMachinePrefs.svelte.js +117 -0
  131. package/dist/data-ui/utils/useMenuTree.svelte.d.ts +26 -0
  132. package/dist/data-ui/utils/useMenuTree.svelte.js +68 -0
  133. package/dist/data-ui/utils/useRecordData.svelte.d.ts +22 -0
  134. package/dist/data-ui/utils/useRecordData.svelte.js +50 -0
  135. package/dist/data-ui/utils/useViewFields.svelte.d.ts +22 -0
  136. package/dist/data-ui/utils/useViewFields.svelte.js +59 -0
  137. package/dist/demo/.gitkeep +0 -0
  138. package/dist/demo/demo-status.json +9 -0
  139. package/dist/idae/boot.d.ts +28 -0
  140. package/dist/idae/boot.js +43 -0
  141. package/dist/idae/bridge/register.d.ts +4 -0
  142. package/dist/idae/bridge/register.js +15 -0
  143. package/dist/idae/capabilities/Capabilities.d.ts +10 -0
  144. package/dist/idae/capabilities/Capabilities.js +34 -0
  145. package/dist/idae/codefield/CodeFieldConvention.d.ts +3 -0
  146. package/dist/idae/codefield/CodeFieldConvention.js +25 -0
  147. package/dist/idae/fieldcatalog/defaultFieldTypesDef.d.ts +2 -0
  148. package/dist/idae/fieldcatalog/defaultFieldTypesDef.js +104 -0
  149. package/dist/idae/frames/FrameCatalog.d.ts +31 -0
  150. package/dist/idae/frames/FrameCatalog.js +31 -0
  151. package/dist/idae/index.d.ts +14 -0
  152. package/dist/idae/index.js +13 -0
  153. package/dist/idae/menu/IdaeMenuManager.d.ts +79 -0
  154. package/dist/idae/menu/IdaeMenuManager.js +108 -0
  155. package/dist/idae/menu/IdaeMenuStore.d.ts +77 -0
  156. package/dist/idae/menu/IdaeMenuStore.js +68 -0
  157. package/dist/idae/menu/menuSnapshot.d.ts +30 -0
  158. package/dist/idae/menu/menuSnapshot.js +30 -0
  159. package/dist/idae/meta/MetaModelProvider.d.ts +11 -0
  160. package/dist/idae/meta/MetaModelProvider.js +43 -0
  161. package/dist/idae/relations/RelationPolicy.d.ts +19 -0
  162. package/dist/idae/relations/RelationPolicy.js +125 -0
  163. package/dist/idae/rights/RightsPolicy.d.ts +16 -0
  164. package/dist/idae/rights/RightsPolicy.js +80 -0
  165. package/dist/idae/userscope/UserScopePolicy.d.ts +9 -0
  166. package/dist/idae/userscope/UserScopePolicy.js +42 -0
  167. package/dist/idae/userscope/navTracking.d.ts +11 -0
  168. package/dist/idae/userscope/navTracking.js +15 -0
  169. package/dist/index.d.ts +68 -35
  170. package/dist/index.js +82 -36
  171. package/dist/main/__tests__/_relationTestUtils.d.ts +12 -0
  172. package/dist/main/__tests__/_relationTestUtils.js +53 -0
  173. package/dist/main/__tests__/helpers/mockCollection.d.ts +21 -0
  174. package/dist/main/__tests__/helpers/mockCollection.js +27 -0
  175. package/dist/main/api/types.d.ts +29 -0
  176. package/dist/main/ext/hooks.d.ts +32 -0
  177. package/dist/main/ext/hooks.js +31 -0
  178. package/dist/main/ext/interfaces.d.ts +69 -0
  179. package/dist/main/ext/interfaces.js +3 -0
  180. package/dist/main/ext/registry.d.ts +29 -0
  181. package/dist/main/ext/registry.js +30 -0
  182. package/dist/main/frame/MachineFrameManager.d.ts +187 -0
  183. package/dist/main/frame/MachineFrameManager.js +403 -0
  184. package/dist/main/frame/contextMenuSetup.d.ts +9 -0
  185. package/dist/main/frame/contextMenuSetup.js +42 -0
  186. package/dist/main/frame/frameUrl.d.ts +1 -0
  187. package/dist/main/frame/frameUrl.js +8 -0
  188. package/dist/main/frame/frameUtils.d.ts +16 -0
  189. package/dist/main/frame/frameUtils.js +26 -0
  190. package/dist/main/frame/linkParser.d.ts +9 -0
  191. package/dist/main/frame/linkParser.js +15 -0
  192. package/dist/main/index.d.ts +15 -0
  193. package/dist/main/index.js +19 -0
  194. package/dist/main/machine/MachineAction.d.ts +62 -0
  195. package/dist/main/machine/MachineAction.js +96 -0
  196. package/dist/main/machine/MachineError.js +2 -2
  197. package/dist/main/machine/MachineFieldType.d.ts +25 -6
  198. package/dist/main/machine/MachineFieldType.js +118 -27
  199. package/dist/main/machine/MachineFkFold.d.ts +34 -0
  200. package/dist/main/machine/MachineFkFold.js +57 -0
  201. package/dist/main/machine/MachineRecordIdentity.d.ts +26 -0
  202. package/dist/main/machine/MachineRecordIdentity.js +44 -0
  203. package/dist/main/machine/MachineRights.d.ts +50 -0
  204. package/dist/main/machine/MachineRights.js +133 -0
  205. package/dist/main/machine/MachineRouter.d.ts +56 -0
  206. package/dist/main/machine/MachineRouter.js +250 -0
  207. package/dist/main/machine/MachineScheme.d.ts +40 -70
  208. package/dist/main/machine/MachineScheme.js +107 -94
  209. package/dist/main/machine/MachineSchemeField.js +32 -16
  210. package/dist/main/machine/MachineSchemeFieldForge.d.ts +11 -11
  211. package/dist/main/machine/MachineSchemeFieldForge.js +33 -21
  212. package/dist/main/machine/MachineSchemeFieldValues.d.ts +8 -9
  213. package/dist/main/machine/MachineSchemeFieldValues.js +12 -9
  214. package/dist/main/machine/MachineSchemeValidate.d.ts +69 -13
  215. package/dist/main/machine/MachineSchemeValidate.js +173 -46
  216. package/dist/main/machine/MachineSchemeValues.d.ts +32 -21
  217. package/dist/main/machine/MachineSchemeValues.js +132 -104
  218. package/dist/main/machine/SchemeFieldDefaultValues.d.ts +4 -2
  219. package/dist/main/machine/SchemeFieldDefaultValues.js +8 -2
  220. package/dist/main/machine/authState.svelte.d.ts +11 -0
  221. package/dist/main/machine/authState.svelte.js +17 -0
  222. package/dist/main/machine/fieldBuilder.d.ts +23 -0
  223. package/dist/main/machine/fieldBuilder.d.ts.map +1 -0
  224. package/dist/main/machine/fieldBuilder.js +10 -0
  225. package/dist/main/machine/fieldBuilder.js.map +1 -0
  226. package/dist/main/machine/machineLabel.d.ts +11 -0
  227. package/dist/main/machine/machineLabel.js +23 -0
  228. package/dist/main/machine/validateRules.d.ts +38 -0
  229. package/dist/main/machine/validateRules.js +109 -0
  230. package/dist/main/machine.d.ts +207 -68
  231. package/dist/main/machine.js +482 -96
  232. package/dist/main/machineDb.d.ts +21 -8
  233. package/dist/main/machineDb.js +33 -4
  234. package/dist/main/machineIdbAdapter.d.ts +83 -0
  235. package/dist/main/machineIdbAdapter.js +347 -0
  236. package/dist/main/machineModelBuilder.d.ts +31 -0
  237. package/dist/main/machineModelBuilder.js +58 -0
  238. package/dist/main/machineParserForge.d.ts +9 -18
  239. package/dist/main/machineParserForge.js +92 -35
  240. package/dist/main/machineSchemaCache.d.ts +8 -0
  241. package/dist/main/machineSchemaCache.js +58 -0
  242. package/dist/main/machineSchemaDoctor.d.ts +17 -0
  243. package/dist/main/machineSchemaDoctor.js +73 -0
  244. package/dist/main/machineSchemaLoader.d.ts +18 -0
  245. package/dist/main/machineSchemaLoader.js +43 -0
  246. package/dist/main/machineSeed.d.ts +21 -0
  247. package/dist/main/machineSeed.js +44 -0
  248. package/dist/main/router/componentRegistry.d.ts +35 -0
  249. package/dist/main/router/componentRegistry.js +35 -0
  250. package/dist/main/router/urlParser.d.ts +17 -0
  251. package/dist/main/router/urlParser.js +41 -0
  252. package/dist/main/warmupUtils.d.ts +40 -0
  253. package/dist/main/warmupUtils.js +73 -0
  254. package/dist/mcp/MachineMcpClient.d.ts +43 -0
  255. package/dist/mcp/MachineMcpClient.js +175 -0
  256. package/dist/shell/Frame.svelte +67 -0
  257. package/dist/shell/Frame.svelte.d.ts +11 -0
  258. package/dist/shell/auth/Login.svelte +244 -0
  259. package/dist/shell/auth/Login.svelte.d.ts +3 -0
  260. package/dist/shell/frame/dashboard/Dashboard.svelte +0 -0
  261. package/dist/shell/frame/dashboard/Dashboard.svelte.d.ts +26 -0
  262. package/dist/shell/frame/diagram/Diagram.svelte +244 -0
  263. package/dist/shell/frame/diagram/Diagram.svelte.d.ts +9 -0
  264. package/dist/shell/frame/explorer/Explorer.svelte +86 -0
  265. package/dist/shell/frame/explorer/Explorer.svelte.d.ts +29 -0
  266. package/dist/shell/frame/explorer/ExplorerContent.svelte +126 -0
  267. package/dist/shell/frame/explorer/ExplorerContent.svelte.d.ts +32 -0
  268. package/dist/shell/frame/index.d.ts +8 -0
  269. package/dist/shell/frame/index.js +9 -0
  270. package/dist/shell/frame/main-menu-content/MainMenuContent.svelte +100 -0
  271. package/dist/shell/frame/main-menu-content/MainMenuContent.svelte.d.ts +6 -0
  272. package/dist/shell/frame/planning/Planning.svelte +426 -0
  273. package/dist/shell/frame/planning/Planning.svelte.d.ts +12 -0
  274. package/dist/shell/frame/rbac/RbacMatrix.svelte +197 -0
  275. package/dist/shell/frame/rbac/RbacMatrix.svelte.d.ts +7 -0
  276. package/dist/shell/frame/space/Space.svelte +554 -0
  277. package/dist/shell/frame/space/Space.svelte.d.ts +8 -0
  278. package/dist/shell/frame/synthesis/Synthesis.svelte +383 -0
  279. package/dist/shell/frame/synthesis/Synthesis.svelte.d.ts +8 -0
  280. package/dist/shell/frame/today/Today.svelte +174 -0
  281. package/dist/shell/frame/today/Today.svelte.d.ts +3 -0
  282. package/dist/shell/layout/App.svelte +30 -0
  283. package/dist/shell/layout/App.svelte.d.ts +3 -0
  284. package/dist/shell/layout/Breadcrumb.svelte +67 -0
  285. package/dist/shell/layout/Breadcrumb.svelte.d.ts +12 -0
  286. package/dist/shell/layout/Columner.svelte +214 -0
  287. package/dist/shell/layout/Columner.svelte.d.ts +16 -0
  288. package/dist/shell/layout/DevResetPanel.svelte +194 -0
  289. package/dist/shell/layout/DevResetPanel.svelte.d.ts +7 -0
  290. package/dist/shell/layout/Fiche.svelte +111 -0
  291. package/dist/shell/layout/Fiche.svelte.d.ts +7 -0
  292. package/dist/shell/layout/FicheUpdate.svelte +53 -0
  293. package/dist/shell/layout/FicheUpdate.svelte.d.ts +7 -0
  294. package/dist/shell/layout/MainMenu.svelte +256 -0
  295. package/dist/shell/layout/MainMenu.svelte.d.ts +6 -0
  296. package/dist/shell/layout/MenuSettings.svelte +182 -0
  297. package/dist/shell/layout/MenuSettings.svelte.d.ts +6 -0
  298. package/dist/shell/layout/RecordTimeline.svelte +199 -0
  299. package/dist/shell/layout/RecordTimeline.svelte.d.ts +8 -0
  300. package/dist/shell/layout/RecordToolbar.svelte +39 -0
  301. package/dist/shell/layout/RecordToolbar.svelte.d.ts +7 -0
  302. package/dist/shell/layout/TaskBar.svelte +118 -0
  303. package/dist/shell/layout/TaskBar.svelte.d.ts +7 -0
  304. package/dist/shell/layout/TemplateShell.svelte +48 -0
  305. package/dist/shell/layout/TemplateShell.svelte.d.ts +15 -0
  306. package/dist/shell/layout/ThemeToggle.svelte +46 -0
  307. package/dist/shell/layout/ThemeToggle.svelte.d.ts +3 -0
  308. package/dist/shell/layout/index.d.ts +8 -0
  309. package/dist/shell/layout/index.js +9 -0
  310. package/dist/storage/ApiStorageAdapter.d.ts +41 -0
  311. package/dist/storage/ApiStorageAdapter.js +111 -0
  312. package/dist/storage/IdbStorageAdapter.d.ts +31 -0
  313. package/dist/storage/IdbStorageAdapter.js +72 -0
  314. package/dist/storage/MemoryStorageAdapter.d.ts +33 -0
  315. package/dist/storage/MemoryStorageAdapter.js +132 -0
  316. package/dist/storage/README.md +222 -0
  317. package/dist/storage/StorageAdapter.d.ts +75 -0
  318. package/dist/storage/StorageAdapter.js +7 -0
  319. package/dist/storage/demo/storage-demo.d.ts +22 -0
  320. package/dist/storage/demo/storage-demo.js +107 -0
  321. package/dist/storage/index.d.ts +9 -0
  322. package/dist/storage/index.js +9 -0
  323. package/dist/types/entity-types.d.ts +444 -0
  324. package/dist/types/entity-types.js +16 -0
  325. package/dist/types/index.d.ts +7 -0
  326. package/dist/types/index.js +6 -0
  327. package/dist/types/machine-model.d.ts +198 -0
  328. package/dist/types/machine-model.js +5 -0
  329. package/dist/types/qoolie-svelte.d.ts +11 -0
  330. package/dist/types/schema-utils.d.ts +32 -0
  331. package/dist/types/schema-utils.js +103 -0
  332. package/dist/utils/generateCode.d.ts +5 -0
  333. package/dist/utils/generateCode.js +9 -0
  334. package/dist/utils/logger.d.ts +10 -0
  335. package/dist/utils/logger.js +20 -0
  336. package/package.json +59 -33
  337. package/cli.js +0 -46
  338. package/dist/db/CrudService.d.ts +0 -9
  339. package/dist/db/CrudService.js +0 -45
  340. package/dist/demo/dbSchema.d.ts +0 -446
  341. package/dist/demo/dbSchema.js +0 -449
  342. package/dist/demo/testScheme.d.ts +0 -56
  343. package/dist/demo/testScheme.js +0 -42
  344. package/dist/form/CreateUpdate.svelte +0 -219
  345. package/dist/form/CreateUpdate.svelte.d.ts +0 -27
  346. package/dist/form/DataProvider.svelte +0 -23
  347. package/dist/form/DataProvider.svelte.d.ts +0 -7
  348. package/dist/form/FieldValue.svelte +0 -148
  349. package/dist/form/FieldValue.svelte.d.ts +0 -34
  350. package/dist/form/types.d.ts +0 -17
  351. package/dist/fragments/Confirm.svelte +0 -73
  352. package/dist/fragments/Confirm.svelte.d.ts +0 -7
  353. package/dist/fragments/Frame.svelte +0 -19
  354. package/dist/fragments/Frame.svelte.d.ts +0 -32
  355. package/dist/fragments/InfoLine.svelte +0 -21
  356. package/dist/fragments/InfoLine.svelte.d.ts +0 -35
  357. package/dist/fragments/Selector.svelte +0 -26
  358. package/dist/fragments/Selector.svelte.d.ts +0 -38
  359. package/dist/main/machine/MachineSchemeField.d.ts +0 -19
  360. package/dist/types/appschemeTypes.d.ts +0 -71
  361. package/dist/types/appschemeTypes.js +0 -83
  362. package/dist/ui/CollectionButton.svelte +0 -29
  363. package/dist/ui/CollectionButton.svelte.d.ts +0 -29
  364. package/dist/ui/CollectionFks.svelte +0 -24
  365. package/dist/ui/CollectionFks.svelte.d.ts +0 -9
  366. package/dist/ui/CollectionList.svelte +0 -100
  367. package/dist/ui/CollectionList.svelte.d.ts +0 -36
  368. package/dist/ui/CollectionListFieldValues.svelte +0 -59
  369. package/dist/ui/CollectionListFieldValues.svelte.d.ts +0 -9
  370. package/dist/ui/CollectionListMenu.svelte +0 -39
  371. package/dist/ui/CollectionListMenu.svelte.d.ts +0 -34
  372. package/dist/ui/CollectionReverseFks.svelte +0 -37
  373. package/dist/ui/CollectionReverseFks.svelte.d.ts +0 -14
  374. /package/dist/{fragments → data-ui/fragments}/Skeleton.svelte.d.ts +0 -0
  375. /package/dist/{form → main/api}/types.js +0 -0
@@ -1,6 +1,7 @@
1
- import type { IdbqModel, TplCollectionName } from "@medyll/idae-idbql";
2
- import { MachineScheme } from "./machine/MachineScheme.js";
3
- import { MachineParserForge } from "./machineParserForge.js";
1
+ import type { TplCollectionName } from '../types/index.js';
2
+ import type { MachineModel } from '../types/index.js';
3
+ import { MachineScheme } from './machine/MachineScheme.js';
4
+ import { MachineParserForge } from './machineParserForge.js';
4
5
  /**
5
6
  * @class MachineDb
6
7
  * @role Central class for parsing, introspecting, and extracting metadata from the database schema. Provides methods to access collections, templates, fields, foreign keys, and type information. Used for dynamic UI generation, validation, and schema-driven logic.
@@ -10,19 +11,31 @@ export declare class MachineDb {
10
11
  /**
11
12
  * The database model (schema) used for introspection.
12
13
  */
13
- model: IdbqModel;
14
+ model: MachineModel;
14
15
  machineForge: MachineParserForge;
15
16
  /**
16
17
  * Create a new MachineDb instance.
17
18
  * @role Constructor
18
- * @param {IdbqModel} model Custom model to use.
19
+ * @param {IdbqModel} model Custom model to use (typically from buildEffectiveModel).
19
20
  */
20
- constructor(model: IdbqModel);
21
+ constructor(model: MachineModel);
22
+ /**
23
+ * List all collections defined in the model as MachineScheme instances.
24
+ * @role Schema introspection
25
+ * @return {MachineScheme[]} A list of MachineScheme instances.
26
+ */
27
+ collections(): MachineScheme[];
21
28
  /**
22
29
  * Get an IDbCollection instance for a collection name.
23
30
  * @role Collection accessor
24
31
  * @param {TplCollectionName} collection The collection name.
25
- * @return {MachineScheme} The IDbCollection instance.
32
+ * @return {MachineScheme | null} The IDbCollection instance, or null when unknown to the model.
33
+ */
34
+ collection(collection: TplCollectionName): MachineScheme | null;
35
+ /**
36
+ * Return all unique `base` module names declared in the model.
37
+ * Used by the server to know which MongoDB databases to create.
38
+ * e.g. ['machine_base', 'machine_app']
26
39
  */
27
- collection(collection: TplCollectionName): MachineScheme;
40
+ getBaseModules(): string[];
28
41
  }
@@ -1,5 +1,5 @@
1
- import { MachineScheme } from "./machine/MachineScheme.js";
2
- import { MachineParserForge } from "./machineParserForge.js";
1
+ import { MachineScheme } from './machine/MachineScheme.js';
2
+ import { MachineParserForge } from './machineParserForge.js';
3
3
  /**
4
4
  * @class MachineDb
5
5
  * @role Central class for parsing, introspecting, and extracting metadata from the database schema. Provides methods to access collections, templates, fields, foreign keys, and type information. Used for dynamic UI generation, validation, and schema-driven logic.
@@ -14,22 +14,51 @@ export class MachineDb {
14
14
  /**
15
15
  * Create a new MachineDb instance.
16
16
  * @role Constructor
17
- * @param {IdbqModel} model Custom model to use.
17
+ * @param {IdbqModel} model Custom model to use (typically from buildEffectiveModel).
18
18
  */
19
19
  constructor(model) {
20
20
  this.model = model;
21
21
  this.machineForge = new MachineParserForge();
22
22
  }
23
+ /**
24
+ * List all collections defined in the model as MachineScheme instances.
25
+ * @role Schema introspection
26
+ * @return {MachineScheme[]} A list of MachineScheme instances.
27
+ */
28
+ collections() {
29
+ const list = [];
30
+ for (const name of Object.keys(this.model)) {
31
+ // Model keys are guaranteed present, so collection() always resolves.
32
+ list.push(this.collection(name));
33
+ }
34
+ return list;
35
+ }
23
36
  /**
24
37
  * Get an IDbCollection instance for a collection name.
25
38
  * @role Collection accessor
26
39
  * @param {TplCollectionName} collection The collection name.
27
- * @return {MachineScheme} The IDbCollection instance.
40
+ * @return {MachineScheme | null} The IDbCollection instance, or null when unknown to the model.
28
41
  */
29
42
  collection(collection) {
43
+ if (!this.model[String(collection)])
44
+ return null;
30
45
  if (!this.#idbCollectionsList[collection]) {
31
46
  this.#idbCollectionsList[collection] = new MachineScheme(collection, this, this.model);
32
47
  }
33
48
  return this.#idbCollectionsList[collection];
34
49
  }
50
+ /**
51
+ * Return all unique `base` module names declared in the model.
52
+ * Used by the server to know which MongoDB databases to create.
53
+ * e.g. ['machine_base', 'machine_app']
54
+ */
55
+ getBaseModules() {
56
+ const bases = new Set();
57
+ for (const col of Object.values(this.model)) {
58
+ const base = col.base;
59
+ if (base)
60
+ bases.add(base);
61
+ }
62
+ return [...bases];
63
+ }
35
64
  }
@@ -0,0 +1,83 @@
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
+ import type { MachineModel } from '../types/index.js';
17
+ export interface PendingIdbUpgrade {
18
+ toCreate: string[];
19
+ toDelete: string[];
20
+ expectedHash: string;
21
+ newVersion: number;
22
+ }
23
+ /** True for internal stores that must never be deleted. */
24
+ export declare function isProtectedStore(name: string): boolean;
25
+ /**
26
+ * Translate a Dexie-style keyPath config ('++id', 'id', '&code', 'a, b, ++id')
27
+ * into native createObjectStore options. Mirrors qoolie's IdbSchema.createSchema:
28
+ * native IDB rejects '++id' ("keyPath is not a valid key path") — the '++' prefix
29
+ * means autoIncrement on the bare field name.
30
+ */
31
+ export declare function nativeStoreOptions(config: string | null | undefined): IDBObjectStoreParameters;
32
+ /**
33
+ * Detect drift between expected schema and actual IDB stores.
34
+ * Returns PendingIdbUpgrade (with bumped version) if drift found, null if schema is current.
35
+ */
36
+ export declare function detectSchemaDrift(dbName: string, version: number, effectiveModel: MachineModel): Promise<PendingIdbUpgrade | null>;
37
+ /**
38
+ * Perform IDB schema upgrade: handle store renames and deletions.
39
+ * Called after detectSchemaDrift() returned a pending upgrade.
40
+ *
41
+ * Qoolie now handles all store creation (including __schema_meta__) in its onupgradeneeded handler.
42
+ * This method only handles:
43
+ * - Store renames: copies data from old → new store when keyPath matches
44
+ * - Store deletions: removes orphaned stores (excluding protected stores)
45
+ * - Store creation: only for stores not created by Qoolie (fallback)
46
+ *
47
+ * Edge cases handled:
48
+ * - __outbox__ / internal stores: never deleted
49
+ * - Rename detection: copies data from old → new store when keyPath matches
50
+ */
51
+ export declare function performIdbUpgrade(dbName: string, version: number, upgrade: PendingIdbUpgrade, effectiveModel: MachineModel): Promise<void>;
52
+ /**
53
+ * Deterministic hash of expected store names — sorted join, order-independent.
54
+ */
55
+ export declare function computeSchemaHash(storeNames: string[]): string;
56
+ /**
57
+ * Opens IDB briefly to read actual object store names.
58
+ * Excludes internal stores (__outbox__, __schema_meta__, __migrations__).
59
+ * Returns empty Set if database doesn't exist (to avoid creating it with no-version open).
60
+ */
61
+ export declare function getCurrentIdbStores(dbName: string): Promise<Set<string>>;
62
+ /**
63
+ * Returns the actual current version of the IDB database, or 0 if it doesn't exist.
64
+ * Used to prevent version downgrade when re-opening after a drift-triggered increment.
65
+ * Returns 0 if database doesn't exist (to avoid creating it with no-version open).
66
+ */
67
+ export declare function getActualIdbVersion(dbName: string): Promise<number>;
68
+ /**
69
+ * Read the persisted schema hash from __schema_meta__ store.
70
+ * Returns null if the store doesn't exist or no hash is stored.
71
+ * Returns null if database doesn't exist (to avoid creating it with no-version open).
72
+ */
73
+ export declare function getStoredSchemaHash(dbName: string): Promise<string | null>;
74
+ /**
75
+ * Persist the schema hash into __schema_meta__ store.
76
+ * Auto-creates the store if it doesn't exist (requires version bump via upgradeIdb).
77
+ */
78
+ export declare function storeSchemaHash(dbName: string, hash: string): Promise<void>;
79
+ /**
80
+ * Delete an IDB database entirely — dev tool, irreversible.
81
+ * Does NOT reload the page — caller decides.
82
+ */
83
+ export declare function deleteIdbDatabase(dbName: string): Promise<void>;
@@ -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
+ }