@medyll/idae-machine 0.129.0 → 0.136.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +462 -300
- 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/data-ui/field/DataFieldEdit.svelte +103 -0
- package/dist/data-ui/field/DataFieldEdit.svelte.d.ts +14 -0
- 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 +3 -3
- 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 -43
- package/dist/index.js +82 -44
- 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.d.ts +33 -0
- package/dist/main/machine/MachineError.js +49 -0
- package/dist/main/machine/MachineErrorValidation.d.ts +19 -0
- package/dist/main/machine/MachineErrorValidation.js +24 -0
- package/dist/main/machine/MachineFieldType.d.ts +140 -0
- package/dist/main/machine/MachineFieldType.js +341 -0
- 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 +54 -0
- package/dist/main/machine/MachineScheme.js +159 -0
- package/dist/main/machine/MachineSchemeField.js +67 -0
- package/dist/main/machine/MachineSchemeFieldForge.d.ts +84 -0
- package/dist/main/machine/MachineSchemeFieldForge.js +140 -0
- package/dist/main/machine/MachineSchemeFieldValues.d.ts +68 -0
- package/dist/main/machine/MachineSchemeFieldValues.js +97 -0
- package/dist/main/machine/MachineSchemeValidate.d.ts +107 -0
- package/dist/main/machine/MachineSchemeValidate.js +247 -0
- package/dist/main/machine/MachineSchemeValues.d.ts +120 -0
- package/dist/main/machine/MachineSchemeValues.js +306 -0
- package/dist/main/machine/SchemeFieldDefaultValues.d.ts +76 -0
- package/dist/main/machine/SchemeFieldDefaultValues.js +104 -0
- 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 +227 -61
- package/dist/main/machine.js +503 -86
- package/dist/main/machineDb.d.ts +25 -54
- package/dist/main/machineDb.js +40 -94
- 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 +38 -0
- package/dist/main/machineParserForge.js +168 -0
- 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 +70 -31
- package/dist/db/CrudService.d.ts +0 -9
- package/dist/db/CrudService.js +0 -45
- package/dist/db/dbSchema.d.ts +0 -201
- package/dist/db/dbSchema.js +0 -205
- package/dist/db/fieldTypes.d.ts +0 -13
- package/dist/db/fieldTypes.js +0 -67
- package/dist/db/types.d.ts +0 -124
- package/dist/demo/form/CreateUpdate.svelte +0 -198
- package/dist/demo/form/CreateUpdate.svelte.d.ts +0 -29
- package/dist/demo/form/CrudZone.svelte +0 -22
- package/dist/demo/form/CrudZone.svelte.d.ts +0 -29
- package/dist/demo/form/DataProvider.svelte +0 -20
- package/dist/demo/form/DataProvider.svelte.d.ts +0 -9
- package/dist/demo/form/FieldInPlace.svelte +0 -49
- package/dist/demo/form/FieldInPlace.svelte.d.ts +0 -11
- package/dist/demo/form/FieldValue.svelte +0 -212
- package/dist/demo/form/FieldValue.svelte.d.ts +0 -35
- package/dist/demo/form/types.d.ts +0 -17
- package/dist/demo/form/types.js +0 -1
- package/dist/demo/testDbSchema.d.ts +0 -6
- package/dist/demo/testDbSchema.js +0 -58
- package/dist/demo/types.d.ts +0 -140
- package/dist/demo/types.js +0 -1
- package/dist/fragments/Confirm.svelte +0 -58
- package/dist/fragments/Confirm.svelte.d.ts +0 -11
- 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/List.svelte +0 -21
- package/dist/fragments/List.svelte.d.ts +0 -38
- package/dist/fragments/Selector.svelte +0 -26
- package/dist/fragments/Selector.svelte.d.ts +0 -38
- package/dist/main/machine/IDbCollection.d.ts +0 -69
- package/dist/main/machine/IDbCollection.js +0 -98
- package/dist/main/machine/IDbCollectionFieldForge.d.ts +0 -42
- package/dist/main/machine/IDbCollectionFieldForge.js +0 -74
- package/dist/main/machine/IDbCollectionFieldValues.d.ts +0 -46
- package/dist/main/machine/IDbCollectionFieldValues.js +0 -62
- package/dist/main/machine/IDbCollectionValues.d.ts +0 -78
- package/dist/main/machine/IDbCollectionValues.js +0 -203
- package/dist/main/machine/IDbError.d.ts +0 -6
- package/dist/main/machine/IDbError.js +0 -61
- package/dist/main/machine/IDbFormValidate.d.ts +0 -55
- package/dist/main/machine/IDbFormValidate.js +0 -183
- package/dist/main/machine/IDbValidationError.d.ts +0 -19
- package/dist/main/machine/IDbValidationError.js +0 -24
- package/dist/main/machine/types.d.ts +0 -1
- package/dist/main/machine/types.js +0 -1
- package/dist/main/machineForge.d.ts +0 -57
- package/dist/main/machineForge.js +0 -105
- package/dist/types/appschemeTypes.d.ts +0 -71
- package/dist/types/appschemeTypes.js +0 -83
- package/dist/ui/CollectionButton.svelte +0 -26
- package/dist/ui/CollectionButton.svelte.d.ts +0 -29
- package/dist/ui/CollectionFieldGuess.svelte +0 -29
- package/dist/ui/CollectionFieldGuess.svelte.d.ts +0 -11
- package/dist/ui/CollectionFks.svelte +0 -24
- package/dist/ui/CollectionFks.svelte.d.ts +0 -9
- package/dist/ui/CollectionList.svelte +0 -95
- package/dist/ui/CollectionList.svelte.d.ts +0 -37
- package/dist/ui/CollectionListMenu.svelte +0 -47
- package/dist/ui/CollectionListMenu.svelte.d.ts +0 -34
- package/dist/ui/CollectionReverseFks.svelte +0 -56
- package/dist/ui/CollectionReverseFks.svelte.d.ts +0 -18
- /package/dist/{fragments → data-ui/fragments}/Skeleton.svelte.d.ts +0 -0
- /package/dist/{db → main/api}/types.js +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { MachineSchemeValues } from './MachineSchemeValues.js';
|
|
2
|
+
/**
|
|
3
|
+
* @class IDbCollectionFieldForge
|
|
4
|
+
* @role Provides advanced metadata and formatting for a single field of a collection, given a data object.
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* @template T The type of the data object for the collection.
|
|
8
|
+
*/
|
|
9
|
+
export class MachineSchemeFieldForge {
|
|
10
|
+
#collection;
|
|
11
|
+
#collectionValues;
|
|
12
|
+
#fieldName;
|
|
13
|
+
#data;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new IDbCollectionFieldForge instance.
|
|
16
|
+
* @role Constructor
|
|
17
|
+
* @param {TplCollectionName} collection The collection name.
|
|
18
|
+
* @param {keyof T | string} fieldName The field name.
|
|
19
|
+
* @param {T} data The data object.
|
|
20
|
+
* @param {MachineSchemeValues<T>=} collectionValues Optional collection values instance.
|
|
21
|
+
*/
|
|
22
|
+
constructor(collection, fieldName, data, collectionValues, machineDb) {
|
|
23
|
+
this.#collection = collection;
|
|
24
|
+
this.#collectionValues = collectionValues ?? new MachineSchemeValues(collection, machineDb);
|
|
25
|
+
this.#fieldName = String(fieldName);
|
|
26
|
+
this.#data = data;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the formatted value for the field.
|
|
30
|
+
* @role Field formatting
|
|
31
|
+
* @return {string} The formatted value for display.
|
|
32
|
+
*/
|
|
33
|
+
get format() {
|
|
34
|
+
return this.#collectionValues.format(String(this.#fieldName), this.#data);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get input attributes for the field.
|
|
38
|
+
* @role Input attribute generation
|
|
39
|
+
* @return {any} The input attributes for the field.
|
|
40
|
+
*/
|
|
41
|
+
get inputDataSet() {
|
|
42
|
+
return this.#collectionValues.getInputDataSet(String(this.#fieldName), this.#data);
|
|
43
|
+
}
|
|
44
|
+
// renamed from parseCollectionFieldName
|
|
45
|
+
/**
|
|
46
|
+
* Get the parsed field metadata (IDbForge) for the field.
|
|
47
|
+
* @role Field metadata accessor
|
|
48
|
+
* @return {IDbForge | undefined} The field metadata object or undefined.
|
|
49
|
+
*/
|
|
50
|
+
get forge() {
|
|
51
|
+
return this.#collectionValues.machine
|
|
52
|
+
.collection(this.#collection)
|
|
53
|
+
.field(String(this.#fieldName))
|
|
54
|
+
.parse();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the field arguments for the field.
|
|
58
|
+
* @role Field argument accessor
|
|
59
|
+
* @return {TplFieldArgs | undefined} The field arguments or undefined.
|
|
60
|
+
*/
|
|
61
|
+
get fieldArgs() {
|
|
62
|
+
return this.forge?.fieldArgs;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the field type for the field.
|
|
66
|
+
* @role Field type accessor
|
|
67
|
+
* @return {TplFieldType | undefined} The field type or undefined.
|
|
68
|
+
*/
|
|
69
|
+
get fieldType() {
|
|
70
|
+
return this.forge?.fieldType;
|
|
71
|
+
}
|
|
72
|
+
get inputSize() {
|
|
73
|
+
if (this.forge?.inputSize)
|
|
74
|
+
return this.forge.inputSize;
|
|
75
|
+
const ft = this.forge?.fieldType ?? '';
|
|
76
|
+
if (ft === 'text-area' || ft === 'text-full')
|
|
77
|
+
return 'full';
|
|
78
|
+
if (ft === 'text-xs')
|
|
79
|
+
return 'xs';
|
|
80
|
+
if (ft === 'text-sm')
|
|
81
|
+
return 'sm';
|
|
82
|
+
if (ft === 'text-lg' || ft === 'text-long')
|
|
83
|
+
return 'lg';
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* will return text.inputBase for ['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password']
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Get the HTML input type for the field (for form generation).
|
|
91
|
+
* @role Input type accessor
|
|
92
|
+
* @return {string | 'text' | 'area'} The HTML input type.
|
|
93
|
+
*/
|
|
94
|
+
get htmlInputType() {
|
|
95
|
+
const ft = this.forge?.fieldType ?? '';
|
|
96
|
+
if (ft === 'image')
|
|
97
|
+
return 'file';
|
|
98
|
+
if (ft === 'color')
|
|
99
|
+
return 'color';
|
|
100
|
+
if (ft === 'icon')
|
|
101
|
+
return 'icon';
|
|
102
|
+
const variant = ft.split('text-')?.[1] ?? ft;
|
|
103
|
+
if (variant === 'area')
|
|
104
|
+
return variant;
|
|
105
|
+
if (ft.startsWith('text-'))
|
|
106
|
+
return 'text';
|
|
107
|
+
if (['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password'].includes(ft)) {
|
|
108
|
+
return ft.trim() || 'text';
|
|
109
|
+
}
|
|
110
|
+
return 'text';
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the raw data object for the field.
|
|
114
|
+
* @role Data accessor
|
|
115
|
+
* @return {T} The raw data object.
|
|
116
|
+
*/
|
|
117
|
+
get rawData() {
|
|
118
|
+
return this.#data;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Iterate over an array field and return field metadata for each item.
|
|
122
|
+
* @role Array field iteration
|
|
123
|
+
* @param {string} fieldName The field name.
|
|
124
|
+
* @param {any[]} data The array data.
|
|
125
|
+
* @return {IDbForge[]} Array of field metadata objects for each item.
|
|
126
|
+
*/
|
|
127
|
+
iterateArray(fieldName, data) {
|
|
128
|
+
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Iterate over an object field and return field metadata for each property.
|
|
132
|
+
* @role Object field iteration
|
|
133
|
+
* @param {string} fieldName The field name.
|
|
134
|
+
* @param {Record<string, unknown>} data The object data.
|
|
135
|
+
* @return {IDbForge[]} Array of field metadata objects for each property.
|
|
136
|
+
*/
|
|
137
|
+
iterateObject(fieldName, data) {
|
|
138
|
+
return this.#collectionValues.iterateObjectField(fieldName, data);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TplCollectionName, IDbForge } from '../../types/index.js';
|
|
2
|
+
import { MachineSchemeValues } from './MachineSchemeValues.js';
|
|
3
|
+
/**
|
|
4
|
+
* @class MachineSchemeFieldValues
|
|
5
|
+
* @role Utility class for introspecting and formatting field values for a given collection and data object.
|
|
6
|
+
*
|
|
7
|
+
* Provides utilities to introspect and format field values for a given collection and data object.
|
|
8
|
+
*
|
|
9
|
+
* Main responsibilities:
|
|
10
|
+
* - Holds references to the collection, data, and collection values instance.
|
|
11
|
+
* - Provides methods to get field metadata, format values, and generate input attributes.
|
|
12
|
+
* - Supports iteration over array and object fields for advanced UI layouts.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const fieldValues = new MachineSchemeFieldValues('agents', agentData);
|
|
16
|
+
* const forge = fieldValues.getForge('name');
|
|
17
|
+
* const formatted = fieldValues.format('name');
|
|
18
|
+
*
|
|
19
|
+
* @template T The type of the data object for the collection.
|
|
20
|
+
*/
|
|
21
|
+
export declare class MachineSchemeFieldValues<T extends Record<string, unknown>> {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the IDbForge metadata for a given field name.
|
|
25
|
+
* @role Field metadata introspection
|
|
26
|
+
* @param {keyof T} fieldName The field name to introspect.
|
|
27
|
+
* @return {IDbForge | undefined} The field metadata object or undefined if not found.
|
|
28
|
+
*/
|
|
29
|
+
getForge(fieldName: keyof T): IDbForge | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Create a new IDbCollectionFieldValues instance.
|
|
32
|
+
* @role Constructor
|
|
33
|
+
* @param {TplCollectionName} collection The collection name.
|
|
34
|
+
* @param {T} data The data object.
|
|
35
|
+
* @param {MachineSchemeValues<T>=} collectionValues Optional IDbCollectionValues instance.
|
|
36
|
+
*/
|
|
37
|
+
constructor(collection: TplCollectionName, data: T, collectionValues?: MachineSchemeValues<T>);
|
|
38
|
+
/**
|
|
39
|
+
* Format the value of a field, handling arrays and objects.
|
|
40
|
+
* @role Field value formatting
|
|
41
|
+
* @param {keyof T} fieldName The field name.
|
|
42
|
+
* @return {string | string[]} The formatted value or array of formatted values.
|
|
43
|
+
*/
|
|
44
|
+
format(fieldName: keyof T): string | string[] | unknown[];
|
|
45
|
+
/**
|
|
46
|
+
* Get input attributes for a field.
|
|
47
|
+
* @role Input attribute generation
|
|
48
|
+
* @param {keyof T} fieldName The field name.
|
|
49
|
+
* @return {any} The input attributes for the field.
|
|
50
|
+
*/
|
|
51
|
+
getInputDataSet(fieldName: keyof T): Record<string, unknown> | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Iterate over an array field and return field metadata for each item.
|
|
54
|
+
* @role Array field iteration
|
|
55
|
+
* @param {string} fieldName The field name.
|
|
56
|
+
* @param {any[]} data The array data.
|
|
57
|
+
* @return {IDbForge[]} Array of field metadata objects for each item.
|
|
58
|
+
*/
|
|
59
|
+
iterateArray(fieldName: string, data: unknown[]): unknown[];
|
|
60
|
+
/**
|
|
61
|
+
* Iterate over an object field and return field metadata for each property.
|
|
62
|
+
* @role Object field iteration
|
|
63
|
+
* @param {string} fieldName The field name.
|
|
64
|
+
* @param {Record<string, unknown>} data The object data.
|
|
65
|
+
* @return {IDbForge[]} Array of field metadata objects for each property.
|
|
66
|
+
*/
|
|
67
|
+
iterateObject(fieldName: string, data: Record<string, unknown>): IDbForge[];
|
|
68
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { MachineSchemeValues } from './MachineSchemeValues.js';
|
|
2
|
+
import { machine } from '../machine.js';
|
|
3
|
+
/**
|
|
4
|
+
* @class MachineSchemeFieldValues
|
|
5
|
+
* @role Utility class for introspecting and formatting field values for a given collection and data object.
|
|
6
|
+
*
|
|
7
|
+
* Provides utilities to introspect and format field values for a given collection and data object.
|
|
8
|
+
*
|
|
9
|
+
* Main responsibilities:
|
|
10
|
+
* - Holds references to the collection, data, and collection values instance.
|
|
11
|
+
* - Provides methods to get field metadata, format values, and generate input attributes.
|
|
12
|
+
* - Supports iteration over array and object fields for advanced UI layouts.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const fieldValues = new MachineSchemeFieldValues('agents', agentData);
|
|
16
|
+
* const forge = fieldValues.getForge('name');
|
|
17
|
+
* const formatted = fieldValues.format('name');
|
|
18
|
+
*
|
|
19
|
+
* @template T The type of the data object for the collection.
|
|
20
|
+
*/
|
|
21
|
+
export class MachineSchemeFieldValues {
|
|
22
|
+
#collection;
|
|
23
|
+
#collectionValues;
|
|
24
|
+
#data;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the IDbForge metadata for a given field name.
|
|
27
|
+
* @role Field metadata introspection
|
|
28
|
+
* @param {keyof T} fieldName The field name to introspect.
|
|
29
|
+
* @return {IDbForge | undefined} The field metadata object or undefined if not found.
|
|
30
|
+
*/
|
|
31
|
+
getForge(fieldName) {
|
|
32
|
+
return this.#collectionValues.machine
|
|
33
|
+
.collection(this.#collection)
|
|
34
|
+
.field(String(fieldName))
|
|
35
|
+
.parse();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a new IDbCollectionFieldValues instance.
|
|
39
|
+
* @role Constructor
|
|
40
|
+
* @param {TplCollectionName} collection The collection name.
|
|
41
|
+
* @param {T} data The data object.
|
|
42
|
+
* @param {MachineSchemeValues<T>=} collectionValues Optional IDbCollectionValues instance.
|
|
43
|
+
*/
|
|
44
|
+
constructor(collection, data, collectionValues) {
|
|
45
|
+
this.#collection = collection;
|
|
46
|
+
this.#collectionValues = collectionValues ?? new MachineSchemeValues(collection, machine.logic);
|
|
47
|
+
this.#data = data;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Format the value of a field, handling arrays and objects.
|
|
51
|
+
* @role Field value formatting
|
|
52
|
+
* @param {keyof T} fieldName The field name.
|
|
53
|
+
* @return {string | string[]} The formatted value or array of formatted values.
|
|
54
|
+
*/
|
|
55
|
+
format(fieldName) {
|
|
56
|
+
const fieldInfo = this.#collectionValues.machine
|
|
57
|
+
.collection(this.#collection)
|
|
58
|
+
.field(String(fieldName))
|
|
59
|
+
.parse();
|
|
60
|
+
if (fieldInfo?.is === 'array') {
|
|
61
|
+
return this.iterateArray(String(fieldName), this.#data);
|
|
62
|
+
}
|
|
63
|
+
if (fieldInfo?.is === 'object') {
|
|
64
|
+
return this.iterateObject(String(fieldName), this.#data);
|
|
65
|
+
}
|
|
66
|
+
return this.#collectionValues.format(fieldName, this.#data);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get input attributes for a field.
|
|
70
|
+
* @role Input attribute generation
|
|
71
|
+
* @param {keyof T} fieldName The field name.
|
|
72
|
+
* @return {any} The input attributes for the field.
|
|
73
|
+
*/
|
|
74
|
+
getInputDataSet(fieldName) {
|
|
75
|
+
return this.#collectionValues.getInputDataSet(String(fieldName), this.#data);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Iterate over an array field and return field metadata for each item.
|
|
79
|
+
* @role Array field iteration
|
|
80
|
+
* @param {string} fieldName The field name.
|
|
81
|
+
* @param {any[]} data The array data.
|
|
82
|
+
* @return {IDbForge[]} Array of field metadata objects for each item.
|
|
83
|
+
*/
|
|
84
|
+
iterateArray(fieldName, data) {
|
|
85
|
+
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Iterate over an object field and return field metadata for each property.
|
|
89
|
+
* @role Object field iteration
|
|
90
|
+
* @param {string} fieldName The field name.
|
|
91
|
+
* @param {Record<string, unknown>} data The object data.
|
|
92
|
+
* @return {IDbForge[]} Array of field metadata objects for each property.
|
|
93
|
+
*/
|
|
94
|
+
iterateObject(fieldName, data) {
|
|
95
|
+
return this.#collectionValues.iterateObjectField(fieldName, data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { TplCollectionName, TplFields } from '../../types/index.js';
|
|
2
|
+
import { MachineDb } from '../machineDb.js';
|
|
3
|
+
/**
|
|
4
|
+
* @class MachineSchemeValidate
|
|
5
|
+
* @role Provides validation utilities for form fields in a collection.
|
|
6
|
+
* Supports field validation, custom validators, cross-field validation, and async validators.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const validator = new MachineSchemeValidate('agents', machineDb);
|
|
10
|
+
* validator.registerCustom('email', (val) => /^.+@.+/.test(val));
|
|
11
|
+
* const result = validator.validateField('email', value);
|
|
12
|
+
*/
|
|
13
|
+
/** Validation error result structure */
|
|
14
|
+
export interface ValidationError {
|
|
15
|
+
fieldName: string;
|
|
16
|
+
message: string;
|
|
17
|
+
severity: 'error' | 'warning';
|
|
18
|
+
type: 'required' | 'type' | 'format' | 'custom' | 'cross-field';
|
|
19
|
+
}
|
|
20
|
+
export declare class MachineSchemeValidate {
|
|
21
|
+
#private;
|
|
22
|
+
private collection;
|
|
23
|
+
private machineDb;
|
|
24
|
+
private customValidators;
|
|
25
|
+
private asyncValidators;
|
|
26
|
+
private crossFieldValidators;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new MachineSchemeValidate instance.
|
|
29
|
+
* @role Constructor
|
|
30
|
+
* @param {TplCollectionName} collection The collection name.
|
|
31
|
+
* @param {MachineDb} machineDb The MachineDb instance.
|
|
32
|
+
*/
|
|
33
|
+
constructor(collection: TplCollectionName, machineDb: MachineDb);
|
|
34
|
+
/**
|
|
35
|
+
* Validate a field value for the collection.
|
|
36
|
+
* @role Field validation
|
|
37
|
+
* @param {keyof TplFields} fieldName The field name.
|
|
38
|
+
* @param {any} value The value to validate.
|
|
39
|
+
* @return {{ isValid: boolean; error?: string; }} An object with isValid and optional error.
|
|
40
|
+
*/
|
|
41
|
+
validateField(fieldName: keyof TplFields, value: unknown, formData?: Record<string, unknown>): Promise<{
|
|
42
|
+
isValid: boolean;
|
|
43
|
+
error?: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Validate a single field value for a collection.
|
|
47
|
+
* @param fieldName The field name.
|
|
48
|
+
* @param value The value to validate.
|
|
49
|
+
* @returns True if valid, false otherwise.
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Quick validation check for a field value (boolean result).
|
|
53
|
+
* @role Field validation
|
|
54
|
+
* @param {keyof TplFields} fieldName The field name to validate.
|
|
55
|
+
* @param {unknown} value The value to validate.
|
|
56
|
+
* @returns {Promise<boolean>} True if valid, false otherwise.
|
|
57
|
+
*/
|
|
58
|
+
validateFieldValue(fieldName: keyof TplFields, value: unknown): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Register a custom validator function for a specific field.
|
|
61
|
+
* @role Custom validation
|
|
62
|
+
* @param {keyof TplFields} fieldName The field name to validate.
|
|
63
|
+
* @param {(value: unknown) => boolean} validator The validator function (returns true if valid).
|
|
64
|
+
*/
|
|
65
|
+
registerCustom(fieldName: keyof TplFields, validator: (value: unknown) => boolean): void;
|
|
66
|
+
/**
|
|
67
|
+
* Register an async validator function for a specific field.
|
|
68
|
+
* @role Async validation
|
|
69
|
+
* @param {keyof TplFields} fieldName The field name to validate.
|
|
70
|
+
* @param {(value: unknown) => Promise<boolean>} validator The async validator function.
|
|
71
|
+
*/
|
|
72
|
+
registerAsync(fieldName: keyof TplFields, validator: (value: unknown) => Promise<boolean>): void;
|
|
73
|
+
/**
|
|
74
|
+
* Register a cross-field validator that validates multiple fields together.
|
|
75
|
+
* @role Cross-field validation
|
|
76
|
+
* @param {Object} rule The cross-field validation rule.
|
|
77
|
+
* @param {string[]} rule.fields The field names involved in the validation.
|
|
78
|
+
* @param {(data: Record<string, unknown>) => boolean | Promise<boolean>} rule.validator The validator function.
|
|
79
|
+
*/
|
|
80
|
+
registerCrossField(rule: {
|
|
81
|
+
fields: string[];
|
|
82
|
+
validator: (data: Record<string, unknown>) => boolean | Promise<boolean>;
|
|
83
|
+
}): void;
|
|
84
|
+
/**
|
|
85
|
+
* Validate entire form data against all collection fields.
|
|
86
|
+
* @role Form validation
|
|
87
|
+
* @param {Record<string, unknown>} formData The complete form data to validate.
|
|
88
|
+
* @param {Object} [options] Validation options.
|
|
89
|
+
* @param {string[]} [options.ignoreFields] Fields to skip during validation.
|
|
90
|
+
* @param {Array} [options.crossFieldValidators] Array of cross-field validator functions.
|
|
91
|
+
* @returns {Promise<Object>} Validation result with isValid flag, error messages, and invalid field names.
|
|
92
|
+
*/
|
|
93
|
+
validateForm(formData: Record<string, unknown>, options?: {
|
|
94
|
+
ignoreFields?: string[] | undefined;
|
|
95
|
+
crossFieldValidators?: Array<(data: Record<string, unknown>) => boolean | {
|
|
96
|
+
isValid: boolean;
|
|
97
|
+
errors?: Record<string, string>;
|
|
98
|
+
} | Promise<boolean | {
|
|
99
|
+
isValid: boolean;
|
|
100
|
+
errors?: Record<string, string>;
|
|
101
|
+
}>>;
|
|
102
|
+
}): Promise<{
|
|
103
|
+
isValid: boolean;
|
|
104
|
+
errors: Record<string, string>;
|
|
105
|
+
invalidFields: string[];
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { MachineDb } from '../machineDb.js';
|
|
2
|
+
import { MachineErrorValidation } from './MachineErrorValidation.js';
|
|
3
|
+
import { MachineError } from './MachineError.js';
|
|
4
|
+
import MachineSchemeFieldType, { defaultTypes } from './MachineFieldType.js';
|
|
5
|
+
import { validateField as validateFieldPure } from './validateRules.js';
|
|
6
|
+
export class MachineSchemeValidate {
|
|
7
|
+
collection;
|
|
8
|
+
machineDb;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
customValidators = new Map();
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
asyncValidators = new Map();
|
|
13
|
+
crossFieldValidators = [];
|
|
14
|
+
/**
|
|
15
|
+
* Create a new MachineSchemeValidate instance.
|
|
16
|
+
* @role Constructor
|
|
17
|
+
* @param {TplCollectionName} collection The collection name.
|
|
18
|
+
* @param {MachineDb} machineDb The MachineDb instance.
|
|
19
|
+
*/
|
|
20
|
+
constructor(collection, machineDb) {
|
|
21
|
+
this.collection = collection;
|
|
22
|
+
this.machineDb = machineDb;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate a field value for the collection.
|
|
26
|
+
* @role Field validation
|
|
27
|
+
* @param {keyof TplFields} fieldName The field name.
|
|
28
|
+
* @param {any} value The value to validate.
|
|
29
|
+
* @return {{ isValid: boolean; error?: string; }} An object with isValid and optional error.
|
|
30
|
+
*/
|
|
31
|
+
async validateField(fieldName, value, formData) {
|
|
32
|
+
try {
|
|
33
|
+
const fieldInfo = this.machineDb.collection(this.collection).field(fieldName).parse();
|
|
34
|
+
if (!fieldInfo) {
|
|
35
|
+
return {
|
|
36
|
+
isValid: false,
|
|
37
|
+
error: `Field ${String(fieldName)} not found in collection`
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// If the value is empty (undefined/null/empty string) and the field is not required, skip further checks.
|
|
41
|
+
const args = (fieldInfo.fieldArgs ?? []);
|
|
42
|
+
const isRequired = args.includes('required');
|
|
43
|
+
if (value === undefined || value === null || value === '') {
|
|
44
|
+
if (isRequired) {
|
|
45
|
+
return this.#returnError(fieldName, 'required');
|
|
46
|
+
}
|
|
47
|
+
return { isValid: true };
|
|
48
|
+
}
|
|
49
|
+
const typeOK = await this.#validateType(value, fieldInfo.fieldType, {
|
|
50
|
+
formData,
|
|
51
|
+
fieldName: String(fieldName)
|
|
52
|
+
});
|
|
53
|
+
if (!typeOK) {
|
|
54
|
+
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
55
|
+
}
|
|
56
|
+
// Check custom validators for this field
|
|
57
|
+
const customValidators = this.customValidators.get(String(fieldName)) || [];
|
|
58
|
+
for (const validator of customValidators) {
|
|
59
|
+
if (!validator(value)) {
|
|
60
|
+
return { isValid: false, error: `Invalid value for ${String(fieldName)}` };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Check async validators for this field
|
|
64
|
+
const asyncValidators = this.asyncValidators.get(String(fieldName)) || [];
|
|
65
|
+
for (const validator of asyncValidators) {
|
|
66
|
+
const isValid = await validator(value);
|
|
67
|
+
if (!isValid) {
|
|
68
|
+
return { isValid: false, error: `Validation failed for ${String(fieldName)}` };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { isValid: true };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof MachineErrorValidation) {
|
|
75
|
+
return { isValid: false, error: error.message };
|
|
76
|
+
}
|
|
77
|
+
else if (error instanceof MachineError) {
|
|
78
|
+
return { isValid: false, error: error.message };
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate a single field value for a collection.
|
|
85
|
+
* @param fieldName The field name.
|
|
86
|
+
* @param value The value to validate.
|
|
87
|
+
* @returns True if valid, false otherwise.
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Quick validation check for a field value (boolean result).
|
|
91
|
+
* @role Field validation
|
|
92
|
+
* @param {keyof TplFields} fieldName The field name to validate.
|
|
93
|
+
* @param {unknown} value The value to validate.
|
|
94
|
+
* @returns {Promise<boolean>} True if valid, false otherwise.
|
|
95
|
+
*/
|
|
96
|
+
async validateFieldValue(fieldName, value) {
|
|
97
|
+
const result = await this.validateField(fieldName, value);
|
|
98
|
+
return !!result.isValid;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Register a custom validator function for a specific field.
|
|
102
|
+
* @role Custom validation
|
|
103
|
+
* @param {keyof TplFields} fieldName The field name to validate.
|
|
104
|
+
* @param {(value: unknown) => boolean} validator The validator function (returns true if valid).
|
|
105
|
+
*/
|
|
106
|
+
registerCustom(fieldName, validator) {
|
|
107
|
+
if (!this.customValidators.has(String(fieldName))) {
|
|
108
|
+
this.customValidators.set(String(fieldName), []);
|
|
109
|
+
}
|
|
110
|
+
this.customValidators.get(String(fieldName))?.push(validator);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Register an async validator function for a specific field.
|
|
114
|
+
* @role Async validation
|
|
115
|
+
* @param {keyof TplFields} fieldName The field name to validate.
|
|
116
|
+
* @param {(value: unknown) => Promise<boolean>} validator The async validator function.
|
|
117
|
+
*/
|
|
118
|
+
registerAsync(fieldName, validator) {
|
|
119
|
+
if (!this.asyncValidators.has(String(fieldName))) {
|
|
120
|
+
this.asyncValidators.set(String(fieldName), []);
|
|
121
|
+
}
|
|
122
|
+
this.asyncValidators.get(String(fieldName))?.push(validator);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Register a cross-field validator that validates multiple fields together.
|
|
126
|
+
* @role Cross-field validation
|
|
127
|
+
* @param {Object} rule The cross-field validation rule.
|
|
128
|
+
* @param {string[]} rule.fields The field names involved in the validation.
|
|
129
|
+
* @param {(data: Record<string, unknown>) => boolean | Promise<boolean>} rule.validator The validator function.
|
|
130
|
+
*/
|
|
131
|
+
registerCrossField(rule) {
|
|
132
|
+
this.crossFieldValidators.push(rule);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Validate entire form data against all collection fields.
|
|
136
|
+
* @role Form validation
|
|
137
|
+
* @param {Record<string, unknown>} formData The complete form data to validate.
|
|
138
|
+
* @param {Object} [options] Validation options.
|
|
139
|
+
* @param {string[]} [options.ignoreFields] Fields to skip during validation.
|
|
140
|
+
* @param {Array} [options.crossFieldValidators] Array of cross-field validator functions.
|
|
141
|
+
* @returns {Promise<Object>} Validation result with isValid flag, error messages, and invalid field names.
|
|
142
|
+
*/
|
|
143
|
+
async validateForm(formData, options = {}) {
|
|
144
|
+
const errors = {};
|
|
145
|
+
const invalidFields = [];
|
|
146
|
+
let isValid = true;
|
|
147
|
+
const fields = this.machineDb.collection(this.collection).fields;
|
|
148
|
+
if (!fields) {
|
|
149
|
+
return {
|
|
150
|
+
isValid: false,
|
|
151
|
+
errors: { general: 'Collection fields not found' },
|
|
152
|
+
invalidFields: ['general']
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
for (const [fieldName] of Object.entries(fields)) {
|
|
156
|
+
if (options.ignoreFields && options.ignoreFields.includes(fieldName)) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const result = await this.validateField(fieldName, formData[fieldName], formData);
|
|
160
|
+
if (!result.isValid) {
|
|
161
|
+
errors[fieldName] = result.error || 'Invalid field';
|
|
162
|
+
invalidFields.push(fieldName);
|
|
163
|
+
isValid = false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// FK relations declared `required: true` in the `fks` block — checked
|
|
167
|
+
// separately from `fields` since FK refs aren't scalar form fields.
|
|
168
|
+
const scheme = this.machineDb.collection(this.collection);
|
|
169
|
+
for (const [relationKey, fkDef] of Object.entries(scheme.fks)) {
|
|
170
|
+
if (!fkDef.required)
|
|
171
|
+
continue;
|
|
172
|
+
if (options.ignoreFields && options.ignoreFields.includes(relationKey))
|
|
173
|
+
continue;
|
|
174
|
+
if (!scheme.hasFkValue(formData, relationKey)) {
|
|
175
|
+
errors[relationKey] = 'Ce champ est obligatoire';
|
|
176
|
+
invalidFields.push(relationKey);
|
|
177
|
+
isValid = false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Cross-field validators (from options parameter)
|
|
181
|
+
if (options.crossFieldValidators) {
|
|
182
|
+
for (const vf of options.crossFieldValidators) {
|
|
183
|
+
const out = await vf(formData);
|
|
184
|
+
if (typeof out === 'boolean') {
|
|
185
|
+
if (!out) {
|
|
186
|
+
errors['__form'] = 'Cross-field validation failed';
|
|
187
|
+
invalidFields.push('__form');
|
|
188
|
+
isValid = false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (typeof out === 'object') {
|
|
192
|
+
if (!out.isValid) {
|
|
193
|
+
if (out.errors) {
|
|
194
|
+
Object.entries(out.errors).forEach(([k, v]) => {
|
|
195
|
+
errors[k] = v;
|
|
196
|
+
invalidFields.push(k);
|
|
197
|
+
isValid = false;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
errors['__form'] = 'Cross-field validation failed';
|
|
202
|
+
invalidFields.push('__form');
|
|
203
|
+
isValid = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Cross-field validators (registered instance validators)
|
|
210
|
+
for (const rule of this.crossFieldValidators) {
|
|
211
|
+
try {
|
|
212
|
+
const result = await rule.validator(formData);
|
|
213
|
+
if (!result) {
|
|
214
|
+
errors['__form'] = `Cross-field validation failed for fields: ${rule.fields.join(', ')}`;
|
|
215
|
+
invalidFields.push('__form');
|
|
216
|
+
isValid = false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
errors['__form'] = 'Cross-field validation error';
|
|
221
|
+
invalidFields.push('__form');
|
|
222
|
+
isValid = false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return { isValid, errors, invalidFields };
|
|
226
|
+
}
|
|
227
|
+
async #validateType(value, type, ctx) {
|
|
228
|
+
// First try the shared pure validateRules for standard types
|
|
229
|
+
const pureError = validateFieldPure(value, { type: type ?? 'any' });
|
|
230
|
+
if (pureError !== null) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
// Then check MachineSchemeFieldType registry for custom types
|
|
234
|
+
const typeDef = MachineSchemeFieldType.getFieldType(type ?? 'any');
|
|
235
|
+
if (typeDef && typeDef.validator) {
|
|
236
|
+
const res = typeDef.validator(value, ctx);
|
|
237
|
+
if (res && typeof res?.then === 'function') {
|
|
238
|
+
return (await res);
|
|
239
|
+
}
|
|
240
|
+
return Boolean(res);
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
#returnError(fieldName, enumCode) {
|
|
245
|
+
throw new MachineErrorValidation(String(fieldName), enumCode ?? 'unknown', `Invalid format for field ${String(fieldName)}. Cause "${enumCode}" `);
|
|
246
|
+
}
|
|
247
|
+
}
|