@medyll/idae-machine 0.135.2 → 0.136.2
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.
- package/LICENSE +21 -21
- package/README.md +555 -360
- package/cli.cjs +22 -0
- package/dist/__fixtures__/demoModel.d.ts +79 -0
- package/dist/__fixtures__/demoModel.js +146 -0
- package/dist/ai/frame/AiChatSession.svelte +152 -0
- package/dist/ai/frame/AiChatSession.svelte.d.ts +7 -0
- package/dist/ai/frame/index.d.ts +1 -0
- package/dist/ai/frame/index.js +2 -0
- package/dist/ai/index.d.ts +9 -0
- package/dist/ai/index.js +12 -0
- package/dist/ai/schema/ai-catalogs.d.ts +2 -0
- package/dist/ai/schema/ai-catalogs.js +86 -0
- package/dist/ai/schema/ai-chat-session.d.ts +2 -0
- package/dist/ai/schema/ai-chat-session.js +35 -0
- package/dist/ai/schema/ai-companion.d.ts +2 -0
- package/dist/ai/schema/ai-companion.js +25 -0
- package/dist/ai/schema/ai-message.d.ts +2 -0
- package/dist/ai/schema/ai-message.js +20 -0
- package/dist/ai/schema/ai-tool-call.d.ts +2 -0
- package/dist/ai/schema/ai-tool-call.js +18 -0
- package/dist/ai/schema/ai-user-prompt.d.ts +2 -0
- package/dist/ai/schema/ai-user-prompt.js +17 -0
- package/dist/ai/schema/tag.d.ts +2 -0
- package/dist/ai/schema/tag.js +14 -0
- package/dist/ai/streamIntoRecord.d.ts +31 -0
- package/dist/ai/streamIntoRecord.js +79 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +19 -0
- package/dist/data-ui/controls/AlphabetFilter.svelte +114 -0
- package/dist/data-ui/controls/AlphabetFilter.svelte.d.ts +10 -0
- package/dist/data-ui/controls/ButtonAction.svelte +151 -0
- package/dist/data-ui/controls/ButtonAction.svelte.d.ts +18 -0
- package/dist/data-ui/controls/DataFind.svelte +174 -0
- package/dist/data-ui/controls/DataFind.svelte.d.ts +10 -0
- package/dist/data-ui/controls/DataGroup.svelte +150 -0
- package/dist/data-ui/controls/DataGroup.svelte.d.ts +7 -0
- package/dist/data-ui/controls/DataSort.svelte +78 -0
- package/dist/data-ui/controls/DataSort.svelte.d.ts +9 -0
- package/dist/data-ui/controls/DataToolbar.svelte +67 -0
- package/dist/data-ui/controls/DataToolbar.svelte.d.ts +11 -0
- package/dist/data-ui/controls/Find.svelte +38 -0
- package/dist/data-ui/controls/Find.svelte.d.ts +9 -0
- package/dist/data-ui/controls/FkFilter.svelte +94 -0
- package/dist/data-ui/controls/FkFilter.svelte.d.ts +11 -0
- package/dist/data-ui/controls/Group.svelte +36 -0
- package/dist/data-ui/controls/Group.svelte.d.ts +8 -0
- package/dist/data-ui/controls/ListMode.svelte +79 -0
- package/dist/data-ui/controls/ListMode.svelte.d.ts +10 -0
- package/dist/data-ui/controls/Sort.svelte +100 -0
- package/dist/data-ui/controls/Sort.svelte.d.ts +8 -0
- package/dist/data-ui/data/DataCount.svelte +67 -0
- package/dist/data-ui/data/DataCount.svelte.d.ts +36 -0
- package/dist/data-ui/data/DataFk.svelte +54 -0
- package/dist/data-ui/data/DataFk.svelte.d.ts +11 -0
- package/dist/data-ui/data/DataForm.svelte +191 -0
- package/dist/data-ui/data/DataForm.svelte.d.ts +15 -0
- package/dist/data-ui/data/DataList.svelte +645 -0
- package/dist/data-ui/data/DataList.svelte.d.ts +75 -0
- package/dist/data-ui/data/DataListFk.svelte +111 -0
- package/dist/data-ui/data/DataListFk.svelte.d.ts +13 -0
- package/dist/data-ui/data/DataListRfk.svelte +111 -0
- package/dist/data-ui/data/DataListRfk.svelte.d.ts +13 -0
- package/dist/data-ui/data/DataRecord.svelte +167 -0
- package/dist/data-ui/data/DataRecord.svelte.d.ts +22 -0
- package/dist/data-ui/data/DataRfk.svelte +73 -0
- package/dist/data-ui/data/DataRfk.svelte.d.ts +15 -0
- package/dist/data-ui/data/index.d.ts +7 -0
- package/dist/data-ui/data/index.js +8 -0
- package/dist/data-ui/field/DataField.svelte +343 -0
- package/dist/data-ui/field/DataField.svelte.d.ts +33 -0
- package/dist/{form/FieldInPlace.svelte → data-ui/field/DataFieldEdit.svelte} +103 -98
- package/dist/{form/FieldInPlace.svelte.d.ts → data-ui/field/DataFieldEdit.svelte.d.ts} +5 -5
- package/dist/data-ui/field/index.d.ts +2 -0
- package/dist/data-ui/field/index.js +3 -0
- package/dist/data-ui/field/snippets/FieldAiPrompt.svelte +145 -0
- package/dist/data-ui/field/snippets/FieldAiPrompt.svelte.d.ts +14 -0
- package/dist/data-ui/field/snippets/FieldBoolean.svelte +43 -0
- package/dist/data-ui/field/snippets/FieldBoolean.svelte.d.ts +12 -0
- package/dist/data-ui/field/snippets/FieldColor.svelte +48 -0
- package/dist/data-ui/field/snippets/FieldColor.svelte.d.ts +10 -0
- package/dist/data-ui/field/snippets/FieldCurrency.svelte +105 -0
- package/dist/data-ui/field/snippets/FieldCurrency.svelte.d.ts +15 -0
- package/dist/data-ui/field/snippets/FieldEmail.svelte +77 -0
- package/dist/data-ui/field/snippets/FieldEmail.svelte.d.ts +14 -0
- package/dist/data-ui/field/snippets/FieldIcon.svelte +73 -0
- package/dist/data-ui/field/snippets/FieldIcon.svelte.d.ts +11 -0
- package/dist/data-ui/field/snippets/FieldSelect.svelte +71 -0
- package/dist/data-ui/field/snippets/FieldSelect.svelte.d.ts +15 -0
- package/dist/data-ui/field/snippets/FieldText.svelte +52 -0
- package/dist/data-ui/field/snippets/FieldText.svelte.d.ts +13 -0
- package/dist/data-ui/field/snippets/FieldTextarea.svelte +50 -0
- package/dist/data-ui/field/snippets/FieldTextarea.svelte.d.ts +13 -0
- package/dist/data-ui/field/snippets/index.d.ts +9 -0
- package/dist/data-ui/field/snippets/index.js +10 -0
- package/dist/data-ui/fragments/ContextMenu.svelte +109 -0
- package/dist/data-ui/fragments/ContextMenu.svelte.d.ts +4 -0
- package/dist/data-ui/fragments/ContextMenuContent.svelte +275 -0
- package/dist/data-ui/fragments/ContextMenuContent.svelte.d.ts +8 -0
- package/dist/data-ui/fragments/Frame.svelte +43 -0
- package/dist/data-ui/fragments/Frame.svelte.d.ts +10 -0
- package/dist/data-ui/fragments/InfoLine.svelte +123 -0
- package/dist/data-ui/fragments/InfoLine.svelte.d.ts +12 -0
- package/dist/data-ui/fragments/Selector.svelte +56 -0
- package/dist/data-ui/fragments/Selector.svelte.d.ts +10 -0
- package/dist/{fragments → data-ui/fragments}/Skeleton.svelte +21 -21
- package/dist/data-ui/fragments/Tile.svelte +126 -0
- package/dist/data-ui/fragments/Tile.svelte.d.ts +14 -0
- package/dist/data-ui/fragments/contextMenu.svelte.d.ts +22 -0
- package/dist/data-ui/fragments/contextMenu.svelte.js +31 -0
- package/dist/data-ui/fragments/dialog/Dialog.svelte +185 -0
- package/dist/data-ui/fragments/dialog/Dialog.svelte.d.ts +29 -0
- package/dist/data-ui/fragments/dialog/dialog.svelte.d.ts +27 -0
- package/dist/data-ui/fragments/dialog/dialog.svelte.js +41 -0
- package/dist/data-ui/fragments/index.d.ts +11 -0
- package/dist/data-ui/fragments/index.js +11 -0
- package/dist/data-ui/utils/__tests__/HostProbe.svelte +18 -0
- package/dist/data-ui/utils/__tests__/HostProbe.svelte.d.ts +8 -0
- package/dist/data-ui/utils/data-utils.d.ts +29 -0
- package/dist/data-ui/utils/data-utils.js +83 -0
- package/dist/data-ui/utils/dataRelationUtils.d.ts +37 -0
- package/dist/data-ui/utils/dataRelationUtils.js +125 -0
- package/dist/data-ui/utils/diagramUtils.d.ts +6 -0
- package/dist/data-ui/utils/diagramUtils.js +131 -0
- package/dist/data-ui/utils/draggable.d.ts +15 -0
- package/dist/data-ui/utils/draggable.js +61 -0
- package/dist/data-ui/utils/menuPrefs.d.ts +80 -0
- package/dist/data-ui/utils/menuPrefs.js +119 -0
- package/dist/data-ui/utils/useMachinePrefs.svelte.d.ts +38 -0
- package/dist/data-ui/utils/useMachinePrefs.svelte.js +117 -0
- package/dist/data-ui/utils/useMenuTree.svelte.d.ts +26 -0
- package/dist/data-ui/utils/useMenuTree.svelte.js +68 -0
- package/dist/data-ui/utils/useRecordData.svelte.d.ts +22 -0
- package/dist/data-ui/utils/useRecordData.svelte.js +50 -0
- package/dist/data-ui/utils/useViewFields.svelte.d.ts +22 -0
- package/dist/data-ui/utils/useViewFields.svelte.js +59 -0
- package/dist/demo/.gitkeep +0 -0
- package/dist/demo/demo-status.json +9 -0
- package/dist/idae/boot.d.ts +28 -0
- package/dist/idae/boot.js +43 -0
- package/dist/idae/bridge/register.d.ts +4 -0
- package/dist/idae/bridge/register.js +15 -0
- package/dist/idae/capabilities/Capabilities.d.ts +10 -0
- package/dist/idae/capabilities/Capabilities.js +34 -0
- package/dist/idae/codefield/CodeFieldConvention.d.ts +3 -0
- package/dist/idae/codefield/CodeFieldConvention.js +25 -0
- package/dist/idae/fieldcatalog/defaultFieldTypesDef.d.ts +2 -0
- package/dist/idae/fieldcatalog/defaultFieldTypesDef.js +104 -0
- package/dist/idae/frames/FrameCatalog.d.ts +31 -0
- package/dist/idae/frames/FrameCatalog.js +31 -0
- package/dist/idae/index.d.ts +14 -0
- package/dist/idae/index.js +13 -0
- package/dist/idae/menu/IdaeMenuManager.d.ts +79 -0
- package/dist/idae/menu/IdaeMenuManager.js +108 -0
- package/dist/idae/menu/IdaeMenuStore.d.ts +77 -0
- package/dist/idae/menu/IdaeMenuStore.js +68 -0
- package/dist/idae/menu/menuSnapshot.d.ts +30 -0
- package/dist/idae/menu/menuSnapshot.js +30 -0
- package/dist/idae/meta/MetaModelProvider.d.ts +11 -0
- package/dist/idae/meta/MetaModelProvider.js +43 -0
- package/dist/idae/relations/RelationPolicy.d.ts +19 -0
- package/dist/idae/relations/RelationPolicy.js +125 -0
- package/dist/idae/rights/RightsPolicy.d.ts +16 -0
- package/dist/idae/rights/RightsPolicy.js +80 -0
- package/dist/idae/userscope/UserScopePolicy.d.ts +9 -0
- package/dist/idae/userscope/UserScopePolicy.js +42 -0
- package/dist/idae/userscope/navTracking.d.ts +11 -0
- package/dist/idae/userscope/navTracking.js +15 -0
- package/dist/index.d.ts +68 -35
- package/dist/index.js +82 -36
- package/dist/main/__tests__/_relationTestUtils.d.ts +12 -0
- package/dist/main/__tests__/_relationTestUtils.js +53 -0
- package/dist/main/__tests__/helpers/mockCollection.d.ts +21 -0
- package/dist/main/__tests__/helpers/mockCollection.js +27 -0
- package/dist/main/api/types.d.ts +29 -0
- package/dist/main/ext/hooks.d.ts +32 -0
- package/dist/main/ext/hooks.js +31 -0
- package/dist/main/ext/interfaces.d.ts +69 -0
- package/dist/main/ext/interfaces.js +3 -0
- package/dist/main/ext/registry.d.ts +29 -0
- package/dist/main/ext/registry.js +30 -0
- package/dist/main/frame/MachineFrameManager.d.ts +187 -0
- package/dist/main/frame/MachineFrameManager.js +403 -0
- package/dist/main/frame/contextMenuSetup.d.ts +9 -0
- package/dist/main/frame/contextMenuSetup.js +42 -0
- package/dist/main/frame/frameUrl.d.ts +1 -0
- package/dist/main/frame/frameUrl.js +8 -0
- package/dist/main/frame/frameUtils.d.ts +16 -0
- package/dist/main/frame/frameUtils.js +26 -0
- package/dist/main/frame/linkParser.d.ts +9 -0
- package/dist/main/frame/linkParser.js +15 -0
- package/dist/main/index.d.ts +15 -0
- package/dist/main/index.js +19 -0
- package/dist/main/machine/MachineAction.d.ts +62 -0
- package/dist/main/machine/MachineAction.js +96 -0
- package/dist/main/machine/MachineError.js +2 -2
- package/dist/main/machine/MachineFieldType.d.ts +25 -6
- package/dist/main/machine/MachineFieldType.js +118 -27
- package/dist/main/machine/MachineFkFold.d.ts +34 -0
- package/dist/main/machine/MachineFkFold.js +57 -0
- package/dist/main/machine/MachineRecordIdentity.d.ts +26 -0
- package/dist/main/machine/MachineRecordIdentity.js +44 -0
- package/dist/main/machine/MachineRights.d.ts +50 -0
- package/dist/main/machine/MachineRights.js +133 -0
- package/dist/main/machine/MachineRouter.d.ts +56 -0
- package/dist/main/machine/MachineRouter.js +250 -0
- package/dist/main/machine/MachineScheme.d.ts +40 -70
- package/dist/main/machine/MachineScheme.js +107 -94
- package/dist/main/machine/MachineSchemeField.js +32 -16
- package/dist/main/machine/MachineSchemeFieldForge.d.ts +11 -11
- package/dist/main/machine/MachineSchemeFieldForge.js +33 -21
- package/dist/main/machine/MachineSchemeFieldValues.d.ts +8 -9
- package/dist/main/machine/MachineSchemeFieldValues.js +12 -9
- package/dist/main/machine/MachineSchemeValidate.d.ts +69 -13
- package/dist/main/machine/MachineSchemeValidate.js +173 -46
- package/dist/main/machine/MachineSchemeValues.d.ts +32 -21
- package/dist/main/machine/MachineSchemeValues.js +132 -104
- package/dist/main/machine/SchemeFieldDefaultValues.d.ts +4 -2
- package/dist/main/machine/SchemeFieldDefaultValues.js +8 -2
- package/dist/main/machine/authState.svelte.d.ts +11 -0
- package/dist/main/machine/authState.svelte.js +17 -0
- package/dist/main/machine/fieldBuilder.d.ts +23 -0
- package/dist/main/machine/fieldBuilder.d.ts.map +1 -0
- package/dist/main/machine/fieldBuilder.js +10 -0
- package/dist/main/machine/fieldBuilder.js.map +1 -0
- package/dist/main/machine/machineLabel.d.ts +11 -0
- package/dist/main/machine/machineLabel.js +23 -0
- package/dist/main/machine/validateRules.d.ts +38 -0
- package/dist/main/machine/validateRules.js +109 -0
- package/dist/main/machine.d.ts +207 -68
- package/dist/main/machine.js +482 -96
- package/dist/main/machineDb.d.ts +21 -8
- package/dist/main/machineDb.js +33 -4
- package/dist/main/machineIdbAdapter.d.ts +83 -0
- package/dist/main/machineIdbAdapter.js +347 -0
- package/dist/main/machineModelBuilder.d.ts +31 -0
- package/dist/main/machineModelBuilder.js +58 -0
- package/dist/main/machineParserForge.d.ts +9 -18
- package/dist/main/machineParserForge.js +92 -35
- package/dist/main/machineSchemaCache.d.ts +8 -0
- package/dist/main/machineSchemaCache.js +58 -0
- package/dist/main/machineSchemaDoctor.d.ts +17 -0
- package/dist/main/machineSchemaDoctor.js +73 -0
- package/dist/main/machineSchemaLoader.d.ts +18 -0
- package/dist/main/machineSchemaLoader.js +43 -0
- package/dist/main/machineSeed.d.ts +21 -0
- package/dist/main/machineSeed.js +44 -0
- package/dist/main/router/componentRegistry.d.ts +35 -0
- package/dist/main/router/componentRegistry.js +35 -0
- package/dist/main/router/urlParser.d.ts +17 -0
- package/dist/main/router/urlParser.js +41 -0
- package/dist/main/warmupUtils.d.ts +40 -0
- package/dist/main/warmupUtils.js +73 -0
- package/dist/mcp/MachineMcpClient.d.ts +43 -0
- package/dist/mcp/MachineMcpClient.js +175 -0
- package/dist/shell/Frame.svelte +67 -0
- package/dist/shell/Frame.svelte.d.ts +11 -0
- package/dist/shell/auth/Login.svelte +244 -0
- package/dist/shell/auth/Login.svelte.d.ts +3 -0
- package/dist/shell/frame/dashboard/Dashboard.svelte +0 -0
- package/dist/shell/frame/dashboard/Dashboard.svelte.d.ts +26 -0
- package/dist/shell/frame/diagram/Diagram.svelte +244 -0
- package/dist/shell/frame/diagram/Diagram.svelte.d.ts +9 -0
- package/dist/shell/frame/explorer/Explorer.svelte +86 -0
- package/dist/shell/frame/explorer/Explorer.svelte.d.ts +29 -0
- package/dist/shell/frame/explorer/ExplorerContent.svelte +126 -0
- package/dist/shell/frame/explorer/ExplorerContent.svelte.d.ts +32 -0
- package/dist/shell/frame/index.d.ts +8 -0
- package/dist/shell/frame/index.js +9 -0
- package/dist/shell/frame/main-menu-content/MainMenuContent.svelte +100 -0
- package/dist/shell/frame/main-menu-content/MainMenuContent.svelte.d.ts +6 -0
- package/dist/shell/frame/planning/Planning.svelte +426 -0
- package/dist/shell/frame/planning/Planning.svelte.d.ts +12 -0
- package/dist/shell/frame/rbac/RbacMatrix.svelte +197 -0
- package/dist/shell/frame/rbac/RbacMatrix.svelte.d.ts +7 -0
- package/dist/shell/frame/space/Space.svelte +554 -0
- package/dist/shell/frame/space/Space.svelte.d.ts +8 -0
- package/dist/shell/frame/synthesis/Synthesis.svelte +383 -0
- package/dist/shell/frame/synthesis/Synthesis.svelte.d.ts +8 -0
- package/dist/shell/frame/today/Today.svelte +174 -0
- package/dist/shell/frame/today/Today.svelte.d.ts +3 -0
- package/dist/shell/layout/App.svelte +30 -0
- package/dist/shell/layout/App.svelte.d.ts +3 -0
- package/dist/shell/layout/Breadcrumb.svelte +67 -0
- package/dist/shell/layout/Breadcrumb.svelte.d.ts +12 -0
- package/dist/shell/layout/Columner.svelte +214 -0
- package/dist/shell/layout/Columner.svelte.d.ts +16 -0
- package/dist/shell/layout/DevResetPanel.svelte +194 -0
- package/dist/shell/layout/DevResetPanel.svelte.d.ts +7 -0
- package/dist/shell/layout/Fiche.svelte +111 -0
- package/dist/shell/layout/Fiche.svelte.d.ts +7 -0
- package/dist/shell/layout/FicheUpdate.svelte +53 -0
- package/dist/shell/layout/FicheUpdate.svelte.d.ts +7 -0
- package/dist/shell/layout/MainMenu.svelte +256 -0
- package/dist/shell/layout/MainMenu.svelte.d.ts +6 -0
- package/dist/shell/layout/MenuSettings.svelte +182 -0
- package/dist/shell/layout/MenuSettings.svelte.d.ts +6 -0
- package/dist/shell/layout/RecordTimeline.svelte +199 -0
- package/dist/shell/layout/RecordTimeline.svelte.d.ts +8 -0
- package/dist/shell/layout/RecordToolbar.svelte +39 -0
- package/dist/shell/layout/RecordToolbar.svelte.d.ts +7 -0
- package/dist/shell/layout/TaskBar.svelte +118 -0
- package/dist/shell/layout/TaskBar.svelte.d.ts +7 -0
- package/dist/shell/layout/TemplateShell.svelte +48 -0
- package/dist/shell/layout/TemplateShell.svelte.d.ts +15 -0
- package/dist/shell/layout/ThemeToggle.svelte +46 -0
- package/dist/shell/layout/ThemeToggle.svelte.d.ts +3 -0
- package/dist/shell/layout/index.d.ts +8 -0
- package/dist/shell/layout/index.js +9 -0
- package/dist/storage/ApiStorageAdapter.d.ts +41 -0
- package/dist/storage/ApiStorageAdapter.js +111 -0
- package/dist/storage/IdbStorageAdapter.d.ts +31 -0
- package/dist/storage/IdbStorageAdapter.js +72 -0
- package/dist/storage/MemoryStorageAdapter.d.ts +33 -0
- package/dist/storage/MemoryStorageAdapter.js +132 -0
- package/dist/storage/README.md +222 -0
- package/dist/storage/StorageAdapter.d.ts +75 -0
- package/dist/storage/StorageAdapter.js +7 -0
- package/dist/storage/demo/storage-demo.d.ts +22 -0
- package/dist/storage/demo/storage-demo.js +107 -0
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.js +9 -0
- package/dist/types/entity-types.d.ts +444 -0
- package/dist/types/entity-types.js +16 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +6 -0
- package/dist/types/machine-model.d.ts +198 -0
- package/dist/types/machine-model.js +5 -0
- package/dist/types/qoolie-svelte.d.ts +11 -0
- package/dist/types/schema-utils.d.ts +32 -0
- package/dist/types/schema-utils.js +103 -0
- package/dist/utils/generateCode.d.ts +5 -0
- package/dist/utils/generateCode.js +9 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.js +20 -0
- package/package.json +59 -33
- package/cli.js +0 -46
- package/dist/db/CrudService.d.ts +0 -9
- package/dist/db/CrudService.js +0 -45
- package/dist/demo/dbSchema.d.ts +0 -446
- package/dist/demo/dbSchema.js +0 -449
- package/dist/demo/testScheme.d.ts +0 -56
- package/dist/demo/testScheme.js +0 -42
- package/dist/form/CreateUpdate.svelte +0 -219
- package/dist/form/CreateUpdate.svelte.d.ts +0 -27
- package/dist/form/DataProvider.svelte +0 -23
- package/dist/form/DataProvider.svelte.d.ts +0 -7
- package/dist/form/FieldValue.svelte +0 -148
- package/dist/form/FieldValue.svelte.d.ts +0 -34
- package/dist/form/types.d.ts +0 -17
- package/dist/fragments/Confirm.svelte +0 -73
- package/dist/fragments/Confirm.svelte.d.ts +0 -7
- package/dist/fragments/Frame.svelte +0 -19
- package/dist/fragments/Frame.svelte.d.ts +0 -32
- package/dist/fragments/InfoLine.svelte +0 -21
- package/dist/fragments/InfoLine.svelte.d.ts +0 -35
- package/dist/fragments/Selector.svelte +0 -26
- package/dist/fragments/Selector.svelte.d.ts +0 -38
- package/dist/main/machine/MachineSchemeField.d.ts +0 -19
- package/dist/types/appschemeTypes.d.ts +0 -71
- package/dist/types/appschemeTypes.js +0 -83
- package/dist/ui/CollectionButton.svelte +0 -29
- package/dist/ui/CollectionButton.svelte.d.ts +0 -29
- package/dist/ui/CollectionFks.svelte +0 -24
- package/dist/ui/CollectionFks.svelte.d.ts +0 -9
- package/dist/ui/CollectionList.svelte +0 -100
- package/dist/ui/CollectionList.svelte.d.ts +0 -36
- package/dist/ui/CollectionListFieldValues.svelte +0 -59
- package/dist/ui/CollectionListFieldValues.svelte.d.ts +0 -9
- package/dist/ui/CollectionListMenu.svelte +0 -39
- package/dist/ui/CollectionListMenu.svelte.d.ts +0 -34
- package/dist/ui/CollectionReverseFks.svelte +0 -37
- package/dist/ui/CollectionReverseFks.svelte.d.ts +0 -14
- /package/dist/{fragments → data-ui/fragments}/Skeleton.svelte.d.ts +0 -0
- /package/dist/{form → main/api}/types.js +0 -0
package/dist/main/machine.js
CHANGED
|
@@ -1,116 +1,334 @@
|
|
|
1
|
-
import { MachineDb } from
|
|
2
|
-
import {
|
|
1
|
+
import { MachineDb } from './machineDb.js';
|
|
2
|
+
import { createQoolie } from '@medyll/qoolie';
|
|
3
|
+
import { useQoolieCollection, useQoolieQuery } from '@medyll/qoolie/svelte';
|
|
4
|
+
import { be as _be } from '@medyll/idae-be';
|
|
5
|
+
import { MachineRouter } from './machine/MachineRouter.js';
|
|
6
|
+
import { setupNavigationTracking } from '../idae/userscope/navTracking.js';
|
|
7
|
+
import { machineRights } from './machine/MachineRights.js';
|
|
8
|
+
import { machineAction, machineActionCallable } from './machine/MachineAction.js';
|
|
9
|
+
import { buildEffectiveModel } from './machineModelBuilder.js';
|
|
10
|
+
import { diagnoseMachineModel } from './machineSchemaDoctor.js';
|
|
11
|
+
import { detectSchemaDrift, performIdbUpgrade, deleteIdbDatabase, getActualIdbVersion, storeSchemaHash } from './machineIdbAdapter.js';
|
|
12
|
+
import { componentRegistry } from './router/componentRegistry.js';
|
|
13
|
+
import { machineFrameManager } from './frame/MachineFrameManager.js';
|
|
14
|
+
import { createMenuManager } from '../idae/menu/menuSnapshot.js';
|
|
15
|
+
import { wrapCollectionFkFold } from './machine/MachineFkFold.js';
|
|
16
|
+
import { initializeDomainPoliciesWithMachine, initializeDomainPoliciesWithModel, frameCatalog } from '../idae/boot.js';
|
|
17
|
+
/**
|
|
18
|
+
* Race a promise against a timeout so a silently-hung IndexedDB open (e.g. an Edge
|
|
19
|
+
* tab where another connection blocks the versioned upgrade) rejects instead of
|
|
20
|
+
* leaving the app stuck on the boot splash forever. The rejection bubbles to the
|
|
21
|
+
* caller's boot try/catch → recovery screen, turning an invisible hang into a real error.
|
|
22
|
+
*/
|
|
23
|
+
function withTimeout(promise, ms, label) {
|
|
24
|
+
let timer;
|
|
25
|
+
const timeout = new Promise((_, reject) => {
|
|
26
|
+
timer = setTimeout(() => reject(new Error(`[idae-machine] ${label} timed out after ${ms}ms — IndexedDB likely blocked (another tab open) or sync stalled. Close other tabs and reload.`)), ms);
|
|
27
|
+
});
|
|
28
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
29
|
+
}
|
|
30
|
+
const machineComponentRegistry = Object.freeze({
|
|
31
|
+
register: componentRegistry.register.bind(componentRegistry),
|
|
32
|
+
registerMany: componentRegistry.registerMany.bind(componentRegistry),
|
|
33
|
+
unregister: componentRegistry.unregister.bind(componentRegistry),
|
|
34
|
+
resolve: componentRegistry.resolve.bind(componentRegistry),
|
|
35
|
+
has: componentRegistry.has.bind(componentRegistry),
|
|
36
|
+
keys: componentRegistry.keys.bind(componentRegistry)
|
|
37
|
+
});
|
|
3
38
|
/**
|
|
4
39
|
* @class Machine
|
|
5
40
|
* @role Main entry point for managing the IDBQL connection and centralized data access.
|
|
6
41
|
*/
|
|
7
42
|
export class Machine {
|
|
8
43
|
/**
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
_idbql;
|
|
12
|
-
/**
|
|
13
|
-
* IDBQL (stateful collections instance)
|
|
44
|
+
* Static registry of named Machine instances
|
|
14
45
|
*/
|
|
15
|
-
|
|
46
|
+
static instanceRegistry = {};
|
|
16
47
|
/**
|
|
17
|
-
*
|
|
48
|
+
* Instance name (optional)
|
|
18
49
|
*/
|
|
19
|
-
|
|
50
|
+
instanceName;
|
|
20
51
|
/**
|
|
21
|
-
*
|
|
52
|
+
* Qoolie instance — data layer (IndexedDB + optional sync)
|
|
22
53
|
*/
|
|
23
|
-
|
|
54
|
+
_qoolie;
|
|
24
55
|
/**
|
|
25
56
|
* Centralized access to schema and collection logic
|
|
26
57
|
*/
|
|
27
58
|
_machineDb;
|
|
28
59
|
/**
|
|
29
|
-
* Database name
|
|
60
|
+
* Database name (IDB). Derived from org+domain if not explicit.
|
|
30
61
|
*/
|
|
31
|
-
_dbName;
|
|
62
|
+
_dbName = '';
|
|
32
63
|
/**
|
|
33
64
|
* Schema version
|
|
34
65
|
*/
|
|
35
|
-
_version;
|
|
66
|
+
_version = 1;
|
|
67
|
+
/** System/framework collections (appscheme, appuser_*, …). Usually omitted — schema is fetched during boot(). */
|
|
68
|
+
_core;
|
|
69
|
+
/** Application business collections (vehicle, reservation, …). */
|
|
70
|
+
_business;
|
|
71
|
+
/**
|
|
72
|
+
* Effective model = system collections + business model. Built once at boot().
|
|
73
|
+
*/
|
|
74
|
+
_effectiveModel;
|
|
75
|
+
/** Organisation identifier — prefixes all DB names. e.g. 'test', 'crfr' */
|
|
76
|
+
_org;
|
|
77
|
+
/** Domain/site name. e.g. 'machine', 'sitebase' */
|
|
78
|
+
_domain;
|
|
79
|
+
/**
|
|
80
|
+
* Schema router instance (lazy-initialized)
|
|
81
|
+
*/
|
|
82
|
+
_router;
|
|
83
|
+
/** Global sync config forwarded to createQoolie(). false = sync disabled. */
|
|
84
|
+
_syncOptions;
|
|
85
|
+
/** Reactive state engine: 'svelte5' (default) | 'stator' */
|
|
86
|
+
_stateEngine;
|
|
87
|
+
/** Qoolie lifecycle hooks */
|
|
88
|
+
_hooks;
|
|
89
|
+
/** Seed data for mobile-first mode — auto-called with onlyIfEmpty on boot if mode === 'mobile-first' */
|
|
90
|
+
_seed;
|
|
91
|
+
/** Frame manager — handles dynamic frame registration and content loading */
|
|
92
|
+
_frameManager = machineFrameManager;
|
|
93
|
+
/** Menu manager — created during boot to avoid module-level machine dependency. */
|
|
94
|
+
_menuManager;
|
|
95
|
+
/** Cleanup fn returned by setupContextMenuListener — called in destroy(). */
|
|
96
|
+
_contextMenuCleanup;
|
|
97
|
+
/** Last boot trace — intentionally plain data so recovery screens can render it after failure. */
|
|
98
|
+
_bootTrace = [];
|
|
99
|
+
/** Last pure schema inspection, refreshed whenever the effective model changes. */
|
|
100
|
+
_schemaDiagnostics = {
|
|
101
|
+
valid: true,
|
|
102
|
+
errors: 0,
|
|
103
|
+
warnings: 0,
|
|
104
|
+
issues: []
|
|
105
|
+
};
|
|
106
|
+
/** Development signal for spotting repeated store subscriptions per collection. */
|
|
107
|
+
_storeAccessCounts = new Map();
|
|
36
108
|
/**
|
|
37
|
-
*
|
|
109
|
+
* Promise that resolves when boot() has completed.
|
|
110
|
+
* Use `await machine.ready` after createInstance() to ensure the machine is fully initialized.
|
|
38
111
|
*/
|
|
39
|
-
|
|
112
|
+
ready = Promise.resolve();
|
|
40
113
|
/**
|
|
41
114
|
* Main constructor
|
|
42
115
|
* @role Constructor
|
|
43
116
|
* @param {string=} dbName The name of the database.
|
|
44
117
|
* @param {number=} version The schema version number.
|
|
45
|
-
* @param {
|
|
118
|
+
* @param {MachineModel=} business The business data model.
|
|
46
119
|
*/
|
|
47
|
-
constructor(dbName, version,
|
|
48
|
-
this.
|
|
49
|
-
this._version = version ?? 1;
|
|
50
|
-
this._model = model ?? undefined;
|
|
120
|
+
constructor(dbName, version, business) {
|
|
121
|
+
this.init({ dbName, version, business });
|
|
51
122
|
}
|
|
52
123
|
/**
|
|
53
124
|
* Initialize the machine with configuration parameters.
|
|
125
|
+
* dbName is derived from org+domain when both are provided and no explicit dbName is given.
|
|
54
126
|
* @role Initializer
|
|
55
|
-
* @param {{ dbName?: string; version?: number; model: IdbqModel }} [options] Optional parameters to set dbName, version, and model.
|
|
56
|
-
* @return {void}
|
|
57
127
|
*/
|
|
58
128
|
init(options) {
|
|
59
|
-
|
|
129
|
+
if (options?.org)
|
|
130
|
+
this._org = options.org;
|
|
131
|
+
if (options?.domain)
|
|
132
|
+
this._domain = options.domain;
|
|
133
|
+
const derived = this._org && this._domain ? `${this._org}_${this._domain}` : undefined;
|
|
134
|
+
this._dbName = options?.dbName ?? derived ?? this._dbName;
|
|
60
135
|
this._version = options?.version ?? this._version;
|
|
61
|
-
this.
|
|
136
|
+
this._core = options?.core ?? this._core;
|
|
137
|
+
this._business = options?.business ?? this._business;
|
|
138
|
+
this._syncOptions = options?.sync !== undefined ? options.sync : this._syncOptions;
|
|
139
|
+
this._stateEngine = options?.stateEngine ?? this._stateEngine;
|
|
140
|
+
this._hooks = options?.hooks ?? this._hooks;
|
|
141
|
+
this._seed = options?.seed ?? this._seed;
|
|
62
142
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
143
|
+
/** Fully qualified DB name for a given base: {org}_{base} */
|
|
144
|
+
moduleDbName(base) {
|
|
145
|
+
return this._org ? `${this._org}_${base}` : base;
|
|
146
|
+
}
|
|
147
|
+
markBoot(phase, status, detail) {
|
|
148
|
+
this._bootTrace.push({
|
|
149
|
+
phase,
|
|
150
|
+
status,
|
|
151
|
+
at: new Date().toISOString(),
|
|
152
|
+
...(detail ? { detail } : {})
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
get bootTrace() {
|
|
156
|
+
return this._bootTrace;
|
|
157
|
+
}
|
|
158
|
+
get schemaDiagnostics() {
|
|
159
|
+
return this._schemaDiagnostics;
|
|
160
|
+
}
|
|
161
|
+
get storeDiagnostics() {
|
|
162
|
+
return [...this._storeAccessCounts.entries()]
|
|
163
|
+
.map(([collection, calls]) => ({ collection, calls }))
|
|
164
|
+
.sort((left, right) => right.calls - left.calls);
|
|
165
|
+
}
|
|
166
|
+
/** Pending IDB upgrade scheduled by drift detection — consumed by next createStore(). */
|
|
167
|
+
_pendingIdbUpgrade = null;
|
|
168
|
+
async createStore(replaceExisting = false) {
|
|
169
|
+
// Capture pending upgrade: performIdbUpgrade handles renames/deletions only
|
|
170
|
+
// (pure-creation is skipped — qoolie's versioned open creates those stores).
|
|
171
|
+
const pending = this._pendingIdbUpgrade;
|
|
172
|
+
if (pending) {
|
|
173
|
+
await performIdbUpgrade(this._dbName, this._version, pending, this._effectiveModel);
|
|
174
|
+
this._pendingIdbUpgrade = null;
|
|
175
|
+
}
|
|
176
|
+
if (replaceExisting) {
|
|
177
|
+
this._qoolie?.destroy();
|
|
178
|
+
this._qoolie = undefined;
|
|
179
|
+
}
|
|
180
|
+
const collections = Object.fromEntries([
|
|
181
|
+
...Object.entries(this._effectiveModel).map(([name, col]) => [
|
|
182
|
+
name,
|
|
183
|
+
{ keyPath: col.keyPath ?? '++id' }
|
|
184
|
+
]),
|
|
185
|
+
['__schema_meta__', { keyPath: 'id' }]
|
|
186
|
+
]);
|
|
187
|
+
this._qoolie = createQoolie({
|
|
188
|
+
dbName: this._dbName,
|
|
189
|
+
dbVersion: this._version,
|
|
190
|
+
collections,
|
|
191
|
+
...(this._syncOptions !== undefined && { sync: this._syncOptions }),
|
|
192
|
+
...(this._stateEngine !== undefined && { stateEngine: this._stateEngine }),
|
|
193
|
+
...(this._hooks !== undefined && { hooks: this._hooks })
|
|
194
|
+
});
|
|
195
|
+
// Persist the schema hash AFTER qoolie's open created __schema_meta__.
|
|
196
|
+
// Doing this inside performIdbUpgrade (which runs before createQoolie) fails
|
|
197
|
+
// with "__schema_meta__ store not found" — the store does not exist yet.
|
|
198
|
+
if (pending) {
|
|
199
|
+
await withTimeout(this._qoolie.ready(), 20000, 'qoolie.ready');
|
|
200
|
+
await storeSchemaHash(this._dbName, pending.expectedHash).catch((err) => {
|
|
201
|
+
console.warn('[idae-machine] Could not persist schema hash after store creation (will retry next boot):', err);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async _scheduleDrift() {
|
|
206
|
+
const drift = await detectSchemaDrift(this._dbName, this._version, this._effectiveModel);
|
|
207
|
+
if (drift) {
|
|
208
|
+
this._version = drift.newVersion;
|
|
209
|
+
this._pendingIdbUpgrade = drift;
|
|
210
|
+
}
|
|
72
211
|
}
|
|
73
212
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
213
|
+
* Shared model-rebuild sequence for both the initial boot path and the onDrift
|
|
214
|
+
* schema-reload path. Keeps the two callers in sync without duplication.
|
|
215
|
+
*
|
|
216
|
+
* replaceExisting=false → initial boot: read actual IDB version first (never downgrade).
|
|
217
|
+
* replaceExisting=true → schema drift reload: skip version check (already managed).
|
|
79
218
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
219
|
+
async _applyModel(replaceExisting) {
|
|
220
|
+
this._effectiveModel = buildEffectiveModel(this._core, this._business);
|
|
221
|
+
this._schemaDiagnostics = diagnoseMachineModel(this._effectiveModel);
|
|
222
|
+
this._machineDb = new MachineDb(this._effectiveModel);
|
|
223
|
+
machineRights.loadPoliciesFromModel(this._effectiveModel);
|
|
224
|
+
initializeDomainPoliciesWithModel(this._effectiveModel);
|
|
225
|
+
if (!replaceExisting) {
|
|
226
|
+
// Never downgrade IDB — adopt the actual on-disk version BEFORE drift detection
|
|
227
|
+
// so a drift-triggered bump lands ABOVE the existing version. Reading it after
|
|
228
|
+
// drift would clobber the bump (this._version = actual >= newVersion) and qoolie
|
|
229
|
+
// would reopen at the same version → onupgradeneeded never fires → stores from a
|
|
230
|
+
// corrupt/partial prior boot are never (re)created.
|
|
231
|
+
const actualVersion = await getActualIdbVersion(this._dbName).catch((err) => {
|
|
232
|
+
console.warn('[idae-machine] Could not read actual IDB version, defaulting to 0:', err);
|
|
233
|
+
return 0;
|
|
234
|
+
});
|
|
235
|
+
if (actualVersion > this._version)
|
|
236
|
+
this._version = actualVersion;
|
|
83
237
|
}
|
|
84
|
-
this.
|
|
238
|
+
await this._scheduleDrift();
|
|
239
|
+
await withTimeout(this.createStore(replaceExisting), 20000, replaceExisting ? 'createStore (schema drift)' : 'createStore');
|
|
240
|
+
initializeDomainPoliciesWithMachine(this);
|
|
85
241
|
}
|
|
86
242
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @role Internal
|
|
90
|
-
* @private
|
|
91
|
-
* @return {void}
|
|
243
|
+
* @framework-bootstrap — called automatically during boot().
|
|
244
|
+
* Not for application code. Detects IDB drift and upgrades stores immediately.
|
|
92
245
|
*/
|
|
93
|
-
|
|
94
|
-
if (!this.
|
|
95
|
-
throw new Error(
|
|
246
|
+
async upgradeIdb() {
|
|
247
|
+
if (!this._dbName || !this._effectiveModel) {
|
|
248
|
+
throw new Error('Machine not initialized — call init() and start() first');
|
|
249
|
+
}
|
|
250
|
+
const drift = await detectSchemaDrift(this._dbName, this._version, this._effectiveModel);
|
|
251
|
+
if (drift) {
|
|
252
|
+
this._version = drift.newVersion;
|
|
253
|
+
await performIdbUpgrade(this._dbName, this._version, drift, this._effectiveModel);
|
|
96
254
|
}
|
|
97
|
-
const idbqStore = createIdbqDb(this._model, this._version);
|
|
98
|
-
const { idbql, idbqlState, idbDatabase, idbqModel } = idbqStore.create(this._dbName);
|
|
99
|
-
this._idbql = idbql;
|
|
100
|
-
this._idbqlState = idbqlState;
|
|
101
|
-
this._idbDatabase = idbDatabase;
|
|
102
|
-
this._idbqModel = idbqModel;
|
|
103
|
-
console.log("Machine started with DB:", this._dbName, "Version:", this._version);
|
|
104
|
-
console.log("IDBQL State Instance:", this._idbqlState);
|
|
105
255
|
}
|
|
106
256
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
257
|
+
* Atomic boot — single async entry point for the app shell.
|
|
258
|
+
*
|
|
259
|
+
* Resolves the schema (server or local), builds MachineDb, adapts IDB drift,
|
|
260
|
+
* creates the qoolie store. Returns only once `machine.logic` + `machine.store`
|
|
261
|
+
* are ready. UI must `await machine.boot(...)` before mounting machine-aware
|
|
262
|
+
* components — no partial render, no reactivity races.
|
|
263
|
+
*
|
|
264
|
+
* Data hydration (IDB ← server) is owned by qoolie's sync layer, not by boot.
|
|
265
|
+
*
|
|
266
|
+
* @param options - Same shape as init(); typically { org, domain, version, sync }.
|
|
267
|
+
* @throws If sync is enabled but schema is unavailable (no cache, no network, no local model).
|
|
111
268
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
269
|
+
async boot(options) {
|
|
270
|
+
this._bootTrace = [];
|
|
271
|
+
this._storeAccessCounts.clear();
|
|
272
|
+
this.markBoot('boot', 'start');
|
|
273
|
+
try {
|
|
274
|
+
if (options)
|
|
275
|
+
this.init(options);
|
|
276
|
+
if (!this._dbName)
|
|
277
|
+
throw new Error('dbName is required — call machine.boot({ org, domain }) or machine.init({ dbName }) first');
|
|
278
|
+
if (this._qoolie) {
|
|
279
|
+
this._qoolie.destroy();
|
|
280
|
+
this._qoolie = undefined;
|
|
281
|
+
}
|
|
282
|
+
const dbHost = this._syncOptions && typeof this._syncOptions === 'object'
|
|
283
|
+
? this._syncOptions.databaseHost
|
|
284
|
+
: undefined;
|
|
285
|
+
this.markBoot('schema', 'start', dbHost ? 'remote' : 'local');
|
|
286
|
+
if (dbHost) {
|
|
287
|
+
const orgQs = this._org ? `?org=${encodeURIComponent(this._org)}` : '';
|
|
288
|
+
const url = dbHost.replace(/\/+$/, '') + '/api/scheme' + orgQs;
|
|
289
|
+
const { loadSchema } = await import('./machineSchemaLoader.js');
|
|
290
|
+
await loadSchema(url, {
|
|
291
|
+
onModel: (model) => {
|
|
292
|
+
this._business = model;
|
|
293
|
+
},
|
|
294
|
+
onStart: () => { },
|
|
295
|
+
onDrift: async () => {
|
|
296
|
+
await this._applyModel(true);
|
|
297
|
+
}
|
|
298
|
+
}).catch((err) => {
|
|
299
|
+
if (!this._business)
|
|
300
|
+
throw err;
|
|
301
|
+
console.warn('[idae-machine] Schema fetch failed, continuing with local model:', err);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
this.markBoot('schema', 'done');
|
|
305
|
+
this.markBoot('model', 'start');
|
|
306
|
+
this.markBoot('storage', 'start');
|
|
307
|
+
await this._applyModel(false);
|
|
308
|
+
this.markBoot('model', 'done', `${Object.keys(this._effectiveModel).length} collections, ${this._schemaDiagnostics.issues.length} diagnostics`);
|
|
309
|
+
this.markBoot('storage', 'done', this._dbName);
|
|
310
|
+
this.markBoot('frames', 'start');
|
|
311
|
+
frameCatalog.registerFrames(componentRegistry);
|
|
312
|
+
this.markBoot('frames', 'done', `${componentRegistry.keys().length} frames`);
|
|
313
|
+
const syncMode = this._syncOptions && typeof this._syncOptions === 'object'
|
|
314
|
+
? this._syncOptions.mode
|
|
315
|
+
: undefined;
|
|
316
|
+
if (syncMode === 'mobile-first' && this._seed) {
|
|
317
|
+
this.markBoot('seed', 'start');
|
|
318
|
+
const { seed } = await import('./machineSeed.js');
|
|
319
|
+
await seed(this._seed, { onlyIfEmpty: true });
|
|
320
|
+
this.markBoot('seed', 'done');
|
|
321
|
+
}
|
|
322
|
+
this.markBoot('ui', 'start');
|
|
323
|
+
const { setupContextMenuListener } = await import('./frame/contextMenuSetup.js');
|
|
324
|
+
this._contextMenuCleanup = setupContextMenuListener(this._frameManager);
|
|
325
|
+
this.markBoot('ui', 'done');
|
|
326
|
+
this.markBoot('boot', 'done');
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
this.markBoot('boot', 'error', error instanceof Error ? error.message : String(error));
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
114
332
|
}
|
|
115
333
|
/**
|
|
116
334
|
* Get the IDbBase (schema logic) instance.
|
|
@@ -122,50 +340,218 @@ export class Machine {
|
|
|
122
340
|
return this._machineDb;
|
|
123
341
|
}
|
|
124
342
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
343
|
+
* Reactive collection reader — returns live-updating { records } via Svelte 5 runes.
|
|
344
|
+
* `records` is a ResultSet<T> (array + .sortBy/.groupBy/.getPage/.distinct/…).
|
|
345
|
+
* Usage: const { records } = machine.store('users');
|
|
346
|
+
* const { records } = machine.store('users', { status: 'active' });
|
|
347
|
+
*
|
|
348
|
+
* Must be called from within a Svelte component or .svelte.ts context.
|
|
349
|
+
* For imperative CRUD use machine.collection(name) instead.
|
|
129
350
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
351
|
+
store(name, query) {
|
|
352
|
+
if (!this._qoolie || !name)
|
|
353
|
+
return { records: [] };
|
|
354
|
+
this._storeAccessCounts.set(name, (this._storeAccessCounts.get(name) ?? 0) + 1);
|
|
355
|
+
const src = query
|
|
356
|
+
? useQoolieQuery(this._qoolie, name, query)
|
|
357
|
+
: useQoolieCollection(this._qoolie, name);
|
|
358
|
+
// ⚠️ Return a getter, never `{ records: src.items }`. Reading `src.items`
|
|
359
|
+
// eagerly here snapshots it OUTSIDE any reactive frame → no dependency is
|
|
360
|
+
// tracked → consumers never update. The getter defers the read to the
|
|
361
|
+
// consumer's $derived/$effect, where Svelte can track it. Likewise do not
|
|
362
|
+
// "flatten" store() to return the array directly: the underlying $state
|
|
363
|
+
// binding in the qoolie adapter is reassigned, so only a getter sees fresh
|
|
364
|
+
// values. This indirection looks redundant but is load-bearing.
|
|
365
|
+
return {
|
|
366
|
+
get records() {
|
|
367
|
+
return src.items;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
132
370
|
}
|
|
133
371
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
372
|
+
* Direct collection accessor — returns the QoolieCollection for CRUD ops, with
|
|
373
|
+
* create/update/updateWhere wrapped to denormalize FK target snapshots into
|
|
374
|
+
* `record.fks.<field>` before persisting (single write choke-point — see
|
|
375
|
+
* MachineFkFold). Every other method forwards untouched.
|
|
376
|
+
* Usage: await machine.collection('users').create(data)
|
|
377
|
+
* await machine.collection('users').get(id)
|
|
378
|
+
* Note: machine.logic.collection(name) returns the MachineScheme (schema layer).
|
|
379
|
+
*/
|
|
380
|
+
collection(name) {
|
|
381
|
+
const col = this._qoolie?.collection?.[name];
|
|
382
|
+
if (!col)
|
|
383
|
+
throw new Error(`Collection "${name}" not found. Did you call boot()?`);
|
|
384
|
+
return wrapCollectionFkFold(this._machineDb, this._qoolie, name, col);
|
|
385
|
+
}
|
|
386
|
+
/** Access rights manager — checkAccess, setCurrentUser, setPolicies, etc. */
|
|
387
|
+
get rights() {
|
|
388
|
+
return machineRights;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Generic write dispatcher — `machine.action(collection, vars, opts?)`.
|
|
392
|
+
* One imperative entry point for every user-scoped write (prefs, history, activity, …).
|
|
393
|
+
* Auto-injects `userId` + `id`. Use opts for upsert / bump / touch / code-template behavior.
|
|
138
394
|
*/
|
|
139
|
-
get
|
|
140
|
-
return
|
|
395
|
+
get action() {
|
|
396
|
+
return machineActionCallable;
|
|
141
397
|
}
|
|
142
398
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
399
|
+
* Sync controller — pause/resume/status/flush/dlq.
|
|
400
|
+
* Only available when sync is enabled in init() options.
|
|
401
|
+
*/
|
|
402
|
+
get sync() {
|
|
403
|
+
if (!this._qoolie)
|
|
404
|
+
throw new Error('Machine not started. Call boot() first.');
|
|
405
|
+
return this._qoolie.sync;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Socket client — EventDataClientInstance from idae-socket, owned by qoolie's
|
|
409
|
+
* push listener (single connection). Available when `sync.push.protocol === 'socketio'`
|
|
410
|
+
* and the listener has connected. Configure via `init({ sync: { push: { protocol: 'socketio', ... } } })`.
|
|
411
|
+
*/
|
|
412
|
+
get socket() {
|
|
413
|
+
if (!this._qoolie)
|
|
414
|
+
return undefined;
|
|
415
|
+
let pushListener;
|
|
416
|
+
try {
|
|
417
|
+
pushListener = this._qoolie.sync.getPushListener?.();
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
const inner = pushListener?.getListener?.() ??
|
|
423
|
+
pushListener;
|
|
424
|
+
return inner?.getClient?.();
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Release all Qoolie resources (stops sync adapter, clears collections).
|
|
428
|
+
* Call when the Machine instance is no longer needed.
|
|
148
429
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
430
|
+
destroy() {
|
|
431
|
+
this._qoolie?.destroy();
|
|
432
|
+
this._qoolie = undefined;
|
|
433
|
+
this._pendingIdbUpgrade = null;
|
|
434
|
+
this._contextMenuCleanup?.();
|
|
435
|
+
this._contextMenuCleanup = undefined;
|
|
436
|
+
}
|
|
437
|
+
/** Pre-fetch collections into IDB before UI renders. Derives list from model when not provided. */
|
|
438
|
+
async warmup(collections) {
|
|
439
|
+
if (!this._qoolie)
|
|
440
|
+
return;
|
|
441
|
+
const { warmup: doWarmup } = await import('./warmupUtils.js');
|
|
442
|
+
await doWarmup(this._qoolie, this._effectiveModel, collections);
|
|
443
|
+
}
|
|
444
|
+
async resetClientData() {
|
|
445
|
+
this.destroy();
|
|
446
|
+
await deleteIdbDatabase(this._dbName);
|
|
447
|
+
const { clearSchemaCache } = await import('./machineSchemaCache.js');
|
|
448
|
+
await clearSchemaCache();
|
|
449
|
+
window.location.reload();
|
|
151
450
|
}
|
|
152
451
|
/**
|
|
153
|
-
* Get the
|
|
452
|
+
* Get or create the MachineRouter instance (lazy).
|
|
154
453
|
* @role Accessor
|
|
155
|
-
* @
|
|
156
|
-
* @return {ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbDatabase"] | undefined} The IndexedDB instance.
|
|
454
|
+
* @return {MachineRouter} The machine router instance.
|
|
157
455
|
*/
|
|
158
|
-
get
|
|
159
|
-
|
|
456
|
+
get router() {
|
|
457
|
+
if (!this._router)
|
|
458
|
+
this._router = this._buildRouter();
|
|
459
|
+
return this._router;
|
|
460
|
+
}
|
|
461
|
+
initRouter(config) {
|
|
462
|
+
this._router = this._buildRouter(config);
|
|
463
|
+
return this._router;
|
|
464
|
+
}
|
|
465
|
+
_buildRouter(config = {}) {
|
|
466
|
+
const r = new MachineRouter(config);
|
|
467
|
+
r.init();
|
|
468
|
+
this._frameManager.setRouter({
|
|
469
|
+
push: (url) => r.push(url),
|
|
470
|
+
openFrame: (event) => r.openFrame(event),
|
|
471
|
+
openDialog: (event) => r.openDialog(event),
|
|
472
|
+
closeFrame: (frameId) => r.closeFrame(frameId)
|
|
473
|
+
});
|
|
474
|
+
setupNavigationTracking(this._frameManager, (col, id) => this._renderLabel(col, id));
|
|
475
|
+
return r;
|
|
476
|
+
}
|
|
477
|
+
/** Compute a record label from `template.presentation`. Used by nav history writes and dialog titles. @internal */
|
|
478
|
+
async _renderLabel(collection, collectionId) {
|
|
479
|
+
const { renderLabel } = await import('./machine/machineLabel.js');
|
|
480
|
+
return renderLabel(this._machineDb, async (col, id) => this.collection(col).get(id), collection, collectionId);
|
|
481
|
+
}
|
|
482
|
+
/** Access to the frame manager singleton. */
|
|
483
|
+
get framer() {
|
|
484
|
+
return this._frameManager;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Access to the menu manager. Created lazily. Snapshot reader wired on first
|
|
488
|
+
* access so `getTree`/`getFlatItems`/`isVisible` read live appuser_prefs/
|
|
489
|
+
* appscheme/appscheme_type via machine.store (reactive read layer) instead of
|
|
490
|
+
* staying empty forever. Component-level reactivity belongs in
|
|
491
|
+
* useMenuTree.svelte.ts, not here — this getter only guarantees the manager
|
|
492
|
+
* is never wired to stale/empty data.
|
|
493
|
+
*/
|
|
494
|
+
get menu() {
|
|
495
|
+
if (!this._menuManager) {
|
|
496
|
+
this._menuManager = createMenuManager(this._frameManager, this.rights, this);
|
|
497
|
+
}
|
|
498
|
+
return this._menuManager;
|
|
499
|
+
}
|
|
500
|
+
/** Access to the component registry singleton. */
|
|
501
|
+
get componentRegistry() {
|
|
502
|
+
return machineComponentRegistry;
|
|
503
|
+
}
|
|
504
|
+
/** DOM manipulation utility — wraps @medyll/idae-be. Usage: machine.be('#el').addClass('active') */
|
|
505
|
+
get be() {
|
|
506
|
+
return _be;
|
|
160
507
|
}
|
|
161
508
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
509
|
+
* Create and register a new Machine instance.
|
|
510
|
+
* Registers the instance in the static registry for later retrieval.
|
|
511
|
+
* @role Factory method
|
|
512
|
+
* @param {string} [instanceName] Optional name to register the instance under.
|
|
513
|
+
* @param {string} [dbName] Database name for the new instance.
|
|
514
|
+
* @param {number} [version] Schema version for the new instance.
|
|
515
|
+
* @param {MachineModel} [business] Business data model for the new instance.
|
|
516
|
+
* @returns {Machine} The newly created and started Machine instance.
|
|
517
|
+
*/
|
|
518
|
+
createInstance(instanceName, dbName, version, business) {
|
|
519
|
+
const instance = new Machine();
|
|
520
|
+
instance.init({ dbName, version, business });
|
|
521
|
+
if (instanceName) {
|
|
522
|
+
instance.instanceName = instanceName;
|
|
523
|
+
Machine.instanceRegistry[instanceName] = instance;
|
|
524
|
+
}
|
|
525
|
+
instance.ready = instance.boot();
|
|
526
|
+
return instance;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Get a Machine instance by name from the registry.
|
|
164
530
|
* @role Accessor
|
|
165
|
-
* @
|
|
531
|
+
* @param {string} instanceName The name of the instance.
|
|
532
|
+
* @return {Machine | undefined} The Machine instance, or undefined if not found.
|
|
166
533
|
*/
|
|
167
|
-
|
|
168
|
-
return
|
|
534
|
+
static instance(instanceName) {
|
|
535
|
+
return Machine.instanceRegistry[instanceName];
|
|
169
536
|
}
|
|
170
537
|
}
|
|
171
|
-
export
|
|
538
|
+
export { buildLoadInUrl } from './frame/frameUrl.js';
|
|
539
|
+
const _g = globalThis;
|
|
540
|
+
export const machine = _g.__idae_machine ?? (_g.__idae_machine = new Machine());
|
|
541
|
+
// Wire MachineAction with a host that resolves the current user + collections lazily.
|
|
542
|
+
// Avoids importing `machine` from inside MachineAction.ts (which would create a cycle).
|
|
543
|
+
machineAction.setHost({
|
|
544
|
+
currentUserId: () => (machine.rights.currentUser ? String(machine.rights.currentUser.id) : null),
|
|
545
|
+
collection: (name) => {
|
|
546
|
+
try {
|
|
547
|
+
return machine.collection(name);
|
|
548
|
+
}
|
|
549
|
+
catch {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
// Wire dialog/frame titles to record presentation labels (lazy — avoids init ordering).
|
|
555
|
+
machineFrameManager.setLabelResolver((col, id) => id ? machine._renderLabel(col, id) : Promise.resolve(undefined));
|
|
556
|
+
if (import.meta.hot)
|
|
557
|
+
import.meta.hot.accept();
|