snow-flow 1.4.49 → 2.0.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/.claude/helpers/github-setup.sh +28 -0
- package/.claude/helpers/quick-start.sh +19 -0
- package/.claude/helpers/setup-mcp.sh +18 -0
- package/{.claude.settings.template → .claude/settings.local.json} +18 -21
- package/.claude-flow/metrics/system-metrics.json +3060 -0
- package/.env.example +64 -0
- package/.roo/README.md +402 -0
- package/.roo/mcp-list.txt +257 -0
- package/.roo/mcp.json +32 -0
- package/.roo/workflows/basic-tdd.json +32 -0
- package/.roomodes +201 -0
- package/README.md +140 -614
- package/dist/cli.js.bak +2052 -0
- package/package.json +2 -2
- package/scripts/create-env.js +6 -1
- package/scripts/reset-mcp-servers.js +246 -0
- package/scripts/update-version.js +31 -0
- package/src/agents/README.md +192 -0
- package/src/agents/base-agent.ts +251 -0
- package/src/agents/coordinator.ts +971 -0
- package/src/agents/index.ts +18 -0
- package/src/agents/queen-403-handler.ts +230 -0
- package/src/agents/queen-agent.ts +1399 -0
- package/src/agents/script-writer-agent.ts +769 -0
- package/src/agents/security-agent.ts +726 -0
- package/src/agents/widget-creator-agent.ts +568 -0
- package/src/api/error-handling.ts +1758 -0
- package/src/api/natural-language-mapper.ts +630 -0
- package/src/api/performance-optimizer.ts +891 -0
- package/src/api/transaction-manager.ts +754 -0
- package/src/cli/deploy-artifact.ts +304 -0
- package/src/cli/snow-flow-cli-integration.ts +434 -0
- package/src/cli.ts +4455 -0
- package/src/cli.ts.bak +5616 -0
- package/src/compliance/advanced-compliance-system.ts +1268 -0
- package/src/compliance/index.ts +19 -0
- package/src/config/snow-flow-config.ts +1019 -0
- package/src/documentation/index.ts +16 -0
- package/src/documentation/self-documenting-system.ts +1421 -0
- package/src/dynamic-version.ts +44 -0
- package/src/healing/index.ts +20 -0
- package/src/healing/self-healing-system.ts +1435 -0
- package/src/health/README.md +161 -0
- package/src/health/system-health.ts +995 -0
- package/src/index.ts +60 -0
- package/src/intelligence/acl-analyzer.ts +377 -0
- package/src/intelligence/auto-resolution-engine.ts +643 -0
- package/src/intelligence/gap-analysis-engine.ts +488 -0
- package/src/intelligence/manual-instructions-generator.ts +744 -0
- package/src/intelligence/mcp-coverage-analyzer.ts +708 -0
- package/src/intelligence/multi-pass-requirements-analyzer.ts +603 -0
- package/src/intelligence/performance-recommendations-engine.ts +1223 -0
- package/src/intelligence/requirements-analyzer.ts +1148 -0
- package/src/intelligence/task-analyzer.ts +628 -0
- package/src/managers/scope-manager.ts +555 -0
- package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +16110 -0
- package/src/mcp/base-mcp-server.ts +660 -0
- package/src/mcp/http-transport-wrapper.ts +426 -0
- package/src/mcp/service-discovery-client.ts +312 -0
- package/src/mcp/servicenow-automation-mcp-refactored.ts +678 -0
- package/src/mcp/servicenow-automation-mcp.ts +838 -0
- package/src/mcp/servicenow-deployment-mcp-refactored.ts +1292 -0
- package/src/mcp/servicenow-deployment-mcp.ts +7244 -0
- package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +721 -0
- package/src/mcp/servicenow-graph-memory-mcp.ts +832 -0
- package/src/mcp/servicenow-integration-mcp-refactored.ts +655 -0
- package/src/mcp/servicenow-integration-mcp.ts +819 -0
- package/src/mcp/servicenow-intelligent-mcp-refactored.ts +977 -0
- package/src/mcp/servicenow-intelligent-mcp.ts +4638 -0
- package/src/mcp/servicenow-mcp-server.ts +728 -0
- package/src/mcp/servicenow-memory-mcp.ts +474 -0
- package/src/mcp/servicenow-operations-mcp-refactored.ts +1995 -0
- package/src/mcp/servicenow-operations-mcp.ts +3384 -0
- package/src/mcp/servicenow-platform-development-mcp-refactored.ts +611 -0
- package/src/mcp/servicenow-platform-development-mcp.ts +970 -0
- package/src/mcp/servicenow-progressive-indexer.ts +370 -0
- package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +695 -0
- package/src/mcp/servicenow-reporting-analytics-mcp.ts +1123 -0
- package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +642 -0
- package/src/mcp/servicenow-security-compliance-mcp.ts +1157 -0
- package/src/mcp/servicenow-update-set-mcp-refactored.ts +751 -0
- package/src/mcp/servicenow-update-set-mcp.ts +811 -0
- package/src/mcp/shared/agent-context-provider.ts +365 -0
- package/src/mcp/shared/base-mcp-server.ts +2463 -0
- package/src/mcp/shared/mcp-memory-manager.ts +540 -0
- package/src/mcp/shared/mcp-resource-manager.ts +367 -0
- package/src/mcp/snow-flow-mcp.ts +911 -0
- package/src/mcp/start-all-mcp-servers.ts +102 -0
- package/src/mcp/start-servicenow-mcp.ts +67 -0
- package/src/monitoring/enhanced-monitoring-system.ts +1345 -0
- package/src/monitoring/performance-tracker.ts +777 -0
- package/src/optimization/cost-optimization-engine.ts +1125 -0
- package/src/optimization/index.ts +10 -0
- package/src/queen/README.md +403 -0
- package/src/queen/agent-factory.ts +574 -0
- package/src/queen/index.ts +94 -0
- package/src/queen/mcp-execution-bridge.ts +681 -0
- package/src/queen/neural-learning.ts +319 -0
- package/src/queen/parallel-agent-engine.ts +848 -0
- package/src/queen/queen-memory-system.ts +490 -0
- package/src/queen/queen-memory.ts +456 -0
- package/src/queen/servicenow-queen.ts +1029 -0
- package/src/queen/types.ts +87 -0
- package/src/rollback/smart-rollback-system.ts +866 -0
- package/src/schemas/deployment.schema.json +58 -0
- package/src/schemas/flow.schema.json +79 -0
- package/src/schemas/widget.schema.json +72 -0
- package/src/snow-flow-system.ts +541 -0
- package/src/sparc/sparc-help.ts +49 -0
- package/src/sparc/team-sparc.ts +88 -0
- package/src/strategies/global-scope-strategy.ts +736 -0
- package/src/templates/base/application.template.json +45 -0
- package/src/templates/base/business_rule.template.json +33 -0
- package/src/templates/base/script_include.template.json +18 -0
- package/src/templates/base/table.template.json +64 -0
- package/src/templates/base/widget.template.json +25 -0
- package/src/templates/patterns/composite.incident-management.template.json +140 -0
- package/src/templates/patterns/widget.dashboard.template.json +238 -0
- package/src/templates/patterns/widget.datatable.template.json +292 -0
- package/src/testing/integration-test-suite.ts +1276 -0
- package/src/types/index.ts +183 -0
- package/src/types/neo4j-driver.d.ts +23 -0
- package/src/types/servicenow.types.ts +307 -0
- package/src/types/snow-flow.types.ts +186 -0
- package/src/types/todo.types.ts +70 -0
- package/src/utils/action-type-cache.ts +286 -0
- package/src/utils/agent-detector.ts +573 -0
- package/src/utils/artifact-tracker.ts +379 -0
- package/src/utils/dependency-detector.ts +233 -0
- package/src/utils/deployment-metadata-handler.ts +518 -0
- package/src/utils/error-recovery.ts +680 -0
- package/src/utils/logger.ts +60 -0
- package/src/utils/mcp-auth-middleware.ts +262 -0
- package/src/utils/mcp-config-manager.ts +270 -0
- package/src/utils/mcp-server-manager.ts +446 -0
- package/src/utils/mcp-tool-registry.ts +298 -0
- package/src/utils/migrate-snow-flow.ts +98 -0
- package/src/utils/oauth-html-templates.ts +188 -0
- package/src/utils/scope-utils.ts +443 -0
- package/src/utils/servicenow-client.ts +3321 -0
- package/src/utils/servicenow-id-generator.ts +181 -0
- package/src/utils/snow-memory-manager.ts +605 -0
- package/src/utils/snow-oauth.ts +797 -0
- package/src/utils/template-engine.ts +463 -0
- package/src/utils/theme-manager.ts +295 -0
- package/src/utils/unified-auth-store.ts +222 -0
- package/src/utils/update-set-importer.ts +422 -0
- package/src/utils/update-set-xml-packager.ts +371 -0
- package/src/utils/widget-template-generator.ts +1744 -0
- package/src/version.ts +1950 -0
- package/.claude/commands/memory/README.md +0 -9
- package/.claude.mcp-config.template +0 -149
- package/SIMPLE_TEST_COMMANDS.txt +0 -143
- package/SNOW_FLOW_ADVANCED_FEATURES_PLAIN.txt +0 -78
- package/TEST_COMMANDS_v139.sh +0 -126
- package/claude-flow +0 -81
- package/claude-flow.bat +0 -18
- package/claude-flow.config.json +0 -20
- package/claude-flow.ps1 +0 -24
- package/dist/agents/app-creator.agent.d.ts.map +0 -1
- package/dist/agents/app-creator.agent.js.map +0 -1
- package/dist/agents/base/base-snow-agent.d.ts.map +0 -1
- package/dist/agents/base/base-snow-agent.js.map +0 -1
- package/dist/agents/base-agent.d.ts.map +0 -1
- package/dist/agents/base-agent.js.map +0 -1
- package/dist/agents/base-snow-agent.d.ts.map +0 -1
- package/dist/agents/base-snow-agent.js.map +0 -1
- package/dist/agents/coordinator.d.ts.map +0 -1
- package/dist/agents/coordinator.js.map +0 -1
- package/dist/agents/flow-builder-agent.d.ts.map +0 -1
- package/dist/agents/flow-builder-agent.js.map +0 -1
- package/dist/agents/index.d.ts.map +0 -1
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/queen-403-handler.d.ts.map +0 -1
- package/dist/agents/queen-403-handler.js.map +0 -1
- package/dist/agents/queen-agent-example.d.ts.map +0 -1
- package/dist/agents/queen-agent-example.js.map +0 -1
- package/dist/agents/queen-agent.d.ts.map +0 -1
- package/dist/agents/queen-agent.js.map +0 -1
- package/dist/agents/queen-agent.test.d.ts.map +0 -1
- package/dist/agents/queen-agent.test.js.map +0 -1
- package/dist/agents/script-generator.agent.d.ts.map +0 -1
- package/dist/agents/script-generator.agent.js.map +0 -1
- package/dist/agents/script-writer-agent.d.ts.map +0 -1
- package/dist/agents/script-writer-agent.js.map +0 -1
- package/dist/agents/security-agent.d.ts.map +0 -1
- package/dist/agents/security-agent.js.map +0 -1
- package/dist/agents/specialists/automation-specialist.agent.d.ts.map +0 -1
- package/dist/agents/specialists/automation-specialist.agent.js.map +0 -1
- package/dist/agents/specialists/data-specialist.agent.d.ts.map +0 -1
- package/dist/agents/specialists/data-specialist.agent.js.map +0 -1
- package/dist/agents/specialists/integration-specialist.agent.d.ts.map +0 -1
- package/dist/agents/specialists/integration-specialist.agent.js.map +0 -1
- package/dist/agents/specialists/reporting-specialist.agent.d.ts.map +0 -1
- package/dist/agents/specialists/reporting-specialist.agent.js.map +0 -1
- package/dist/agents/specialists/security-specialist.agent.d.ts.map +0 -1
- package/dist/agents/specialists/security-specialist.agent.js.map +0 -1
- package/dist/agents/teams/adaptive/adaptive-coordinator.agent.d.ts.map +0 -1
- package/dist/agents/teams/adaptive/adaptive-coordinator.agent.js.map +0 -1
- package/dist/agents/teams/base-team.d.ts.map +0 -1
- package/dist/agents/teams/base-team.js.map +0 -1
- package/dist/agents/teams/team-types.d.ts.map +0 -1
- package/dist/agents/teams/team-types.js.map +0 -1
- package/dist/agents/teams/widget/widget-architect.agent.d.ts.map +0 -1
- package/dist/agents/teams/widget/widget-architect.agent.js.map +0 -1
- package/dist/agents/teams/widget/widget-backend.agent.d.ts.map +0 -1
- package/dist/agents/teams/widget/widget-backend.agent.js.map +0 -1
- package/dist/agents/teams/widget/widget-frontend.agent.d.ts.map +0 -1
- package/dist/agents/teams/widget/widget-frontend.agent.js.map +0 -1
- package/dist/agents/teams/widget/widget-platform.agent.d.ts.map +0 -1
- package/dist/agents/teams/widget/widget-platform.agent.js.map +0 -1
- package/dist/agents/teams/widget/widget-uiux.agent.d.ts.map +0 -1
- package/dist/agents/teams/widget/widget-uiux.agent.js.map +0 -1
- package/dist/agents/test-agent.d.ts.map +0 -1
- package/dist/agents/test-agent.js.map +0 -1
- package/dist/agents/test-agents.d.ts.map +0 -1
- package/dist/agents/test-agents.js.map +0 -1
- package/dist/agents/ui-builder.agent.d.ts.map +0 -1
- package/dist/agents/ui-builder.agent.js.map +0 -1
- package/dist/agents/widget-builder.agent.d.ts.map +0 -1
- package/dist/agents/widget-builder.agent.js.map +0 -1
- package/dist/agents/widget-creator-agent.d.ts.map +0 -1
- package/dist/agents/widget-creator-agent.js.map +0 -1
- package/dist/agents/workflow-designer.agent.d.ts.map +0 -1
- package/dist/agents/workflow-designer.agent.js.map +0 -1
- package/dist/api/error-handling.d.ts.map +0 -1
- package/dist/api/error-handling.js.map +0 -1
- package/dist/api/flow-designer-api.d.ts.map +0 -1
- package/dist/api/flow-designer-api.js.map +0 -1
- package/dist/api/natural-language-mapper.d.ts.map +0 -1
- package/dist/api/natural-language-mapper.js.map +0 -1
- package/dist/api/performance-optimizer.d.ts.map +0 -1
- package/dist/api/performance-optimizer.js.map +0 -1
- package/dist/api/transaction-manager.d.ts.map +0 -1
- package/dist/api/transaction-manager.js.map +0 -1
- package/dist/assembly/team-assembler.d.ts.map +0 -1
- package/dist/assembly/team-assembler.js.map +0 -1
- package/dist/cli/deploy-artifact.d.ts.map +0 -1
- package/dist/cli/deploy-artifact.js.map +0 -1
- package/dist/cli/snow-flow-cli-integration.d.ts.map +0 -1
- package/dist/cli/snow-flow-cli-integration.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/compliance/advanced-compliance-system.d.ts.map +0 -1
- package/dist/compliance/advanced-compliance-system.js.map +0 -1
- package/dist/compliance/index.d.ts.map +0 -1
- package/dist/compliance/index.js.map +0 -1
- package/dist/config/snow-flow-config.d.ts.map +0 -1
- package/dist/config/snow-flow-config.js.map +0 -1
- package/dist/documentation/index.d.ts.map +0 -1
- package/dist/documentation/index.js.map +0 -1
- package/dist/documentation/self-documenting-system.d.ts.map +0 -1
- package/dist/documentation/self-documenting-system.js.map +0 -1
- package/dist/dynamic-version.d.ts.map +0 -1
- package/dist/dynamic-version.js.map +0 -1
- package/dist/healing/index.d.ts.map +0 -1
- package/dist/healing/index.js.map +0 -1
- package/dist/healing/self-healing-system.d.ts.map +0 -1
- package/dist/healing/self-healing-system.js.map +0 -1
- package/dist/health/system-health.d.ts.map +0 -1
- package/dist/health/system-health.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/intelligence/acl-analyzer.d.ts.map +0 -1
- package/dist/intelligence/acl-analyzer.js.map +0 -1
- package/dist/intelligence/auto-resolution-engine.d.ts.map +0 -1
- package/dist/intelligence/auto-resolution-engine.js.map +0 -1
- package/dist/intelligence/gap-analysis-engine.d.ts.map +0 -1
- package/dist/intelligence/gap-analysis-engine.js.map +0 -1
- package/dist/intelligence/manual-instructions-generator.d.ts.map +0 -1
- package/dist/intelligence/manual-instructions-generator.js.map +0 -1
- package/dist/intelligence/mcp-coverage-analyzer.d.ts.map +0 -1
- package/dist/intelligence/mcp-coverage-analyzer.js.map +0 -1
- package/dist/intelligence/multi-pass-requirements-analyzer.d.ts.map +0 -1
- package/dist/intelligence/multi-pass-requirements-analyzer.js.map +0 -1
- package/dist/intelligence/performance-recommendations-engine.d.ts.map +0 -1
- package/dist/intelligence/performance-recommendations-engine.js.map +0 -1
- package/dist/intelligence/requirements-analyzer.d.ts.map +0 -1
- package/dist/intelligence/requirements-analyzer.js.map +0 -1
- package/dist/intelligence/task-analyzer.d.ts.map +0 -1
- package/dist/intelligence/task-analyzer.js.map +0 -1
- package/dist/managers/scope-manager.d.ts.map +0 -1
- package/dist/managers/scope-manager.js.map +0 -1
- package/dist/mcp/advanced/servicenow-advanced-features-mcp.d.ts.map +0 -1
- package/dist/mcp/advanced/servicenow-advanced-features-mcp.js.map +0 -1
- package/dist/mcp/base-mcp-server.d.ts.map +0 -1
- package/dist/mcp/base-mcp-server.js.map +0 -1
- package/dist/mcp/example-refactored-server.d.ts.map +0 -1
- package/dist/mcp/example-refactored-server.js.map +0 -1
- package/dist/mcp/http-transport-wrapper.d.ts.map +0 -1
- package/dist/mcp/http-transport-wrapper.js.map +0 -1
- package/dist/mcp/mcp-wrapper.d.ts.map +0 -1
- package/dist/mcp/mcp-wrapper.js.map +0 -1
- package/dist/mcp/service-discovery-client.d.ts.map +0 -1
- package/dist/mcp/service-discovery-client.js.map +0 -1
- package/dist/mcp/servicenow-automation-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-automation-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-automation-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-automation-mcp.js.map +0 -1
- package/dist/mcp/servicenow-deployment-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-deployment-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-deployment-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-deployment-mcp.js.map +0 -1
- package/dist/mcp/servicenow-flow-composer-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-flow-composer-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-flow-composer-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-flow-composer-mcp.js.map +0 -1
- package/dist/mcp/servicenow-graph-memory-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-graph-memory-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-graph-memory-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-graph-memory-mcp.js.map +0 -1
- package/dist/mcp/servicenow-integration-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-integration-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-integration-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-integration-mcp.js.map +0 -1
- package/dist/mcp/servicenow-intelligent-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-intelligent-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-intelligent-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-intelligent-mcp.js.map +0 -1
- package/dist/mcp/servicenow-mcp-server.d.ts.map +0 -1
- package/dist/mcp/servicenow-mcp-server.js.map +0 -1
- package/dist/mcp/servicenow-memory-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-memory-mcp.js.map +0 -1
- package/dist/mcp/servicenow-operations-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-operations-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-operations-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-operations-mcp.js.map +0 -1
- package/dist/mcp/servicenow-platform-development-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-platform-development-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-platform-development-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-platform-development-mcp.js.map +0 -1
- package/dist/mcp/servicenow-progressive-indexer.d.ts.map +0 -1
- package/dist/mcp/servicenow-progressive-indexer.js.map +0 -1
- package/dist/mcp/servicenow-reporting-analytics-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-reporting-analytics-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-reporting-analytics-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-reporting-analytics-mcp.js.map +0 -1
- package/dist/mcp/servicenow-security-compliance-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-security-compliance-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-security-compliance-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-security-compliance-mcp.js.map +0 -1
- package/dist/mcp/servicenow-update-set-mcp-refactored.d.ts.map +0 -1
- package/dist/mcp/servicenow-update-set-mcp-refactored.js.map +0 -1
- package/dist/mcp/servicenow-update-set-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-update-set-mcp.js.map +0 -1
- package/dist/mcp/servicenow-xml-flow-mcp.d.ts.map +0 -1
- package/dist/mcp/servicenow-xml-flow-mcp.js.map +0 -1
- package/dist/mcp/shared/agent-context-provider.d.ts.map +0 -1
- package/dist/mcp/shared/agent-context-provider.js.map +0 -1
- package/dist/mcp/shared/base-mcp-server.d.ts.map +0 -1
- package/dist/mcp/shared/base-mcp-server.js.map +0 -1
- package/dist/mcp/shared/mcp-memory-manager.d.ts.map +0 -1
- package/dist/mcp/shared/mcp-memory-manager.js.map +0 -1
- package/dist/mcp/shared/mcp-resource-manager.d.ts.map +0 -1
- package/dist/mcp/shared/mcp-resource-manager.js.map +0 -1
- package/dist/mcp/snow-flow-mcp.d.ts.map +0 -1
- package/dist/mcp/snow-flow-mcp.js.map +0 -1
- package/dist/mcp/start-all-mcp-servers.d.ts.map +0 -1
- package/dist/mcp/start-all-mcp-servers.js.map +0 -1
- package/dist/mcp/start-servicenow-mcp.d.ts.map +0 -1
- package/dist/mcp/start-servicenow-mcp.js.map +0 -1
- package/dist/mcp/test-simple-mcp.d.ts.map +0 -1
- package/dist/mcp/test-simple-mcp.js.map +0 -1
- package/dist/memory/hierarchical-memory-system.d.ts +0 -90
- package/dist/memory/hierarchical-memory-system.d.ts.map +0 -1
- package/dist/memory/hierarchical-memory-system.js +0 -400
- package/dist/memory/hierarchical-memory-system.js.map +0 -1
- package/dist/memory/index.d.ts +0 -9
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -20
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/mcp-integration-example.d.ts +0 -6
- package/dist/memory/mcp-integration-example.d.ts.map +0 -1
- package/dist/memory/mcp-integration-example.js +0 -281
- package/dist/memory/mcp-integration-example.js.map +0 -1
- package/dist/memory/memory-client.d.ts +0 -199
- package/dist/memory/memory-client.d.ts.map +0 -1
- package/dist/memory/memory-client.js +0 -364
- package/dist/memory/memory-client.js.map +0 -1
- package/dist/memory/memory-manager.d.ts +0 -29
- package/dist/memory/memory-manager.d.ts.map +0 -1
- package/dist/memory/memory-manager.js +0 -280
- package/dist/memory/memory-manager.js.map +0 -1
- package/dist/memory/memory-operations.d.ts +0 -179
- package/dist/memory/memory-operations.d.ts.map +0 -1
- package/dist/memory/memory-operations.js +0 -691
- package/dist/memory/memory-operations.js.map +0 -1
- package/dist/memory/memory-system.d.ts +0 -152
- package/dist/memory/memory-system.d.ts.map +0 -1
- package/dist/memory/memory-system.js +0 -632
- package/dist/memory/memory-system.js.map +0 -1
- package/dist/memory/memory-test.d.ts +0 -6
- package/dist/memory/memory-test.d.ts.map +0 -1
- package/dist/memory/memory-test.js +0 -161
- package/dist/memory/memory-test.js.map +0 -1
- package/dist/memory/servicenow-artifact-indexer.d.ts +0 -119
- package/dist/memory/servicenow-artifact-indexer.d.ts.map +0 -1
- package/dist/memory/servicenow-artifact-indexer.js +0 -560
- package/dist/memory/servicenow-artifact-indexer.js.map +0 -1
- package/dist/memory/snow-flow-memory-patterns.d.ts +0 -213
- package/dist/memory/snow-flow-memory-patterns.d.ts.map +0 -1
- package/dist/memory/snow-flow-memory-patterns.js +0 -200
- package/dist/memory/snow-flow-memory-patterns.js.map +0 -1
- package/dist/memory/snow-memory.d.ts +0 -54
- package/dist/memory/snow-memory.d.ts.map +0 -1
- package/dist/memory/snow-memory.js +0 -301
- package/dist/memory/snow-memory.js.map +0 -1
- package/dist/memory/swarm-memory.d.ts +0 -135
- package/dist/memory/swarm-memory.d.ts.map +0 -1
- package/dist/memory/swarm-memory.js +0 -378
- package/dist/memory/swarm-memory.js.map +0 -1
- package/dist/monitoring/enhanced-monitoring-system.d.ts.map +0 -1
- package/dist/monitoring/enhanced-monitoring-system.js.map +0 -1
- package/dist/monitoring/performance-tracker.d.ts.map +0 -1
- package/dist/monitoring/performance-tracker.js.map +0 -1
- package/dist/optimization/cost-optimization-engine.d.ts.map +0 -1
- package/dist/optimization/cost-optimization-engine.js.map +0 -1
- package/dist/optimization/index.d.ts.map +0 -1
- package/dist/optimization/index.js.map +0 -1
- package/dist/orchestration/discovery/service-discovery.d.ts.map +0 -1
- package/dist/orchestration/discovery/service-discovery.js.map +0 -1
- package/dist/orchestration/distributed-orchestrator.d.ts.map +0 -1
- package/dist/orchestration/distributed-orchestrator.js.map +0 -1
- package/dist/orchestration/distribution/task-distribution-engine.d.ts.map +0 -1
- package/dist/orchestration/distribution/task-distribution-engine.js.map +0 -1
- package/dist/orchestration/interfaces/distributed-orchestration.interface.d.ts.map +0 -1
- package/dist/orchestration/interfaces/distributed-orchestration.interface.js.map +0 -1
- package/dist/orchestration/protocols/mcpx-protocol.d.ts.map +0 -1
- package/dist/orchestration/protocols/mcpx-protocol.js.map +0 -1
- package/dist/orchestration/state/distributed-state-manager.d.ts.map +0 -1
- package/dist/orchestration/state/distributed-state-manager.js.map +0 -1
- package/dist/orchestrator/flow-composer.d.ts.map +0 -1
- package/dist/orchestrator/flow-composer.js.map +0 -1
- package/dist/orchestrator/flow-pattern-templates.d.ts.map +0 -1
- package/dist/orchestrator/flow-pattern-templates.js.map +0 -1
- package/dist/orchestrator/flow-subflow-decision-engine.d.ts.map +0 -1
- package/dist/orchestrator/flow-subflow-decision-engine.js.map +0 -1
- package/dist/orchestrator/flow-validation-engine.d.ts.map +0 -1
- package/dist/orchestrator/flow-validation-engine.js.map +0 -1
- package/dist/orchestrator/snow-orchestrator.d.ts.map +0 -1
- package/dist/orchestrator/snow-orchestrator.js.map +0 -1
- package/dist/orchestrator/subflow-creation-handler.d.ts.map +0 -1
- package/dist/orchestrator/subflow-creation-handler.js.map +0 -1
- package/dist/patterns/adaptive-patterns.d.ts.map +0 -1
- package/dist/patterns/adaptive-patterns.js.map +0 -1
- package/dist/queen/advanced-integration-test.d.ts.map +0 -1
- package/dist/queen/advanced-integration-test.js.map +0 -1
- package/dist/queen/agent-factory.d.ts.map +0 -1
- package/dist/queen/agent-factory.js.map +0 -1
- package/dist/queen/index.d.ts.map +0 -1
- package/dist/queen/index.js.map +0 -1
- package/dist/queen/integration-example.d.ts.map +0 -1
- package/dist/queen/integration-example.js.map +0 -1
- package/dist/queen/integration-test.d.ts.map +0 -1
- package/dist/queen/integration-test.js.map +0 -1
- package/dist/queen/mcp-execution-bridge.d.ts.map +0 -1
- package/dist/queen/mcp-execution-bridge.js.map +0 -1
- package/dist/queen/mock-mcp-client.d.ts.map +0 -1
- package/dist/queen/mock-mcp-client.js.map +0 -1
- package/dist/queen/neural-learning.d.ts.map +0 -1
- package/dist/queen/neural-learning.js.map +0 -1
- package/dist/queen/parallel-agent-engine.d.ts.map +0 -1
- package/dist/queen/parallel-agent-engine.js.map +0 -1
- package/dist/queen/queen-memory-system.d.ts.map +0 -1
- package/dist/queen/queen-memory-system.js.map +0 -1
- package/dist/queen/queen-memory.d.ts.map +0 -1
- package/dist/queen/queen-memory.js.map +0 -1
- package/dist/queen/run-integration-tests.d.ts.map +0 -1
- package/dist/queen/run-integration-tests.js.map +0 -1
- package/dist/queen/servicenow-queen.d.ts.map +0 -1
- package/dist/queen/servicenow-queen.js.map +0 -1
- package/dist/queen/types.d.ts.map +0 -1
- package/dist/queen/types.js.map +0 -1
- package/dist/rollback/smart-rollback-system.d.ts.map +0 -1
- package/dist/rollback/smart-rollback-system.js.map +0 -1
- package/dist/snow-flow-system.d.ts.map +0 -1
- package/dist/snow-flow-system.js.map +0 -1
- package/dist/sparc/coordinators/adaptive-coordinator.d.ts.map +0 -1
- package/dist/sparc/coordinators/adaptive-coordinator.js.map +0 -1
- package/dist/sparc/coordinators/team-coordinator.d.ts.map +0 -1
- package/dist/sparc/coordinators/team-coordinator.js.map +0 -1
- package/dist/sparc/modes/team-modes.d.ts.map +0 -1
- package/dist/sparc/modes/team-modes.js.map +0 -1
- package/dist/sparc/sparc-help.d.ts.map +0 -1
- package/dist/sparc/sparc-help.js.map +0 -1
- package/dist/sparc/team-sparc.d.ts.map +0 -1
- package/dist/sparc/team-sparc.js.map +0 -1
- package/dist/sparc/teams/application-team.d.ts.map +0 -1
- package/dist/sparc/teams/application-team.js.map +0 -1
- package/dist/sparc/teams/flow-team.d.ts.map +0 -1
- package/dist/sparc/teams/flow-team.js.map +0 -1
- package/dist/sparc/teams/widget-team.d.ts.map +0 -1
- package/dist/sparc/teams/widget-team.js.map +0 -1
- package/dist/specialists/app-specialists.d.ts.map +0 -1
- package/dist/specialists/app-specialists.js.map +0 -1
- package/dist/specialists/base-specialist.d.ts.map +0 -1
- package/dist/specialists/base-specialist.js.map +0 -1
- package/dist/specialists/flow-specialists.d.ts.map +0 -1
- package/dist/specialists/flow-specialists.js.map +0 -1
- package/dist/specialists/individual-specialists.d.ts.map +0 -1
- package/dist/specialists/individual-specialists.js.map +0 -1
- package/dist/specialists/widget-specialists.d.ts.map +0 -1
- package/dist/specialists/widget-specialists.js.map +0 -1
- package/dist/strategies/global-scope-strategy.d.ts.map +0 -1
- package/dist/strategies/global-scope-strategy.js.map +0 -1
- package/dist/teams/adaptive-team.d.ts.map +0 -1
- package/dist/teams/adaptive-team.js.map +0 -1
- package/dist/teams/application-team.d.ts.map +0 -1
- package/dist/teams/application-team.js.map +0 -1
- package/dist/teams/base-team.d.ts.map +0 -1
- package/dist/teams/base-team.js.map +0 -1
- package/dist/teams/flow-team.d.ts.map +0 -1
- package/dist/teams/flow-team.js.map +0 -1
- package/dist/teams/widget-team.d.ts.map +0 -1
- package/dist/teams/widget-team.js.map +0 -1
- package/dist/testing/integration-test-suite.d.ts.map +0 -1
- package/dist/testing/integration-test-suite.js.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/servicenow.types.d.ts.map +0 -1
- package/dist/types/servicenow.types.js.map +0 -1
- package/dist/types/snow-flow.types.d.ts.map +0 -1
- package/dist/types/snow-flow.types.js.map +0 -1
- package/dist/types/todo.types.d.ts.map +0 -1
- package/dist/types/todo.types.js.map +0 -1
- package/dist/utils/action-type-cache.d.ts.map +0 -1
- package/dist/utils/action-type-cache.js.map +0 -1
- package/dist/utils/agent-detector.d.ts.map +0 -1
- package/dist/utils/agent-detector.js.map +0 -1
- package/dist/utils/artifact-tracker.d.ts.map +0 -1
- package/dist/utils/artifact-tracker.js.map +0 -1
- package/dist/utils/dependency-detector.d.ts.map +0 -1
- package/dist/utils/dependency-detector.js.map +0 -1
- package/dist/utils/deployment-metadata-handler.d.ts.map +0 -1
- package/dist/utils/deployment-metadata-handler.js.map +0 -1
- package/dist/utils/error-recovery.d.ts.map +0 -1
- package/dist/utils/error-recovery.js.map +0 -1
- package/dist/utils/flow-api-discovery.d.ts.map +0 -1
- package/dist/utils/flow-api-discovery.js.map +0 -1
- package/dist/utils/flow-xml-generator.d.ts.map +0 -1
- package/dist/utils/flow-xml-generator.js.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/mcp-auth-middleware.d.ts.map +0 -1
- package/dist/utils/mcp-auth-middleware.js.map +0 -1
- package/dist/utils/mcp-config-manager.d.ts.map +0 -1
- package/dist/utils/mcp-config-manager.js.map +0 -1
- package/dist/utils/mcp-server-manager.d.ts.map +0 -1
- package/dist/utils/mcp-server-manager.js.map +0 -1
- package/dist/utils/mcp-tool-registry.d.ts.map +0 -1
- package/dist/utils/mcp-tool-registry.js.map +0 -1
- package/dist/utils/migrate-claude-flow.d.ts.map +0 -1
- package/dist/utils/migrate-claude-flow.js.map +0 -1
- package/dist/utils/migrate-snow-flow.d.ts.map +0 -1
- package/dist/utils/migrate-snow-flow.js.map +0 -1
- package/dist/utils/oauth-html-templates.d.ts.map +0 -1
- package/dist/utils/oauth-html-templates.js.map +0 -1
- package/dist/utils/scope-utils.d.ts.map +0 -1
- package/dist/utils/scope-utils.js.map +0 -1
- package/dist/utils/servicenow-client.d.ts.map +0 -1
- package/dist/utils/servicenow-client.js.map +0 -1
- package/dist/utils/servicenow-id-generator.d.ts.map +0 -1
- package/dist/utils/servicenow-id-generator.js.map +0 -1
- package/dist/utils/snow-memory-manager.d.ts.map +0 -1
- package/dist/utils/snow-memory-manager.js.map +0 -1
- package/dist/utils/snow-oauth-old.d.ts.map +0 -1
- package/dist/utils/snow-oauth-old.js.map +0 -1
- package/dist/utils/snow-oauth.d.ts.map +0 -1
- package/dist/utils/snow-oauth.js.map +0 -1
- package/dist/utils/template-engine.d.ts.map +0 -1
- package/dist/utils/template-engine.js.map +0 -1
- package/dist/utils/theme-manager.d.ts.map +0 -1
- package/dist/utils/theme-manager.js.map +0 -1
- package/dist/utils/unified-auth-store.d.ts.map +0 -1
- package/dist/utils/unified-auth-store.js.map +0 -1
- package/dist/utils/update-set-importer.d.ts.map +0 -1
- package/dist/utils/update-set-importer.js.map +0 -1
- package/dist/utils/update-set-xml-packager.d.ts.map +0 -1
- package/dist/utils/update-set-xml-packager.js.map +0 -1
- package/dist/utils/widget-template-generator.d.ts.map +0 -1
- package/dist/utils/widget-template-generator.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
- package/memory/agents/README.md +0 -31
- package/memory/claude-flow-data.json +0 -5
- package/memory/servicenow_artifacts/000d9224c895221055906c7518aa2d3d.json +0 -30
- package/memory/servicenow_artifacts/0196b66173303010e46b4a2214f6a7a2.json +0 -36
- package/memory/servicenow_artifacts/125e5d1d837e2a102a7ea130ceaad397.json +0 -30
- package/memory/servicenow_artifacts/7637c1f2b7112210a5e5911cde11a972.json +0 -30
- package/memory/servicenow_artifacts/default_documentation_tables_1754056582292.json +0 -55
- package/memory/servicenow_artifacts/default_documentation_tables_1754057477189.json +0 -55
- package/memory/sessions/README.md +0 -32
- package/memory/update-set-sessions/01f82af583faea102a7ea130ceaad3d4.json +0 -9
- package/memory/update-set-sessions/27718fb983faea102a7ea130ceaad34b.json +0 -9
- package/memory/update-set-sessions/412e9bf6833e22502a7ea130ceaad30a.json +0 -8
- package/memory/update-set-sessions/66fc5a79837aea102a7ea130ceaad3ab.json +0 -9
- package/memory/update-set-sessions/71a30ff5837eea102a7ea130ceaad37f.json +0 -9
- package/memory/update-set-sessions/74fba27983faea102a7ea130ceaad3bd.json +0 -9
- package/memory/update-set-sessions/a0b147b5837eea102a7ea130ceaad344.json +0 -58
- package/memory/update-set-sessions/b13f5eb983baea102a7ea130ceaad33e.json +0 -9
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Management for Multi-Step Flow Creation
|
|
3
|
+
* Provides ACID-like properties for complex flow operations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ServiceNowClient } from '../utils/servicenow-client.js';
|
|
7
|
+
import { FlowErrorHandler, RollbackOperation, TransactionState } from './error-handling.js';
|
|
8
|
+
import { Logger } from '../utils/logger.js';
|
|
9
|
+
|
|
10
|
+
export interface TransactionDefinition {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
steps: TransactionStep[];
|
|
15
|
+
timeout: number;
|
|
16
|
+
isolation_level: 'read_uncommitted' | 'read_committed' | 'repeatable_read' | 'serializable';
|
|
17
|
+
rollback_on_error: boolean;
|
|
18
|
+
retry_policy: RetryPolicy;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TransactionStep {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
operation: 'create' | 'update' | 'delete' | 'validate' | 'custom';
|
|
25
|
+
table: string;
|
|
26
|
+
data?: any;
|
|
27
|
+
condition?: string;
|
|
28
|
+
dependencies: string[];
|
|
29
|
+
compensation?: CompensationAction;
|
|
30
|
+
timeout: number;
|
|
31
|
+
retry_count: number;
|
|
32
|
+
critical: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CompensationAction {
|
|
36
|
+
type: 'delete' | 'update' | 'restore' | 'custom';
|
|
37
|
+
table: string;
|
|
38
|
+
data?: any;
|
|
39
|
+
custom_function?: () => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface RetryPolicy {
|
|
43
|
+
max_attempts: number;
|
|
44
|
+
initial_delay: number;
|
|
45
|
+
max_delay: number;
|
|
46
|
+
backoff_multiplier: number;
|
|
47
|
+
retryable_errors: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface TransactionExecution {
|
|
51
|
+
id: string;
|
|
52
|
+
definition: TransactionDefinition;
|
|
53
|
+
state: TransactionExecutionState;
|
|
54
|
+
start_time: Date;
|
|
55
|
+
end_time?: Date;
|
|
56
|
+
current_step?: string;
|
|
57
|
+
completed_steps: string[];
|
|
58
|
+
failed_steps: string[];
|
|
59
|
+
results: Map<string, any>;
|
|
60
|
+
errors: Map<string, Error>;
|
|
61
|
+
compensations: CompensationAction[];
|
|
62
|
+
locks: Set<string>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export enum TransactionExecutionState {
|
|
66
|
+
PENDING = 'pending',
|
|
67
|
+
RUNNING = 'running',
|
|
68
|
+
COMPLETED = 'completed',
|
|
69
|
+
FAILED = 'failed',
|
|
70
|
+
COMPENSATING = 'compensating',
|
|
71
|
+
COMPENSATED = 'compensated',
|
|
72
|
+
TIMEOUT = 'timeout'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface LockManager {
|
|
76
|
+
acquire(resource: string, timeout: number): Promise<string>;
|
|
77
|
+
release(lockId: string): Promise<void>;
|
|
78
|
+
isLocked(resource: string): boolean;
|
|
79
|
+
getLockOwner(resource: string): string | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class TransactionManager {
|
|
83
|
+
private client: ServiceNowClient;
|
|
84
|
+
private errorHandler: FlowErrorHandler;
|
|
85
|
+
private logger: Logger;
|
|
86
|
+
private activeTransactions: Map<string, TransactionExecution> = new Map();
|
|
87
|
+
private lockManager: LockManager;
|
|
88
|
+
private sagaLog: Map<string, any[]> = new Map();
|
|
89
|
+
|
|
90
|
+
constructor(client: ServiceNowClient, errorHandler: FlowErrorHandler) {
|
|
91
|
+
this.client = client;
|
|
92
|
+
this.errorHandler = errorHandler;
|
|
93
|
+
this.logger = new Logger('TransactionManager');
|
|
94
|
+
this.lockManager = new SimpleLockManager();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Execute a transaction with ACID properties
|
|
99
|
+
*/
|
|
100
|
+
async executeTransaction(definition: TransactionDefinition): Promise<{
|
|
101
|
+
success: boolean;
|
|
102
|
+
transaction_id: string;
|
|
103
|
+
results?: Map<string, any>;
|
|
104
|
+
errors?: Error[];
|
|
105
|
+
compensation_applied?: boolean;
|
|
106
|
+
}> {
|
|
107
|
+
const execution: TransactionExecution = {
|
|
108
|
+
id: definition.id,
|
|
109
|
+
definition,
|
|
110
|
+
state: TransactionExecutionState.PENDING,
|
|
111
|
+
start_time: new Date(),
|
|
112
|
+
completed_steps: [],
|
|
113
|
+
failed_steps: [],
|
|
114
|
+
results: new Map(),
|
|
115
|
+
errors: new Map(),
|
|
116
|
+
compensations: [],
|
|
117
|
+
locks: new Set()
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.activeTransactions.set(definition.id, execution);
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
// Initialize saga log
|
|
124
|
+
this.sagaLog.set(definition.id, []);
|
|
125
|
+
|
|
126
|
+
// Start transaction
|
|
127
|
+
await this.startTransaction(execution);
|
|
128
|
+
|
|
129
|
+
// Execute steps
|
|
130
|
+
const result = await this.executeSteps(execution);
|
|
131
|
+
|
|
132
|
+
if (result.success) {
|
|
133
|
+
await this.commitTransaction(execution);
|
|
134
|
+
return {
|
|
135
|
+
success: true,
|
|
136
|
+
transaction_id: execution.id,
|
|
137
|
+
results: execution.results
|
|
138
|
+
};
|
|
139
|
+
} else {
|
|
140
|
+
await this.rollbackTransaction(execution);
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
transaction_id: execution.id,
|
|
144
|
+
errors: Array.from(execution.errors.values()),
|
|
145
|
+
compensation_applied: true
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
} catch (error) {
|
|
150
|
+
this.logger.error('Transaction execution failed', { transactionId: definition.id, error });
|
|
151
|
+
await this.rollbackTransaction(execution);
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
transaction_id: execution.id,
|
|
156
|
+
errors: [error instanceof Error ? error : new Error(String(error))],
|
|
157
|
+
compensation_applied: true
|
|
158
|
+
};
|
|
159
|
+
} finally {
|
|
160
|
+
this.activeTransactions.delete(definition.id);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Execute a saga pattern transaction
|
|
166
|
+
*/
|
|
167
|
+
async executeSaga(definition: TransactionDefinition): Promise<{
|
|
168
|
+
success: boolean;
|
|
169
|
+
transaction_id: string;
|
|
170
|
+
results?: Map<string, any>;
|
|
171
|
+
compensations_applied?: CompensationAction[];
|
|
172
|
+
}> {
|
|
173
|
+
const execution: TransactionExecution = {
|
|
174
|
+
id: definition.id,
|
|
175
|
+
definition,
|
|
176
|
+
state: TransactionExecutionState.PENDING,
|
|
177
|
+
start_time: new Date(),
|
|
178
|
+
completed_steps: [],
|
|
179
|
+
failed_steps: [],
|
|
180
|
+
results: new Map(),
|
|
181
|
+
errors: new Map(),
|
|
182
|
+
compensations: [],
|
|
183
|
+
locks: new Set()
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
this.activeTransactions.set(definition.id, execution);
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
execution.state = TransactionExecutionState.RUNNING;
|
|
190
|
+
|
|
191
|
+
// Execute steps with saga pattern
|
|
192
|
+
for (const step of definition.steps) {
|
|
193
|
+
try {
|
|
194
|
+
const stepResult = await this.executeStep(execution, step);
|
|
195
|
+
execution.results.set(step.id, stepResult);
|
|
196
|
+
execution.completed_steps.push(step.id);
|
|
197
|
+
|
|
198
|
+
// Log successful step for saga
|
|
199
|
+
this.logSagaStep(execution.id, step, stepResult);
|
|
200
|
+
|
|
201
|
+
} catch (error) {
|
|
202
|
+
execution.errors.set(step.id, error instanceof Error ? error : new Error(String(error)));
|
|
203
|
+
execution.failed_steps.push(step.id);
|
|
204
|
+
|
|
205
|
+
// If step failed, compensate previous steps
|
|
206
|
+
await this.compensateSteps(execution);
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
success: false,
|
|
210
|
+
transaction_id: execution.id,
|
|
211
|
+
compensations_applied: execution.compensations
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
execution.state = TransactionExecutionState.COMPLETED;
|
|
217
|
+
execution.end_time = new Date();
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
success: true,
|
|
221
|
+
transaction_id: execution.id,
|
|
222
|
+
results: execution.results
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
} catch (error) {
|
|
226
|
+
execution.state = TransactionExecutionState.FAILED;
|
|
227
|
+
execution.end_time = new Date();
|
|
228
|
+
|
|
229
|
+
await this.compensateSteps(execution);
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
success: false,
|
|
233
|
+
transaction_id: execution.id,
|
|
234
|
+
compensations_applied: execution.compensations
|
|
235
|
+
};
|
|
236
|
+
} finally {
|
|
237
|
+
this.activeTransactions.delete(definition.id);
|
|
238
|
+
this.sagaLog.delete(definition.id);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Create a distributed transaction across multiple ServiceNow instances
|
|
244
|
+
*/
|
|
245
|
+
async executeDistributedTransaction(
|
|
246
|
+
definition: TransactionDefinition,
|
|
247
|
+
participants: string[]
|
|
248
|
+
): Promise<{
|
|
249
|
+
success: boolean;
|
|
250
|
+
transaction_id: string;
|
|
251
|
+
participant_results?: Map<string, any>;
|
|
252
|
+
failed_participants?: string[];
|
|
253
|
+
}> {
|
|
254
|
+
const transactionId = definition.id;
|
|
255
|
+
const participantResults = new Map<string, any>();
|
|
256
|
+
const failedParticipants: string[] = [];
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
// Phase 1: Prepare all participants
|
|
260
|
+
const prepareResults = await Promise.allSettled(
|
|
261
|
+
participants.map(participant => this.prepareParticipant(participant, definition))
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
// Check if all participants are prepared
|
|
265
|
+
const allPrepared = prepareResults.every(result => result.status === 'fulfilled');
|
|
266
|
+
|
|
267
|
+
if (!allPrepared) {
|
|
268
|
+
// Abort transaction - some participants failed to prepare
|
|
269
|
+
await this.abortDistributedTransaction(transactionId, participants);
|
|
270
|
+
|
|
271
|
+
prepareResults.forEach((result, index) => {
|
|
272
|
+
if (result.status === 'rejected') {
|
|
273
|
+
failedParticipants.push(participants[index]);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
success: false,
|
|
279
|
+
transaction_id: transactionId,
|
|
280
|
+
failed_participants: failedParticipants
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Phase 2: Commit all participants
|
|
285
|
+
const commitResults = await Promise.allSettled(
|
|
286
|
+
participants.map(participant => this.commitParticipant(participant, transactionId))
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
// Check if all participants committed successfully
|
|
290
|
+
const allCommitted = commitResults.every(result => result.status === 'fulfilled');
|
|
291
|
+
|
|
292
|
+
if (!allCommitted) {
|
|
293
|
+
// Some participants failed to commit - this is a critical situation
|
|
294
|
+
this.logger.error('Distributed transaction commit failed', {
|
|
295
|
+
transactionId,
|
|
296
|
+
failedParticipants: commitResults
|
|
297
|
+
.map((result, index) => result.status === 'rejected' ? participants[index] : null)
|
|
298
|
+
.filter(Boolean)
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// Attempt to rollback successful commits
|
|
302
|
+
await this.rollbackDistributedTransaction(transactionId, participants);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
commitResults.forEach((result, index) => {
|
|
306
|
+
if (result.status === 'fulfilled') {
|
|
307
|
+
participantResults.set(participants[index], result.value);
|
|
308
|
+
} else {
|
|
309
|
+
failedParticipants.push(participants[index]);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
success: allCommitted,
|
|
315
|
+
transaction_id: transactionId,
|
|
316
|
+
participant_results: participantResults,
|
|
317
|
+
failed_participants: failedParticipants.length > 0 ? failedParticipants : undefined
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
} catch (error) {
|
|
321
|
+
this.logger.error('Distributed transaction failed', { transactionId, error });
|
|
322
|
+
await this.abortDistributedTransaction(transactionId, participants);
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
success: false,
|
|
326
|
+
transaction_id: transactionId,
|
|
327
|
+
failed_participants: participants
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Start transaction with isolation
|
|
334
|
+
*/
|
|
335
|
+
private async startTransaction(execution: TransactionExecution): Promise<void> {
|
|
336
|
+
execution.state = TransactionExecutionState.RUNNING;
|
|
337
|
+
this.logger.info('Starting transaction', { transactionId: execution.id });
|
|
338
|
+
|
|
339
|
+
// Acquire locks based on isolation level
|
|
340
|
+
await this.acquireLocks(execution);
|
|
341
|
+
|
|
342
|
+
// Start ServiceNow transaction tracking
|
|
343
|
+
const transactionId = this.errorHandler.startTransaction(execution.definition.name);
|
|
344
|
+
execution.id = transactionId;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Execute all steps in the transaction
|
|
349
|
+
*/
|
|
350
|
+
private async executeSteps(execution: TransactionExecution): Promise<{ success: boolean }> {
|
|
351
|
+
const steps = this.orderStepsByDependencies(execution.definition.steps);
|
|
352
|
+
|
|
353
|
+
for (const step of steps) {
|
|
354
|
+
execution.current_step = step.id;
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
// Check timeout
|
|
358
|
+
if (this.isTransactionTimeout(execution)) {
|
|
359
|
+
execution.state = TransactionExecutionState.TIMEOUT;
|
|
360
|
+
throw new Error('Transaction timeout');
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Execute step with retry
|
|
364
|
+
const result = await this.executeStepWithRetry(execution, step);
|
|
365
|
+
execution.results.set(step.id, result);
|
|
366
|
+
execution.completed_steps.push(step.id);
|
|
367
|
+
|
|
368
|
+
// Add to rollback stack
|
|
369
|
+
this.errorHandler.addOperation(execution.id, {
|
|
370
|
+
type: step.operation as any,
|
|
371
|
+
table: step.table,
|
|
372
|
+
record_id: result?.sys_id,
|
|
373
|
+
original_data: step.operation === 'update' ? step.data : undefined,
|
|
374
|
+
new_data: result,
|
|
375
|
+
dependencies: step.dependencies
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
} catch (error) {
|
|
379
|
+
execution.errors.set(step.id, error instanceof Error ? error : new Error(String(error)));
|
|
380
|
+
execution.failed_steps.push(step.id);
|
|
381
|
+
|
|
382
|
+
if (step.critical || execution.definition.rollback_on_error) {
|
|
383
|
+
return { success: false };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Continue with non-critical steps
|
|
387
|
+
this.logger.warn('Non-critical step failed, continuing', { stepId: step.id, error });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return { success: execution.failed_steps.length === 0 };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Execute a single step with retry logic
|
|
396
|
+
*/
|
|
397
|
+
private async executeStepWithRetry(execution: TransactionExecution, step: TransactionStep): Promise<any> {
|
|
398
|
+
const retryPolicy = execution.definition.retry_policy;
|
|
399
|
+
let lastError: Error | null = null;
|
|
400
|
+
let delay = retryPolicy.initial_delay;
|
|
401
|
+
|
|
402
|
+
for (let attempt = 1; attempt <= retryPolicy.max_attempts; attempt++) {
|
|
403
|
+
try {
|
|
404
|
+
return await this.executeStep(execution, step);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
407
|
+
|
|
408
|
+
// Check if error is retryable
|
|
409
|
+
const isRetryable = retryPolicy.retryable_errors.some(retryableError =>
|
|
410
|
+
lastError!.message.toLowerCase().includes(retryableError.toLowerCase())
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
if (!isRetryable || attempt === retryPolicy.max_attempts) {
|
|
414
|
+
throw lastError;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Wait before retry
|
|
418
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
419
|
+
delay = Math.min(delay * retryPolicy.backoff_multiplier, retryPolicy.max_delay);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
throw lastError;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Execute a single step
|
|
428
|
+
*/
|
|
429
|
+
private async executeStep(execution: TransactionExecution, step: TransactionStep): Promise<any> {
|
|
430
|
+
this.logger.debug('Executing step', { transactionId: execution.id, stepId: step.id });
|
|
431
|
+
|
|
432
|
+
// Check dependencies
|
|
433
|
+
for (const dependency of step.dependencies) {
|
|
434
|
+
if (!execution.completed_steps.includes(dependency)) {
|
|
435
|
+
throw new Error(`Dependency ${dependency} not completed`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Execute based on operation type
|
|
440
|
+
switch (step.operation) {
|
|
441
|
+
case 'create':
|
|
442
|
+
return await this.client.createRecord(step.table, step.data);
|
|
443
|
+
|
|
444
|
+
case 'update':
|
|
445
|
+
if (!step.data?.sys_id) {
|
|
446
|
+
throw new Error('sys_id required for update operation');
|
|
447
|
+
}
|
|
448
|
+
return await this.client.updateRecord(step.table, step.data.sys_id, step.data);
|
|
449
|
+
|
|
450
|
+
case 'delete':
|
|
451
|
+
if (!step.data?.sys_id) {
|
|
452
|
+
throw new Error('sys_id required for delete operation');
|
|
453
|
+
}
|
|
454
|
+
return await this.client.deleteRecord(step.table, step.data.sys_id);
|
|
455
|
+
|
|
456
|
+
case 'validate':
|
|
457
|
+
return await this.validateData(step.table, step.data, step.condition);
|
|
458
|
+
|
|
459
|
+
case 'custom':
|
|
460
|
+
if (step.data?.custom_function) {
|
|
461
|
+
return await step.data.custom_function();
|
|
462
|
+
}
|
|
463
|
+
throw new Error('Custom function not provided');
|
|
464
|
+
|
|
465
|
+
default:
|
|
466
|
+
throw new Error(`Unknown operation: ${step.operation}`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Commit transaction
|
|
472
|
+
*/
|
|
473
|
+
private async commitTransaction(execution: TransactionExecution): Promise<void> {
|
|
474
|
+
execution.state = TransactionExecutionState.COMPLETED;
|
|
475
|
+
execution.end_time = new Date();
|
|
476
|
+
|
|
477
|
+
// Commit ServiceNow transaction
|
|
478
|
+
await this.errorHandler.commitTransaction(execution.id);
|
|
479
|
+
|
|
480
|
+
// Release locks
|
|
481
|
+
await this.releaseLocks(execution);
|
|
482
|
+
|
|
483
|
+
this.logger.info('Transaction committed', { transactionId: execution.id });
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Rollback transaction
|
|
488
|
+
*/
|
|
489
|
+
private async rollbackTransaction(execution: TransactionExecution): Promise<void> {
|
|
490
|
+
execution.state = TransactionExecutionState.COMPENSATING;
|
|
491
|
+
|
|
492
|
+
try {
|
|
493
|
+
// Rollback ServiceNow transaction
|
|
494
|
+
await this.errorHandler.rollbackTransaction(execution.id);
|
|
495
|
+
|
|
496
|
+
// Apply compensations
|
|
497
|
+
await this.compensateSteps(execution);
|
|
498
|
+
|
|
499
|
+
execution.state = TransactionExecutionState.COMPENSATED;
|
|
500
|
+
} catch (error) {
|
|
501
|
+
execution.state = TransactionExecutionState.FAILED;
|
|
502
|
+
this.logger.error('Transaction rollback failed', { transactionId: execution.id, error });
|
|
503
|
+
} finally {
|
|
504
|
+
// Always release locks
|
|
505
|
+
await this.releaseLocks(execution);
|
|
506
|
+
execution.end_time = new Date();
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Apply compensations for completed steps
|
|
512
|
+
*/
|
|
513
|
+
private async compensateSteps(execution: TransactionExecution): Promise<void> {
|
|
514
|
+
const completedSteps = execution.definition.steps.filter(step =>
|
|
515
|
+
execution.completed_steps.includes(step.id)
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
// Apply compensations in reverse order
|
|
519
|
+
for (const step of completedSteps.reverse()) {
|
|
520
|
+
if (step.compensation) {
|
|
521
|
+
try {
|
|
522
|
+
await this.applyCompensation(execution, step.compensation);
|
|
523
|
+
execution.compensations.push(step.compensation);
|
|
524
|
+
} catch (error) {
|
|
525
|
+
this.logger.error('Compensation failed', { stepId: step.id, error });
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Apply a compensation action
|
|
533
|
+
*/
|
|
534
|
+
private async applyCompensation(execution: TransactionExecution, compensation: CompensationAction): Promise<void> {
|
|
535
|
+
switch (compensation.type) {
|
|
536
|
+
case 'delete':
|
|
537
|
+
const result = execution.results.get(compensation.table);
|
|
538
|
+
if (result?.sys_id) {
|
|
539
|
+
await this.client.deleteRecord(compensation.table, result.sys_id);
|
|
540
|
+
}
|
|
541
|
+
break;
|
|
542
|
+
|
|
543
|
+
case 'update':
|
|
544
|
+
if (compensation.data?.sys_id) {
|
|
545
|
+
await this.client.updateRecord(compensation.table, compensation.data.sys_id, compensation.data);
|
|
546
|
+
}
|
|
547
|
+
break;
|
|
548
|
+
|
|
549
|
+
case 'restore':
|
|
550
|
+
if (compensation.data) {
|
|
551
|
+
await this.client.createRecord(compensation.table, compensation.data);
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
|
|
555
|
+
case 'custom':
|
|
556
|
+
if (compensation.custom_function) {
|
|
557
|
+
await compensation.custom_function();
|
|
558
|
+
}
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Acquire locks for transaction isolation
|
|
565
|
+
*/
|
|
566
|
+
private async acquireLocks(execution: TransactionExecution): Promise<void> {
|
|
567
|
+
const resourcesToLock = new Set<string>();
|
|
568
|
+
|
|
569
|
+
// Collect resources to lock
|
|
570
|
+
for (const step of execution.definition.steps) {
|
|
571
|
+
if (step.operation === 'update' || step.operation === 'delete') {
|
|
572
|
+
resourcesToLock.add(`${step.table}:${step.data?.sys_id}`);
|
|
573
|
+
} else if (step.operation === 'create') {
|
|
574
|
+
resourcesToLock.add(`${step.table}:create`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Acquire locks
|
|
579
|
+
for (const resource of resourcesToLock) {
|
|
580
|
+
try {
|
|
581
|
+
const lockId = await this.lockManager.acquire(resource, execution.definition.timeout);
|
|
582
|
+
execution.locks.add(lockId);
|
|
583
|
+
} catch (error) {
|
|
584
|
+
// Release already acquired locks
|
|
585
|
+
await this.releaseLocks(execution);
|
|
586
|
+
throw new Error(`Failed to acquire lock for ${resource}: ${error}`);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Release all locks
|
|
593
|
+
*/
|
|
594
|
+
private async releaseLocks(execution: TransactionExecution): Promise<void> {
|
|
595
|
+
for (const lockId of execution.locks) {
|
|
596
|
+
try {
|
|
597
|
+
await this.lockManager.release(lockId);
|
|
598
|
+
} catch (error) {
|
|
599
|
+
this.logger.warn('Failed to release lock', { lockId, error });
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
execution.locks.clear();
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Order steps by dependencies
|
|
607
|
+
*/
|
|
608
|
+
private orderStepsByDependencies(steps: TransactionStep[]): TransactionStep[] {
|
|
609
|
+
const ordered: TransactionStep[] = [];
|
|
610
|
+
const remaining = [...steps];
|
|
611
|
+
|
|
612
|
+
while (remaining.length > 0) {
|
|
613
|
+
const nextSteps = remaining.filter(step =>
|
|
614
|
+
step.dependencies.every(dep => ordered.some(orderedStep => orderedStep.id === dep))
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
if (nextSteps.length === 0) {
|
|
618
|
+
throw new Error('Circular dependency detected in transaction steps');
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
ordered.push(...nextSteps);
|
|
622
|
+
remaining.splice(0, remaining.length, ...remaining.filter(step => !nextSteps.includes(step)));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
return ordered;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Check if transaction has timed out
|
|
630
|
+
*/
|
|
631
|
+
private isTransactionTimeout(execution: TransactionExecution): boolean {
|
|
632
|
+
const elapsed = Date.now() - execution.start_time.getTime();
|
|
633
|
+
return elapsed > execution.definition.timeout;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Validate data against condition
|
|
638
|
+
*/
|
|
639
|
+
private async validateData(table: string, data: any, condition?: string): Promise<boolean> {
|
|
640
|
+
if (!condition) return true;
|
|
641
|
+
|
|
642
|
+
// Simple validation logic - could be enhanced with more complex rules
|
|
643
|
+
const record = await this.client.getRecord(table, data.sys_id);
|
|
644
|
+
return record !== null;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Log saga step
|
|
649
|
+
*/
|
|
650
|
+
private logSagaStep(transactionId: string, step: TransactionStep, result: any): void {
|
|
651
|
+
const sagaLog = this.sagaLog.get(transactionId) || [];
|
|
652
|
+
sagaLog.push({
|
|
653
|
+
step_id: step.id,
|
|
654
|
+
operation: step.operation,
|
|
655
|
+
table: step.table,
|
|
656
|
+
result: result,
|
|
657
|
+
timestamp: new Date()
|
|
658
|
+
});
|
|
659
|
+
this.sagaLog.set(transactionId, sagaLog);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Prepare participant for distributed transaction
|
|
664
|
+
*/
|
|
665
|
+
private async prepareParticipant(participant: string, definition: TransactionDefinition): Promise<any> {
|
|
666
|
+
// Implementation would send prepare request to participant
|
|
667
|
+
// For now, return success
|
|
668
|
+
return { prepared: true, participant };
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Commit participant in distributed transaction
|
|
673
|
+
*/
|
|
674
|
+
private async commitParticipant(participant: string, transactionId: string): Promise<any> {
|
|
675
|
+
// Implementation would send commit request to participant
|
|
676
|
+
return { committed: true, participant };
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Abort distributed transaction
|
|
681
|
+
*/
|
|
682
|
+
private async abortDistributedTransaction(transactionId: string, participants: string[]): Promise<void> {
|
|
683
|
+
// Implementation would send abort request to all participants
|
|
684
|
+
this.logger.info('Aborting distributed transaction', { transactionId, participants });
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Rollback distributed transaction
|
|
689
|
+
*/
|
|
690
|
+
private async rollbackDistributedTransaction(transactionId: string, participants: string[]): Promise<void> {
|
|
691
|
+
// Implementation would send rollback request to all participants
|
|
692
|
+
this.logger.info('Rolling back distributed transaction', { transactionId, participants });
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Get transaction status
|
|
697
|
+
*/
|
|
698
|
+
getTransactionStatus(transactionId: string): TransactionExecution | null {
|
|
699
|
+
return this.activeTransactions.get(transactionId) || null;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Get all active transactions
|
|
704
|
+
*/
|
|
705
|
+
getActiveTransactions(): TransactionExecution[] {
|
|
706
|
+
return Array.from(this.activeTransactions.values());
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Simple lock manager implementation
|
|
712
|
+
*/
|
|
713
|
+
class SimpleLockManager implements LockManager {
|
|
714
|
+
private locks: Map<string, { lockId: string; owner: string; timestamp: Date }> = new Map();
|
|
715
|
+
|
|
716
|
+
async acquire(resource: string, timeout: number): Promise<string> {
|
|
717
|
+
const lockId = `lock_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
718
|
+
const startTime = Date.now();
|
|
719
|
+
|
|
720
|
+
while (Date.now() - startTime < timeout) {
|
|
721
|
+
if (!this.locks.has(resource)) {
|
|
722
|
+
this.locks.set(resource, {
|
|
723
|
+
lockId,
|
|
724
|
+
owner: 'transaction_manager',
|
|
725
|
+
timestamp: new Date()
|
|
726
|
+
});
|
|
727
|
+
return lockId;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Wait before retry
|
|
731
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
throw new Error(`Failed to acquire lock for ${resource}: timeout`);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
async release(lockId: string): Promise<void> {
|
|
738
|
+
for (const [resource, lock] of this.locks) {
|
|
739
|
+
if (lock.lockId === lockId) {
|
|
740
|
+
this.locks.delete(resource);
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
isLocked(resource: string): boolean {
|
|
747
|
+
return this.locks.has(resource);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
getLockOwner(resource: string): string | null {
|
|
751
|
+
const lock = this.locks.get(resource);
|
|
752
|
+
return lock ? lock.owner : null;
|
|
753
|
+
}
|
|
754
|
+
}
|