@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,341 @@
1
+ /**
2
+ * Enum of default field types supported by the system.
3
+ * @role field-type-enum
4
+ */
5
+ export var defaultTypes;
6
+ (function (defaultTypes) {
7
+ defaultTypes["id"] = "id";
8
+ defaultTypes["any"] = "any";
9
+ defaultTypes["date"] = "date";
10
+ defaultTypes["datetime"] = "datetime";
11
+ defaultTypes["time"] = "time";
12
+ defaultTypes["text"] = "text";
13
+ defaultTypes["number"] = "number";
14
+ defaultTypes["boolean"] = "boolean";
15
+ defaultTypes["url"] = "url";
16
+ defaultTypes["email"] = "email";
17
+ defaultTypes["phone"] = "phone";
18
+ defaultTypes["password"] = "password";
19
+ defaultTypes["file"] = "file";
20
+ defaultTypes["image"] = "image";
21
+ defaultTypes["icon"] = "icon";
22
+ defaultTypes["color"] = "color";
23
+ })(defaultTypes || (defaultTypes = {}));
24
+ const timePattern = /^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/;
25
+ function isBooleanLike(value) {
26
+ return typeof value === 'boolean' || value === 'true' || value === 'false';
27
+ }
28
+ function formatBoolean(value) {
29
+ if (value === 'true')
30
+ return true;
31
+ if (value === 'false')
32
+ return false;
33
+ return Boolean(value);
34
+ }
35
+ function isValidTimeValue(value) {
36
+ if (value instanceof Date) {
37
+ return !isNaN(value.getTime());
38
+ }
39
+ return timePattern.test(String(value));
40
+ }
41
+ /**
42
+ * Registry of default field types.
43
+ */
44
+ export const defaultFieldTypesDef = {
45
+ id: {
46
+ id: defaultTypes.id,
47
+ formatter: (value) => String(value),
48
+ validator: (value) => true
49
+ },
50
+ password: {
51
+ id: defaultTypes.password,
52
+ formatter: (value) => String(value),
53
+ validator: (value) => true
54
+ },
55
+ file: {
56
+ id: defaultTypes.file,
57
+ formatter: (value) => String(value),
58
+ validator: (value) => true
59
+ },
60
+ image: {
61
+ id: defaultTypes.image,
62
+ formatter: (value) => String(value),
63
+ validator: (value) => true
64
+ },
65
+ email: {
66
+ id: defaultTypes.email,
67
+ formatter: (value) => String(value).toLowerCase(),
68
+ validator: (value) => {
69
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
70
+ return emailRegex.test(String(value).toLowerCase());
71
+ }
72
+ },
73
+ url: {
74
+ id: defaultTypes.url,
75
+ formatter: (value) => String(value).toLowerCase(),
76
+ validator: (value) => {
77
+ try {
78
+ new URL(String(value).toLowerCase());
79
+ return true;
80
+ }
81
+ catch {
82
+ return false;
83
+ }
84
+ }
85
+ },
86
+ phone: {
87
+ id: defaultTypes.phone,
88
+ formatter: (value) => String(value),
89
+ validator: (value) => {
90
+ const phoneRegex = /^\+?[\d\s-]{10,}$/;
91
+ return phoneRegex.test(String(value));
92
+ }
93
+ },
94
+ date: {
95
+ id: defaultTypes.date,
96
+ formatter: (value) => {
97
+ const d = new Date(value);
98
+ return isNaN(d.getTime()) ? String(value) : d.toLocaleDateString();
99
+ },
100
+ validator: (value) => {
101
+ const date = new Date(String(value));
102
+ return !isNaN(date.getTime());
103
+ }
104
+ },
105
+ datetime: {
106
+ id: defaultTypes.datetime,
107
+ formatter: (value) => {
108
+ const d = new Date(value);
109
+ return isNaN(d.getTime()) ? String(value) : d.toLocaleString();
110
+ },
111
+ validator: (value) => {
112
+ const date = new Date(String(value));
113
+ return !isNaN(date.getTime());
114
+ }
115
+ },
116
+ time: {
117
+ id: defaultTypes.time,
118
+ formatter: (value) => {
119
+ const d = new Date(`1970-01-01T${value}`);
120
+ return isNaN(d.getTime()) ? String(value) : d.toLocaleTimeString();
121
+ },
122
+ validator: (value) => isValidTimeValue(value)
123
+ },
124
+ text: {
125
+ id: defaultTypes.text,
126
+ formatter: (value) => String(value),
127
+ validator: (value) => true
128
+ },
129
+ // T-shirt size presets
130
+ 'text-xs': { id: 'text-xs', formatter: (v) => String(v ?? '').substring(0, 10), validator: () => true },
131
+ 'text-sm': { id: 'text-sm', formatter: (v) => String(v ?? '').substring(0, 20), validator: () => true },
132
+ 'text-md': { id: 'text-md', formatter: (v) => String(v ?? '').substring(0, 30), validator: () => true },
133
+ 'text-lg': { id: 'text-lg', formatter: (v) => String(v ?? '').substring(0, 40), validator: () => true },
134
+ 'text-xl': { id: 'text-xl', formatter: (v) => String(v ?? '').substring(0, 50), validator: () => true },
135
+ 'text-full': { id: 'text-full', formatter: (v) => String(v ?? ''), validator: () => true },
136
+ 'text-area': { id: 'text-area', formatter: (v) => String(v ?? ''), validator: () => true },
137
+ // Deprecated aliases — kept for backward compat
138
+ 'text-tiny': { id: 'text-tiny', formatter: (v) => String(v ?? '').substring(0, 10), validator: () => true },
139
+ 'text-short': { id: 'text-short', formatter: (v) => String(v ?? '').substring(0, 20), validator: () => true },
140
+ 'text-medium': { id: 'text-medium', formatter: (v) => String(v ?? '').substring(0, 30), validator: () => true },
141
+ 'text-long': { id: 'text-long', formatter: (v) => String(v ?? '').substring(0, 40), validator: () => true },
142
+ 'text-giant': { id: 'text-giant', formatter: (v) => String(v ?? '').substring(0, 50), validator: () => true },
143
+ number: {
144
+ id: defaultTypes.number,
145
+ formatter: (value) => Number(value),
146
+ validator: (value) => typeof value === 'number' && !isNaN(value)
147
+ },
148
+ boolean: {
149
+ id: defaultTypes.boolean,
150
+ formatter: (value) => formatBoolean(value),
151
+ validator: (value) => isBooleanLike(value)
152
+ },
153
+ currency: {
154
+ id: 'currency',
155
+ formatter: (value) => {
156
+ const n = Number(value);
157
+ if (isNaN(n))
158
+ return String(value);
159
+ return new Intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(n);
160
+ },
161
+ validator: (value) => !isNaN(Number(value))
162
+ },
163
+ any: {
164
+ id: defaultTypes.any,
165
+ formatter: (value) => value,
166
+ validator: (value) => true
167
+ },
168
+ icon: {
169
+ id: defaultTypes.icon,
170
+ formatter: (value) => String(value ?? ''),
171
+ validator: (value) => true
172
+ },
173
+ color: {
174
+ id: defaultTypes.color,
175
+ formatter: (value) => String(value ?? ''),
176
+ validator: (value) => /^#[0-9a-fA-F]{3,8}$/.test(String(value))
177
+ },
178
+ schemelink: {
179
+ id: 'schemelink',
180
+ formatter: (value) => {
181
+ if (value == null)
182
+ return '';
183
+ const link = value;
184
+ const col = link.collection ?? '?';
185
+ const val = link.collection_value != null ? String(link.collection_value) : '?';
186
+ return `${col}#${val}`;
187
+ },
188
+ validator: (value) => {
189
+ if (value == null)
190
+ return true;
191
+ if (typeof value !== 'object')
192
+ return false;
193
+ const link = value;
194
+ return typeof link.collection === 'string' && link.collection.length > 0
195
+ && link.collection_value !== undefined;
196
+ }
197
+ }
198
+ };
199
+ /**
200
+ * @role field-type-registry
201
+ * Singleton registry for all field types (formatters, validators).
202
+ *
203
+ * Usage:
204
+ * import { MachineSchemeFieldType } from "./MachineFieldType";
205
+ * MachineSchemeFieldType.registerFieldType({ id: 'custom', formatter: v => v, validator: v => true });
206
+ * const isValid = MachineSchemeFieldType.validate('12.34', 'currency'); // true
207
+ *
208
+ * To override or extend types globally:
209
+ * MachineSchemeFieldType.registerFieldType({ id: 'mytype', formatter: ..., validator: ... });
210
+ *
211
+ * To get all types:
212
+ * MachineSchemeFieldType.getAllFieldTypes()
213
+ *
214
+ * Note: The class MachineFieldType is not exported. Use only the singleton MachineSchemeFieldType.
215
+ */
216
+ class MachineFieldType {
217
+ fieldTypeRegistry = {};
218
+ /**
219
+ * Initialize the registry with default field types and optional custom types.
220
+ */
221
+ constructor() { }
222
+ /**
223
+ * Initialize the registry with default and/or custom field types.
224
+ * Clears the registry before registering new types.
225
+ */
226
+ init(def) {
227
+ this.fieldTypeRegistry = {};
228
+ this.registerFieldTypes(def);
229
+ }
230
+ async validate(value, typeId, ctx) {
231
+ const fieldType = this.getFieldType(typeId);
232
+ if (!fieldType)
233
+ return false;
234
+ if (fieldType.validator) {
235
+ const res = fieldType.validator(value, ctx);
236
+ // Promise detection
237
+ if (res && typeof res?.then === 'function') {
238
+ return (await res);
239
+ }
240
+ return Boolean(res);
241
+ }
242
+ return true;
243
+ }
244
+ /**
245
+ * Register a custom field type.
246
+ * @param def Field type definition
247
+ */
248
+ registerFieldType(def) {
249
+ this.fieldTypeRegistry[def.id] = def;
250
+ }
251
+ /**
252
+ * Register multiple custom field types.
253
+ * @param defs Array of definitions
254
+ */
255
+ registerFieldTypes(defs) {
256
+ if (!defs)
257
+ return;
258
+ Object.keys(defs).forEach((key) => {
259
+ this.registerFieldType(defs[key]);
260
+ });
261
+ }
262
+ /**
263
+ * Unregister a field type by its id.
264
+ * @param id Type identifier to remove
265
+ * @returns true if removed, false if not found
266
+ */
267
+ unregister(id) {
268
+ if (this.fieldTypeRegistry[id]) {
269
+ delete this.fieldTypeRegistry[id];
270
+ return true;
271
+ }
272
+ return false;
273
+ }
274
+ /**
275
+ * Retrieve the definition of a field type by its id.
276
+ * @param id Type identifier
277
+ * @return Field type definition or undefined
278
+ */
279
+ getFieldType(id) {
280
+ return this.fieldTypeRegistry[id];
281
+ }
282
+ /**
283
+ * Return all registered field types.
284
+ */
285
+ getAllFieldTypes() {
286
+ return this.fieldTypeRegistry;
287
+ }
288
+ /**
289
+ * Update the validator function for a field type.
290
+ * @param id Type identifier
291
+ * @param validator New validator function
292
+ * @returns true if updated, false if type not found
293
+ */
294
+ setValidator(id, validator) {
295
+ const type = this.getFieldType(id);
296
+ if (type) {
297
+ type.validator = validator;
298
+ return true;
299
+ }
300
+ return false;
301
+ }
302
+ /**
303
+ * Format a value using the registered formatter for the given type id.
304
+ * Falls back to String(value) if type not found.
305
+ */
306
+ format(value, typeId) {
307
+ // Empty values render as empty, never the literal strings "null"/"undefined".
308
+ if (value === null || value === undefined)
309
+ return '';
310
+ const formatted = this.getFieldType(typeId)?.formatter(value);
311
+ return formatted !== undefined ? String(formatted) : String(value);
312
+ }
313
+ /**
314
+ * Update the formatter function for a field type.
315
+ * @param id Type identifier
316
+ * @param formatter New formatter function
317
+ * @returns true if updated, false if type not found
318
+ */
319
+ setFormatter(id, formatter) {
320
+ const type = this.getFieldType(id);
321
+ if (type) {
322
+ type.formatter = formatter;
323
+ return true;
324
+ }
325
+ return false;
326
+ }
327
+ }
328
+ /**
329
+ * Global singleton instance for all field type logic.
330
+ * Use this for all registration, validation, and lookup of field types.
331
+ *
332
+ * Example:
333
+ * MachineSchemeFieldType.registerFieldType({ id: 'custom', formatter: v => v, validator: v => true });
334
+ * const isValid = MachineSchemeFieldType.validate('foo', 'custom');
335
+ *
336
+ * The default catalogue (defaultFieldTypesDef) is auto-registered at module load.
337
+ * The domain layer (idae/fieldcatalog/) can re-init with an extended catalogue at boot.
338
+ */
339
+ export const MachineSchemeFieldType = new MachineFieldType();
340
+ MachineSchemeFieldType.init(defaultFieldTypesDef);
341
+ export default MachineSchemeFieldType;
@@ -0,0 +1,34 @@
1
+ import type { MachineFkDef } from '../../types/index.js';
2
+ /** Minimal schema bridge — avoids importing MachineDb (cycle risk). */
3
+ type FkSchemaBridge = {
4
+ collection(name: string): {
5
+ fks?: Record<string, MachineFkDef>;
6
+ } | null | undefined;
7
+ };
8
+ /** Minimal qoolie bridge — only the where() accessor is needed for FK resolution. */
9
+ type QoolieBridge = {
10
+ collection?: Record<string, {
11
+ where(q: Record<string, unknown>): unknown;
12
+ }>;
13
+ };
14
+ /**
15
+ * MachineFkFold
16
+ * Pure fold: given a record and a collection's `fks{}` block, denormalize a full
17
+ * snapshot of each FK target into `record.fks.<field>` (single) or
18
+ * `record.fks.<field>_<value>` (multiple) — the exact shape `resolvePresentationToken`
19
+ * and `DataField.readFkRaw` already consume for display.
20
+ *
21
+ * No I/O here: target resolution is injected via `resolveTarget`, mirroring
22
+ * `MachineSchemeValues.displayValue(resolveTarget)`.
23
+ */
24
+ export type FkTargetResolver = (fkCollection: string, fkIndexField: string, value: unknown) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
25
+ export declare function foldFksIntoRecord(fks: Record<string, MachineFkDef>, record: Record<string, unknown>, resolveTarget: FkTargetResolver): Promise<Record<string, unknown>>;
26
+ /**
27
+ * Wrap a QoolieCollection so create/update/updateWhere denormalize FK snapshots
28
+ * into `record.fks.<field>` before persisting. All other methods forward untouched.
29
+ *
30
+ * Extracted from machine.ts (#resolveFkTarget + #wrapCollectionFkFold).
31
+ * machine.collection() is the single call-site.
32
+ */
33
+ export declare function wrapCollectionFkFold<C extends object>(machineDb: FkSchemaBridge, qoolie: QoolieBridge, name: string, col: C): C;
34
+ export {};
@@ -0,0 +1,57 @@
1
+ import { foldFk } from '@medyll/qoolie';
2
+ import { getRelationResolver } from '../ext/hooks.js';
3
+ const FK_INDEX_FIELD = 'code';
4
+ export async function foldFksIntoRecord(fks, record, resolveTarget) {
5
+ if (!Object.keys(fks ?? {}).length)
6
+ return record;
7
+ const { data } = await foldFk(fks, record, resolveTarget, FK_INDEX_FIELD);
8
+ return data;
9
+ }
10
+ /**
11
+ * Wrap a QoolieCollection so create/update/updateWhere denormalize FK snapshots
12
+ * into `record.fks.<field>` before persisting. All other methods forward untouched.
13
+ *
14
+ * Extracted from machine.ts (#resolveFkTarget + #wrapCollectionFkFold).
15
+ * machine.collection() is the single call-site.
16
+ */
17
+ export function wrapCollectionFkFold(machineDb, qoolie, name, col) {
18
+ const resolver = getRelationResolver();
19
+ let fold;
20
+ if (resolver?.foldRelations) {
21
+ fold = (data) => resolver.foldRelations(name, data);
22
+ }
23
+ else {
24
+ // Fallback: inline fold when domain bridge not registered (tests, early boot)
25
+ const fks = machineDb.collection(name)?.fks ?? {};
26
+ if (!Object.keys(fks).length)
27
+ return col;
28
+ const resolveFkTarget = async (fkCollection, fkIndexField, value) => {
29
+ const targetCol = qoolie.collection?.[fkCollection];
30
+ if (!targetCol)
31
+ return undefined;
32
+ try {
33
+ const docs = await Promise.resolve(targetCol.where({ [fkIndexField]: value }));
34
+ return docs?.[0];
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ };
40
+ fold = (data) => foldFksIntoRecord(fks, data, resolveFkTarget);
41
+ }
42
+ const overrides = {
43
+ create: async (data) => col.create(await fold(data)),
44
+ update: async (id, data) => col.update(id, await fold(data)),
45
+ updateWhere: async (query, data) => col.updateWhere(query, await fold(data)),
46
+ };
47
+ // Proxy forwards every other method (where/get/getAll/…) to the real instance
48
+ // with correct `this` binding — spreading would silently drop prototype methods.
49
+ return new Proxy(col, {
50
+ get(target, prop, receiver) {
51
+ if (typeof prop === 'string' && prop in overrides)
52
+ return overrides[prop];
53
+ const val = Reflect.get(target, prop, receiver);
54
+ return typeof val === 'function' ? val.bind(target) : val;
55
+ },
56
+ });
57
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * MachineRecordIdentity
3
+ * Shared record-key normalization and matching.
4
+ *
5
+ * Problem: `collectionId` travels as a string through routing/frame state,
6
+ * but the IDB index may be numeric. `'42' !== 42` breaks store lookups.
7
+ * This module is the single place that resolves that mismatch.
8
+ */
9
+ export declare const MachineRecordIdentity: {
10
+ /**
11
+ * Normalize a raw key (string from URL/frame) to the canonical type.
12
+ * Returns a number when the value is a finite integer string, otherwise
13
+ * keeps it as a string. Returns undefined for null/undefined/empty.
14
+ */
15
+ readonly normalizeKey: (raw: unknown) => string | number | undefined;
16
+ /**
17
+ * Build a where-clause for machine.store() / collection.get().
18
+ * Returns null when raw is null/undefined (caller should skip the query).
19
+ */
20
+ readonly buildWhere: (indexName: string, raw: unknown) => Record<string, unknown> | null;
21
+ /**
22
+ * Check whether a record's index field matches a raw key.
23
+ * Compares by normalized value so '42' matches 42 and vice-versa.
24
+ */
25
+ readonly recordMatchesIndex: (record: Record<string, unknown>, indexName: string, raw: unknown) => boolean;
26
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * MachineRecordIdentity
3
+ * Shared record-key normalization and matching.
4
+ *
5
+ * Problem: `collectionId` travels as a string through routing/frame state,
6
+ * but the IDB index may be numeric. `'42' !== 42` breaks store lookups.
7
+ * This module is the single place that resolves that mismatch.
8
+ */
9
+ export const MachineRecordIdentity = {
10
+ /**
11
+ * Normalize a raw key (string from URL/frame) to the canonical type.
12
+ * Returns a number when the value is a finite integer string, otherwise
13
+ * keeps it as a string. Returns undefined for null/undefined/empty.
14
+ */
15
+ normalizeKey(raw) {
16
+ if (raw == null || raw === '')
17
+ return undefined;
18
+ const n = Number(raw);
19
+ if (Number.isFinite(n) && !Number.isNaN(n))
20
+ return n;
21
+ return String(raw);
22
+ },
23
+ /**
24
+ * Build a where-clause for machine.store() / collection.get().
25
+ * Returns null when raw is null/undefined (caller should skip the query).
26
+ */
27
+ buildWhere(indexName, raw) {
28
+ const key = MachineRecordIdentity.normalizeKey(raw);
29
+ if (key === undefined)
30
+ return null;
31
+ return { [indexName]: key };
32
+ },
33
+ /**
34
+ * Check whether a record's index field matches a raw key.
35
+ * Compares by normalized value so '42' matches 42 and vice-versa.
36
+ */
37
+ recordMatchesIndex(record, indexName, raw) {
38
+ const normalized = MachineRecordIdentity.normalizeKey(raw);
39
+ if (normalized === undefined)
40
+ return false;
41
+ const recordKey = MachineRecordIdentity.normalizeKey(record[indexName]);
42
+ return recordKey === normalized;
43
+ },
44
+ };
@@ -0,0 +1,50 @@
1
+ import type { AppUser, AppUserGrant, PermissionCode } from '../../types/entity-types.js';
2
+ import type { MachineModel, MachineRightsPolicy } from '../../types/index.js';
3
+ export declare class MachineRights {
4
+ #private;
5
+ /**
6
+ * Load structural rights policies from the MachineModel.
7
+ * Call once at Machine.boot() — after model is resolved.
8
+ */
9
+ setPolicies(policies: Record<string, MachineRightsPolicy>): void;
10
+ /** Extract and load rights policies directly from a MachineModel. */
11
+ loadPoliciesFromModel(model: MachineModel | undefined): void;
12
+ /**
13
+ * Enable auth and set the current user + their grants.
14
+ * Once called, open mode is disabled — all access goes through checkAccess().
15
+ */
16
+ setCurrentUser(user: AppUser | null, grants?: AppUserGrant[], menuBaseline?: Record<string, boolean>): void;
17
+ /** Disable auth and return to open mode (all access allowed). */
18
+ clearCurrentUser(): void;
19
+ get currentUser(): AppUser | null;
20
+ /**
21
+ * Role-derived menu visibility baseline (scopeKey → bool), resolved server-side at
22
+ * login by OR-ing the user's role presets. The menu reads `override ?? baseline ??
23
+ * false`; role codes are never exposed client-side — only this flat effect.
24
+ */
25
+ get menuBaseline(): Record<string, boolean>;
26
+ get isAuthEnabled(): boolean;
27
+ /**
28
+ * Check if the current user has access to perform `operation` on `collection`.
29
+ *
30
+ * Resolution order:
31
+ * 1. `ops` policy blocks the operation → deny (structural, absolute)
32
+ * 2. Auth not initialized → allow (open mode, dev/test)
33
+ * 3. `public` policy includes the operation → allow (no auth required)
34
+ * 4. No user → deny
35
+ * 5. User inactive or locked → deny
36
+ * 6. appPermissions.ADMIN → allow all (within ops)
37
+ * 7. Explicit grant (temporal + collection scoped) → respected
38
+ * 8. `default` policy includes the operation → allow (authenticated fallback)
39
+ * 9. Deny
40
+ */
41
+ checkAccess(collection: string, operation?: PermissionCode): boolean;
42
+ /**
43
+ * Enumerate all collections the current user has access to for the given operation.
44
+ * Returns an array of collection names where checkAccess(collection, op) returns true.
45
+ * Used by menu generators and UI components that need to filter collections by rights.
46
+ */
47
+ allowedCollections(operation?: PermissionCode): string[];
48
+ }
49
+ export declare const machineRights: MachineRights;
50
+ export default machineRights;
@@ -0,0 +1,133 @@
1
+ import { getGrantDecoder } from '../ext/hooks.js';
2
+ const ALL_OPS = ['C', 'R', 'U', 'D', 'L', 'X'];
3
+ export class MachineRights {
4
+ #currentUser = null;
5
+ #grants = [];
6
+ #menuBaseline = {};
7
+ #authEnabled = false;
8
+ #policies = {};
9
+ /**
10
+ * Load structural rights policies from the MachineModel.
11
+ * Call once at Machine.boot() — after model is resolved.
12
+ */
13
+ setPolicies(policies) {
14
+ this.#policies = policies;
15
+ }
16
+ /** Extract and load rights policies directly from a MachineModel. */
17
+ loadPoliciesFromModel(model) {
18
+ if (!model)
19
+ return;
20
+ const policies = {};
21
+ for (const [name, col] of Object.entries(model)) {
22
+ if ('rights' in col && col.rights)
23
+ policies[name] = col.rights;
24
+ }
25
+ this.setPolicies(policies);
26
+ }
27
+ /**
28
+ * Enable auth and set the current user + their grants.
29
+ * Once called, open mode is disabled — all access goes through checkAccess().
30
+ */
31
+ setCurrentUser(user, grants = [], menuBaseline = {}) {
32
+ this.#authEnabled = true;
33
+ this.#currentUser = user;
34
+ this.#grants = grants;
35
+ this.#menuBaseline = menuBaseline;
36
+ }
37
+ /** Disable auth and return to open mode (all access allowed). */
38
+ clearCurrentUser() {
39
+ this.#authEnabled = false;
40
+ this.#currentUser = null;
41
+ this.#grants = [];
42
+ this.#menuBaseline = {};
43
+ }
44
+ get currentUser() {
45
+ return this.#currentUser;
46
+ }
47
+ /**
48
+ * Role-derived menu visibility baseline (scopeKey → bool), resolved server-side at
49
+ * login by OR-ing the user's role presets. The menu reads `override ?? baseline ??
50
+ * false`; role codes are never exposed client-side — only this flat effect.
51
+ */
52
+ get menuBaseline() {
53
+ return this.#menuBaseline;
54
+ }
55
+ get isAuthEnabled() {
56
+ return this.#authEnabled;
57
+ }
58
+ /**
59
+ * Check if the current user has access to perform `operation` on `collection`.
60
+ *
61
+ * Resolution order:
62
+ * 1. `ops` policy blocks the operation → deny (structural, absolute)
63
+ * 2. Auth not initialized → allow (open mode, dev/test)
64
+ * 3. `public` policy includes the operation → allow (no auth required)
65
+ * 4. No user → deny
66
+ * 5. User inactive or locked → deny
67
+ * 6. appPermissions.ADMIN → allow all (within ops)
68
+ * 7. Explicit grant (temporal + collection scoped) → respected
69
+ * 8. `default` policy includes the operation → allow (authenticated fallback)
70
+ * 9. Deny
71
+ */
72
+ checkAccess(collection, operation = 'R') {
73
+ const policy = this.#policies[collection];
74
+ // 1. Structural ops whitelist — hard deny regardless of user/grants
75
+ const allowedOps = policy?.ops ?? ALL_OPS;
76
+ if (!allowedOps.includes(operation))
77
+ return false;
78
+ // 2. Open mode (auth not initialized)
79
+ if (!this.#authEnabled)
80
+ return true;
81
+ // 3. Public access
82
+ if (policy?.public?.includes(operation))
83
+ return true;
84
+ // 4–5. User checks
85
+ if (!this.#currentUser)
86
+ return false;
87
+ if (!this.#currentUser.isActive || this.#currentUser.isLocked)
88
+ return false;
89
+ // 6. Admin override
90
+ if (this.#currentUser.appPermissions?.ADMIN)
91
+ return true;
92
+ // 7. Explicit grants
93
+ const permField = operation.toLowerCase();
94
+ const now = new Date();
95
+ const granted = this.#grants.some(grant => {
96
+ if (grant.revokedAt)
97
+ return false;
98
+ if (grant.validFrom && new Date(grant.validFrom) > now)
99
+ return false;
100
+ if (grant.validUntil && new Date(grant.validUntil) < now)
101
+ return false;
102
+ const decoder = getGrantDecoder();
103
+ const schemeCode = decoder
104
+ ? decoder.decodeSchemeCode(grant)
105
+ : undefined;
106
+ if (schemeCode && schemeCode !== collection && schemeCode !== '*')
107
+ return false;
108
+ return grant[permField] === true;
109
+ });
110
+ if (granted)
111
+ return true;
112
+ // 8. Default policy for authenticated users
113
+ if (policy?.default?.includes(operation))
114
+ return true;
115
+ return false;
116
+ }
117
+ /**
118
+ * Enumerate all collections the current user has access to for the given operation.
119
+ * Returns an array of collection names where checkAccess(collection, op) returns true.
120
+ * Used by menu generators and UI components that need to filter collections by rights.
121
+ */
122
+ allowedCollections(operation = 'R') {
123
+ const result = [];
124
+ for (const [name] of Object.entries(this.#policies)) {
125
+ if (this.checkAccess(name, operation)) {
126
+ result.push(name);
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+ }
132
+ export const machineRights = new MachineRights();
133
+ export default machineRights;