@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
@@ -0,0 +1,96 @@
1
+ /**
2
+ * MachineAction — generic write dispatcher.
3
+ *
4
+ * Single entry point for any user-scoped write on any collection. Replaces
5
+ * the per-collection wrappers (prefs/history/activity) with one imperative
6
+ * action call: caller passes the target collection, the variables, and
7
+ * optional behavior hints (upsertOn / bump / touch / code template).
8
+ *
9
+ * Auto-injected on every call:
10
+ * - `id` : crypto.randomUUID() when not provided (with non-crypto fallback)
11
+ * - `userId` : host.rights.currentUser.id (no-op if no current user)
12
+ *
13
+ * The dispatcher is the only abstraction. It does not know — and must not
14
+ * know — what `appuser_prefs` / `appuser_history` / `appuser_activity` mean.
15
+ *
16
+ * Dependency is injected (no import of the `machine` singleton) to keep the
17
+ * module free of circular references with `machine.ts`.
18
+ */
19
+ function genId() {
20
+ const g = globalThis.crypto;
21
+ if (g?.randomUUID)
22
+ return g.randomUUID();
23
+ return Math.random().toString(36).slice(2) + Date.now().toString(36);
24
+ }
25
+ export class MachineAction {
26
+ #host = null;
27
+ /** Inject the host providing `currentUserId()` and `collection(name)`. Called once at machine boot. */
28
+ setHost(host) {
29
+ this.#host = host;
30
+ }
31
+ /**
32
+ * Write `vars` to `collection`, applying optional upsert / bump / touch / code rules.
33
+ * Returns the persisted document (or null when no user is authenticated, no host wired, or the collection is missing).
34
+ */
35
+ async act(collection, vars, opts = {}) {
36
+ const host = this.#host;
37
+ if (!host)
38
+ return null;
39
+ const uid = opts.userId ?? host.currentUserId();
40
+ if (!uid)
41
+ return null;
42
+ const col = host.collection(collection);
43
+ if (!col)
44
+ return null;
45
+ const payload = { ...vars, userId: uid };
46
+ if (opts.code !== undefined) {
47
+ payload.code = this.#renderTemplate(opts.code, { userId: uid, ...vars });
48
+ }
49
+ if (opts.touch) {
50
+ payload[opts.touch] = new Date().toISOString();
51
+ }
52
+ const naturalKey = opts.upsertOn?.length
53
+ ? opts.upsertOn
54
+ : (payload.code !== undefined ? ['code'] : undefined);
55
+ if (naturalKey) {
56
+ const existing = await this.#findByKey(col, naturalKey, payload);
57
+ if (existing) {
58
+ const patch = { ...payload };
59
+ delete patch.id;
60
+ if (opts.bump) {
61
+ const current = Number(existing[opts.bump] ?? 0);
62
+ patch[opts.bump] = current + 1;
63
+ }
64
+ await col.update(existing.id, patch);
65
+ return { ...existing, ...patch };
66
+ }
67
+ }
68
+ if (payload.id === undefined)
69
+ payload.id = genId();
70
+ if (opts.bump && payload[opts.bump] === undefined)
71
+ payload[opts.bump] = 1;
72
+ await col.create(payload);
73
+ return payload;
74
+ }
75
+ #renderTemplate(tpl, ctx) {
76
+ return tpl.replace(/\{(\w+)\}/g, (_, k) => {
77
+ const v = ctx[k];
78
+ return v == null ? '' : String(v);
79
+ });
80
+ }
81
+ async #findByKey(col, keys, payload) {
82
+ // Direct where() when a single key field is in play — cheapest path.
83
+ if (keys.length === 1 && payload[keys[0]] !== undefined) {
84
+ const docs = await Promise.resolve(col.where({ [keys[0]]: payload[keys[0]] }));
85
+ return docs[0] ?? null;
86
+ }
87
+ // Composite key — load all, filter in memory. Collections targeted by act()
88
+ // (logs, prefs) stay small in practice; revisit if a hot path emerges.
89
+ const all = await Promise.resolve(col.getAll());
90
+ return all.find((d) => keys.every((k) => String(d[k]) === String(payload[k]))) ?? null;
91
+ }
92
+ }
93
+ export const machineAction = new MachineAction();
94
+ const _call = machineAction.act.bind(machineAction);
95
+ Object.defineProperty(_call, 'instance', { value: machineAction, enumerable: false });
96
+ export const machineActionCallable = _call;
@@ -20,7 +20,7 @@ export class MachineError extends Error {
20
20
  constructor(message, code) {
21
21
  super(message);
22
22
  this.code = code;
23
- this.name = "MachineError";
23
+ this.name = 'MachineError';
24
24
  }
25
25
  /**
26
26
  * Throw a new MachineError.
@@ -43,7 +43,7 @@ export class MachineError extends Error {
43
43
  console.error(`${error.name}: ${error.message} (Code: ${error.code})`);
44
44
  }
45
45
  else {
46
- console.error("Unexpected error:", error);
46
+ console.error('Unexpected error:', error);
47
47
  }
48
48
  }
49
49
  }
@@ -16,7 +16,9 @@ export declare enum defaultTypes {
16
16
  phone = "phone",
17
17
  password = "password",
18
18
  file = "file",
19
- image = "image"
19
+ image = "image",
20
+ icon = "icon",
21
+ color = "color"
20
22
  }
21
23
  /**
22
24
  * Definition of a field type, including formatter and optional validator.
@@ -24,8 +26,11 @@ export declare enum defaultTypes {
24
26
  */
25
27
  export interface FieldTypeDef {
26
28
  id: string;
27
- formatter: (value: any) => any;
28
- validator?: (value: any) => boolean;
29
+ formatter: (value: unknown) => unknown;
30
+ validator?: (value: unknown, ctx?: {
31
+ formData?: Record<string, unknown>;
32
+ fieldName?: string;
33
+ }) => boolean | Promise<boolean>;
29
34
  }
30
35
  /**
31
36
  * Alias for a field type identifier.
@@ -67,7 +72,10 @@ declare class MachineFieldType {
67
72
  * Clears the registry before registering new types.
68
73
  */
69
74
  init(def: FieldTypeRegistry): void;
70
- validate(value: unknown, typeId: FieldTypeId): boolean;
75
+ validate(value: unknown, typeId: FieldTypeId, ctx?: {
76
+ formData?: Record<string, unknown>;
77
+ fieldName?: string;
78
+ }): Promise<boolean>;
71
79
  /**
72
80
  * Register a custom field type.
73
81
  * @param def Field type definition
@@ -100,14 +108,22 @@ declare class MachineFieldType {
100
108
  * @param validator New validator function
101
109
  * @returns true if updated, false if type not found
102
110
  */
103
- setValidator(id: FieldTypeId, validator: (value: any) => boolean): boolean;
111
+ setValidator(id: FieldTypeId, validator: (value: unknown, ctx?: {
112
+ formData?: Record<string, unknown>;
113
+ fieldName?: string;
114
+ }) => boolean | Promise<boolean>): boolean;
115
+ /**
116
+ * Format a value using the registered formatter for the given type id.
117
+ * Falls back to String(value) if type not found.
118
+ */
119
+ format(value: unknown, typeId: FieldTypeId): string;
104
120
  /**
105
121
  * Update the formatter function for a field type.
106
122
  * @param id Type identifier
107
123
  * @param formatter New formatter function
108
124
  * @returns true if updated, false if type not found
109
125
  */
110
- setFormatter(id: FieldTypeId, formatter: (value: any) => any): boolean;
126
+ setFormatter(id: FieldTypeId, formatter: (value: unknown) => unknown): boolean;
111
127
  }
112
128
  /**
113
129
  * Global singleton instance for all field type logic.
@@ -116,6 +132,9 @@ declare class MachineFieldType {
116
132
  * Example:
117
133
  * MachineSchemeFieldType.registerFieldType({ id: 'custom', formatter: v => v, validator: v => true });
118
134
  * const isValid = MachineSchemeFieldType.validate('foo', 'custom');
135
+ *
136
+ * The default catalogue (defaultFieldTypesDef) is auto-registered at module load.
137
+ * The domain layer (idae/fieldcatalog/) can re-init with an extended catalogue at boot.
119
138
  */
120
139
  export declare const MachineSchemeFieldType: MachineFieldType;
121
140
  export default MachineSchemeFieldType;
@@ -18,7 +18,26 @@ export var defaultTypes;
18
18
  defaultTypes["password"] = "password";
19
19
  defaultTypes["file"] = "file";
20
20
  defaultTypes["image"] = "image";
21
+ defaultTypes["icon"] = "icon";
22
+ defaultTypes["color"] = "color";
21
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
+ }
22
41
  /**
23
42
  * Registry of default field types.
24
43
  */
@@ -26,22 +45,22 @@ export const defaultFieldTypesDef = {
26
45
  id: {
27
46
  id: defaultTypes.id,
28
47
  formatter: (value) => String(value),
29
- validator: (value) => true,
48
+ validator: (value) => true
30
49
  },
31
50
  password: {
32
51
  id: defaultTypes.password,
33
52
  formatter: (value) => String(value),
34
- validator: (value) => true,
53
+ validator: (value) => true
35
54
  },
36
55
  file: {
37
56
  id: defaultTypes.file,
38
57
  formatter: (value) => String(value),
39
- validator: (value) => true,
58
+ validator: (value) => true
40
59
  },
41
60
  image: {
42
61
  id: defaultTypes.image,
43
62
  formatter: (value) => String(value),
44
- validator: (value) => true,
63
+ validator: (value) => true
45
64
  },
46
65
  email: {
47
66
  id: defaultTypes.email,
@@ -49,7 +68,7 @@ export const defaultFieldTypesDef = {
49
68
  validator: (value) => {
50
69
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
51
70
  return emailRegex.test(String(value).toLowerCase());
52
- },
71
+ }
53
72
  },
54
73
  url: {
55
74
  id: defaultTypes.url,
@@ -62,7 +81,7 @@ export const defaultFieldTypesDef = {
62
81
  catch {
63
82
  return false;
64
83
  }
65
- },
84
+ }
66
85
  },
67
86
  phone: {
68
87
  id: defaultTypes.phone,
@@ -70,58 +89,112 @@ export const defaultFieldTypesDef = {
70
89
  validator: (value) => {
71
90
  const phoneRegex = /^\+?[\d\s-]{10,}$/;
72
91
  return phoneRegex.test(String(value));
73
- },
92
+ }
74
93
  },
75
94
  date: {
76
95
  id: defaultTypes.date,
77
96
  formatter: (value) => {
78
- new Date(value);
97
+ const d = new Date(value);
98
+ return isNaN(d.getTime()) ? String(value) : d.toLocaleDateString();
79
99
  },
80
100
  validator: (value) => {
81
- const date = new Date(value);
101
+ const date = new Date(String(value));
82
102
  return !isNaN(date.getTime());
83
- },
103
+ }
84
104
  },
85
105
  datetime: {
86
106
  id: defaultTypes.datetime,
87
107
  formatter: (value) => {
88
- new Date(value);
108
+ const d = new Date(value);
109
+ return isNaN(d.getTime()) ? String(value) : d.toLocaleString();
89
110
  },
90
111
  validator: (value) => {
91
- const date = new Date(value);
112
+ const date = new Date(String(value));
92
113
  return !isNaN(date.getTime());
93
- },
114
+ }
94
115
  },
95
116
  time: {
96
117
  id: defaultTypes.time,
97
118
  formatter: (value) => {
98
- new Date(value);
99
- },
100
- validator: (value) => {
101
- const date = new Date(value);
102
- return !isNaN(date.getTime());
119
+ const d = new Date(`1970-01-01T${value}`);
120
+ return isNaN(d.getTime()) ? String(value) : d.toLocaleTimeString();
103
121
  },
122
+ validator: (value) => isValidTimeValue(value)
104
123
  },
105
124
  text: {
106
125
  id: defaultTypes.text,
107
126
  formatter: (value) => String(value),
108
- validator: (value) => true,
127
+ validator: (value) => true
109
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 },
110
143
  number: {
111
144
  id: defaultTypes.number,
112
145
  formatter: (value) => Number(value),
113
- validator: (value) => typeof value === "number" && !isNaN(value),
146
+ validator: (value) => typeof value === 'number' && !isNaN(value)
114
147
  },
115
148
  boolean: {
116
149
  id: defaultTypes.boolean,
117
- formatter: (value) => Boolean(value),
118
- validator: (value) => typeof value === "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))
119
162
  },
120
163
  any: {
121
164
  id: defaultTypes.any,
122
165
  formatter: (value) => value,
123
- validator: (value) => true,
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))
124
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
+ }
125
198
  };
126
199
  /**
127
200
  * @role field-type-registry
@@ -154,13 +227,17 @@ class MachineFieldType {
154
227
  this.fieldTypeRegistry = {};
155
228
  this.registerFieldTypes(def);
156
229
  }
157
- validate(value, typeId) {
230
+ async validate(value, typeId, ctx) {
158
231
  const fieldType = this.getFieldType(typeId);
159
- if (!fieldType) {
232
+ if (!fieldType)
160
233
  return false;
161
- }
162
234
  if (fieldType.validator) {
163
- return fieldType.validator(value);
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);
164
241
  }
165
242
  return true;
166
243
  }
@@ -222,6 +299,17 @@ class MachineFieldType {
222
299
  }
223
300
  return false;
224
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
+ }
225
313
  /**
226
314
  * Update the formatter function for a field type.
227
315
  * @param id Type identifier
@@ -244,6 +332,9 @@ class MachineFieldType {
244
332
  * Example:
245
333
  * MachineSchemeFieldType.registerFieldType({ id: 'custom', formatter: v => v, validator: v => true });
246
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.
247
338
  */
248
339
  export const MachineSchemeFieldType = new MachineFieldType();
249
340
  MachineSchemeFieldType.init(defaultFieldTypesDef);
@@ -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;