@codemation/host 0.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/README.md +75 -0
- package/dist/CodemationConfig-XCkSV2dj.d.ts +168 -0
- package/dist/CodemationConsumerConfigLoader-Dmm2TzAA.d.ts +61 -0
- package/dist/CodemationConsumerConfigLoader-scS_RQMy.js +334 -0
- package/dist/CodemationConsumerConfigLoader-scS_RQMy.js.map +1 -0
- package/dist/CodemationFrontendBootstrapRequest-CE6DjOWJ.js +5768 -0
- package/dist/CodemationFrontendBootstrapRequest-CE6DjOWJ.js.map +1 -0
- package/dist/CodemationPluginListMerger-BNmaoXQL.js +49 -0
- package/dist/CodemationPluginListMerger-BNmaoXQL.js.map +1 -0
- package/dist/CodemationPluginListMerger-BRYqEk0y.d.ts +793 -0
- package/dist/CodemationWhitelabelConfig-DgbjgtrR.d.ts +48 -0
- package/dist/ConsoleLogger-ClPU7jtc.js +35 -0
- package/dist/ConsoleLogger-ClPU7jtc.js.map +1 -0
- package/dist/CredentialServices-BKBGe7l3.js +1030 -0
- package/dist/CredentialServices-BKBGe7l3.js.map +1 -0
- package/dist/CredentialServices-DpDpm8mL.d.ts +291 -0
- package/dist/LogLevelPolicy-4cq9z0TI.d.ts +37 -0
- package/dist/PrismaMigrationDeployer-B1E_gYz7.js +8212 -0
- package/dist/PrismaMigrationDeployer-B1E_gYz7.js.map +1 -0
- package/dist/ServerLoggerFactory-BRHxIDS7.js +340 -0
- package/dist/ServerLoggerFactory-BRHxIDS7.js.map +1 -0
- package/dist/WorkflowViewContracts-DCLpTn25.d.ts +47 -0
- package/dist/chunk-7V6ThxGB.js +39 -0
- package/dist/client-Yh7-CQud.d.ts +21995 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +15 -0
- package/dist/client.js.map +1 -0
- package/dist/consumer.d.ts +5 -0
- package/dist/consumer.js +7 -0
- package/dist/credentials.d.ts +50 -0
- package/dist/credentials.js +11 -0
- package/dist/credentials.js.map +1 -0
- package/dist/decorate-B-N_5S4p.js +10 -0
- package/dist/decorateParam-BTcc3KNk.js +15 -0
- package/dist/devServerSidecar.d.ts +52 -0
- package/dist/devServerSidecar.js +131 -0
- package/dist/devServerSidecar.js.map +1 -0
- package/dist/index-Bs4F1IsC.d.ts +1044 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +14 -0
- package/dist/nextServer.d.ts +89 -0
- package/dist/nextServer.js +127 -0
- package/dist/nextServer.js.map +1 -0
- package/dist/persistenceServer-K5eqlZm3.d.ts +36 -0
- package/dist/persistenceServer-W9uRw0dJ.js +19 -0
- package/dist/persistenceServer-W9uRw0dJ.js.map +1 -0
- package/dist/persistenceServer.d.ts +6 -0
- package/dist/persistenceServer.js +6 -0
- package/dist/server-BBdsATju.d.ts +132 -0
- package/dist/server-BiHSuA13.js +175 -0
- package/dist/server-BiHSuA13.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +13 -0
- package/package.json +152 -0
- package/playwright.config.ts +74 -0
- package/prisma/migrations/20260315063514_init/migration.sql +16 -0
- package/prisma/migrations/20260316090000_workflow_debugger_overlay/migration.sql +9 -0
- package/prisma/migrations/20260317120000_trigger_state_store/migration.sql +3 -0
- package/prisma/migrations/20260317153000_trigger_setup_state/migration.sql +8 -0
- package/prisma/migrations/20260318110000_credentials_v2/migration.sql +49 -0
- package/prisma/migrations/20260319110000_credential_oauth2_material/migration.sql +28 -0
- package/prisma/migrations/20260319200000_codemation_auth_tables/migration.sql +56 -0
- package/prisma/migrations/20260320140000_user_invites_account_status/migration.sql +20 -0
- package/prisma/migrations/20260325120000_workflow_activation/migration.sql +8 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +179 -0
- package/prisma.config.ts +12 -0
- package/scripts/ensure-prisma-runtime-sourcemaps.mjs +42 -0
- package/scripts/integration-database-global-setup.mjs +30 -0
- package/src/application/ApplicationRequestError.ts +12 -0
- package/src/application/auth/AuthenticatedPrincipal.ts +5 -0
- package/src/application/auth/SessionVerifier.ts +5 -0
- package/src/application/binary/OverlayPinnedBinaryUploadService.ts +119 -0
- package/src/application/binary/RunBinaryAttachmentLookupService.ts +139 -0
- package/src/application/binary/RunStateBinaryStorageKeysCollector.ts +57 -0
- package/src/application/bus/Command.ts +3 -0
- package/src/application/bus/CommandBus.ts +5 -0
- package/src/application/bus/CommandHandler.ts +5 -0
- package/src/application/bus/DomainEvent.ts +1 -0
- package/src/application/bus/DomainEventBus.ts +5 -0
- package/src/application/bus/DomainEventHandler.ts +5 -0
- package/src/application/bus/Query.ts +3 -0
- package/src/application/bus/QueryBus.ts +5 -0
- package/src/application/bus/QueryHandler.ts +5 -0
- package/src/application/commands/AcceptUserInviteCommand.ts +10 -0
- package/src/application/commands/AcceptUserInviteCommandHandler.ts +19 -0
- package/src/application/commands/CopyRunToWorkflowDebuggerCommand.ts +14 -0
- package/src/application/commands/CopyRunToWorkflowDebuggerCommandHandler.ts +56 -0
- package/src/application/commands/CreateCredentialInstanceCommand.ts +9 -0
- package/src/application/commands/CreateCredentialInstanceCommandHandler.ts +28 -0
- package/src/application/commands/CredentialCommandHandlers.ts +10 -0
- package/src/application/commands/DeleteCredentialInstanceCommand.ts +7 -0
- package/src/application/commands/DeleteCredentialInstanceCommandHandler.ts +27 -0
- package/src/application/commands/HandleWebhookInvocationCommand.ts +12 -0
- package/src/application/commands/HandleWebhookInvocationCommandHandler.ts +42 -0
- package/src/application/commands/InviteUserCommand.ts +12 -0
- package/src/application/commands/InviteUserCommandHandler.ts +22 -0
- package/src/application/commands/RegenerateUserInviteCommand.ts +12 -0
- package/src/application/commands/RegenerateUserInviteCommandHandler.ts +24 -0
- package/src/application/commands/ReplaceMutableRunWorkflowSnapshotCommand.ts +12 -0
- package/src/application/commands/ReplaceMutableRunWorkflowSnapshotCommandHandler.ts +47 -0
- package/src/application/commands/ReplaceWorkflowDebuggerOverlayCommand.ts +14 -0
- package/src/application/commands/ReplaceWorkflowDebuggerOverlayCommandHandler.ts +35 -0
- package/src/application/commands/ReplayWorkflowNodeCommand.ts +12 -0
- package/src/application/commands/ReplayWorkflowNodeCommandHandler.ts +164 -0
- package/src/application/commands/SetPinnedNodeInputCommand.ts +13 -0
- package/src/application/commands/SetPinnedNodeInputCommandHandler.ts +50 -0
- package/src/application/commands/SetWorkflowActivationCommand.ts +10 -0
- package/src/application/commands/SetWorkflowActivationCommandHandler.ts +39 -0
- package/src/application/commands/StartWorkflowRunCommand.ts +8 -0
- package/src/application/commands/StartWorkflowRunCommandHandler.ts +286 -0
- package/src/application/commands/TestCredentialInstanceCommand.ts +9 -0
- package/src/application/commands/TestCredentialInstanceCommandHandler.ts +28 -0
- package/src/application/commands/UpdateCredentialInstanceCommand.ts +12 -0
- package/src/application/commands/UpdateCredentialInstanceCommandHandler.ts +28 -0
- package/src/application/commands/UpdateUserAccountStatusCommand.ts +12 -0
- package/src/application/commands/UpdateUserAccountStatusCommandHandler.ts +24 -0
- package/src/application/commands/UploadOverlayPinnedBinaryCommand.ts +16 -0
- package/src/application/commands/UploadOverlayPinnedBinaryCommandHandler.ts +31 -0
- package/src/application/commands/UpsertCredentialBindingCommand.ts +11 -0
- package/src/application/commands/UpsertCredentialBindingCommandHandler.ts +28 -0
- package/src/application/commands/UpsertLocalBootstrapUserCommand.ts +12 -0
- package/src/application/commands/UpsertLocalBootstrapUserCommandHandler.ts +24 -0
- package/src/application/commands/UserAccountCommandHandlers.ts +10 -0
- package/src/application/contracts/CredentialContractsRegistry.ts +88 -0
- package/src/application/contracts/RunContracts.ts +41 -0
- package/src/application/contracts/WorkflowDebuggerContracts.ts +12 -0
- package/src/application/contracts/WorkflowViewContracts.ts +40 -0
- package/src/application/contracts/WorkflowWebsocketMessage.ts +8 -0
- package/src/application/contracts/userDirectoryContracts.types.ts +60 -0
- package/src/application/dev/BootRuntimeSnapshotHolder.ts +19 -0
- package/src/application/dev/BootRuntimeSummary.types.ts +11 -0
- package/src/application/dev/DevBootstrapSummaryAssembler.ts +84 -0
- package/src/application/dev/DevBootstrapSummaryJson.types.ts +9 -0
- package/src/application/logging/LogFilter.ts +7 -0
- package/src/application/logging/Logger.ts +10 -0
- package/src/application/mapping/DataMapper.ts +3 -0
- package/src/application/mapping/WorkflowDefinitionMapper.ts +171 -0
- package/src/application/mapping/WorkflowPolicyUiPresentationFactory.ts +39 -0
- package/src/application/queries/CredentialQueryHandlers.ts +12 -0
- package/src/application/queries/GetCredentialFieldEnvStatusQuery.ts +5 -0
- package/src/application/queries/GetCredentialFieldEnvStatusQueryHandler.ts +52 -0
- package/src/application/queries/GetCredentialInstanceQuery.ts +9 -0
- package/src/application/queries/GetCredentialInstanceQueryHandler.ts +27 -0
- package/src/application/queries/GetCredentialInstanceWithSecretsQuery.ts +9 -0
- package/src/application/queries/GetCredentialInstanceWithSecretsQueryHandler.ts +27 -0
- package/src/application/queries/GetRunBinaryAttachmentQuery.ts +11 -0
- package/src/application/queries/GetRunBinaryAttachmentQueryHandler.ts +23 -0
- package/src/application/queries/GetRunStateQuery.ts +8 -0
- package/src/application/queries/GetRunStateQueryHandler.ts +21 -0
- package/src/application/queries/GetWorkflowCredentialHealthQuery.ts +9 -0
- package/src/application/queries/GetWorkflowCredentialHealthQueryHandler.ts +27 -0
- package/src/application/queries/GetWorkflowDebuggerOverlayQuery.ts +8 -0
- package/src/application/queries/GetWorkflowDebuggerOverlayQueryHandler.ts +28 -0
- package/src/application/queries/GetWorkflowDetailQuery.ts +8 -0
- package/src/application/queries/GetWorkflowDetailQueryHandler.ts +24 -0
- package/src/application/queries/GetWorkflowOverlayBinaryAttachmentQuery.ts +11 -0
- package/src/application/queries/GetWorkflowOverlayBinaryAttachmentQueryHandler.ts +23 -0
- package/src/application/queries/GetWorkflowSummariesQuery.ts +4 -0
- package/src/application/queries/GetWorkflowSummariesQueryHandler.ts +23 -0
- package/src/application/queries/ListCredentialInstancesQuery.ts +5 -0
- package/src/application/queries/ListCredentialInstancesQueryHandler.ts +27 -0
- package/src/application/queries/ListCredentialTypesQuery.ts +5 -0
- package/src/application/queries/ListCredentialTypesQueryHandler.ts +28 -0
- package/src/application/queries/ListUserAccountsQuery.ts +5 -0
- package/src/application/queries/ListUserAccountsQueryHandler.ts +22 -0
- package/src/application/queries/ListWorkflowRunsQuery.ts +8 -0
- package/src/application/queries/ListWorkflowRunsQueryHandler.ts +21 -0
- package/src/application/queries/UserAccountQueryHandlers.ts +4 -0
- package/src/application/queries/VerifyUserInviteQuery.ts +9 -0
- package/src/application/queries/VerifyUserInviteQueryHandler.ts +21 -0
- package/src/application/runs/WorkflowRunRetentionPruneScheduler.ts +98 -0
- package/src/application/websocket/WorkflowRunEventWebsocketRelay.ts +36 -0
- package/src/application/websocket/WorkflowWebsocketPublisher.ts +5 -0
- package/src/application/workflows/WebhookEndpointPathValidator.ts +35 -0
- package/src/application/workflows/WorkflowDebuggerOverlayStateFactory.ts +122 -0
- package/src/applicationTokens.ts +72 -0
- package/src/bootstrap/CodemationBootstrapRequest.ts +27 -0
- package/src/bootstrap/CodemationContainerFactory.ts +310 -0
- package/src/bootstrap/CodemationContainerRegistration.ts +23 -0
- package/src/bootstrap/CodemationContainerRegistrationRegistrar.ts +42 -0
- package/src/bootstrap/CodemationFrontendBootstrapRequest.ts +16 -0
- package/src/bootstrap/CodemationWorkerBootstrapRequest.ts +19 -0
- package/src/bootstrap/PreparedCodemationRuntime.ts +37 -0
- package/src/bootstrap/PreparedCodemationRuntimeFactory.ts +308 -0
- package/src/bootstrap/boot/CliRuntimeBootService.ts +27 -0
- package/src/bootstrap/boot/FrontendRuntimeBootService.ts +86 -0
- package/src/bootstrap/boot/WorkerRuntimeBootService.ts +64 -0
- package/src/bootstrap/runtime/AppConfigFactory.ts +57 -0
- package/src/bootstrap/runtime/ResolvedImplementationSelectionFactory.ts +118 -0
- package/src/client.ts +3 -0
- package/src/codemationApplication.ts +311 -0
- package/src/consumer.ts +4 -0
- package/src/credentials.ts +24 -0
- package/src/devServerSidecar.ts +10 -0
- package/src/domain/credentials/CredentialBindingService.ts +139 -0
- package/src/domain/credentials/CredentialFieldEnvOverlayService.ts +60 -0
- package/src/domain/credentials/CredentialInstanceService.ts +391 -0
- package/src/domain/credentials/CredentialMaterialResolver.ts +55 -0
- package/src/domain/credentials/CredentialRuntimeMaterialService.ts +39 -0
- package/src/domain/credentials/CredentialSecretCipher.ts +70 -0
- package/src/domain/credentials/CredentialServices.ts +145 -0
- package/src/domain/credentials/CredentialSessionServiceImpl.ts +119 -0
- package/src/domain/credentials/CredentialTestService.ts +73 -0
- package/src/domain/credentials/CredentialTypeRegistryImpl.ts +29 -0
- package/src/domain/credentials/OAuth2ConnectServiceFactory.ts +396 -0
- package/src/domain/credentials/OAuth2ProviderRegistry.ts +75 -0
- package/src/domain/credentials/WorkflowCredentialNodeResolver.ts +246 -0
- package/src/domain/runs/WorkflowRunRepository.ts +11 -0
- package/src/domain/users/UserAccountServiceRegistry.ts +315 -0
- package/src/domain/users/userLoginMethodLabels.types.ts +29 -0
- package/src/domain/workflows/WorkflowActivationPreflight.ts +32 -0
- package/src/domain/workflows/WorkflowActivationPreflightRules.ts +77 -0
- package/src/domain/workflows/WorkflowActivationRepository.ts +9 -0
- package/src/domain/workflows/WorkflowDebuggerOverlayRepository.ts +7 -0
- package/src/domain/workflows/WorkflowDebuggerOverlayState.ts +8 -0
- package/src/domain/workflows/WorkflowDefinitionRepository.ts +11 -0
- package/src/index.ts +58 -0
- package/src/infrastructure/auth/AuthJsSessionVerifier.ts +26 -0
- package/src/infrastructure/auth/DevelopmentSessionBypassVerifier.ts +12 -0
- package/src/infrastructure/binary/BinaryBodyNodeReadableFactory.ts +22 -0
- package/src/infrastructure/binary/CountingSha256Transform.ts +26 -0
- package/src/infrastructure/binary/LocalFilesystemBinaryStorageRegistry.ts +86 -0
- package/src/infrastructure/config/CodemationPluginRegistrar.ts +44 -0
- package/src/infrastructure/credentials/FrameworkBuiltinCredentialTypesRegistrar.ts +21 -0
- package/src/infrastructure/credentials/OpenAiApiKeyCredentialHealthTester.ts +89 -0
- package/src/infrastructure/credentials/OpenAiApiKeyCredentialShapes.types.ts +15 -0
- package/src/infrastructure/credentials/OpenAiApiKeyCredentialTypeFactory.ts +47 -0
- package/src/infrastructure/di/HandlesCommandRegistry.ts +24 -0
- package/src/infrastructure/di/HandlesDomainEventRegistry.ts +24 -0
- package/src/infrastructure/di/HandlesQueryRegistry.ts +24 -0
- package/src/infrastructure/di/InMemoryCommandBus.ts +47 -0
- package/src/infrastructure/di/InMemoryDomainEventBus.ts +47 -0
- package/src/infrastructure/di/InMemoryQueryBus.ts +45 -0
- package/src/infrastructure/ids/CodemationIdFactory.ts +12 -0
- package/src/infrastructure/logging/BrowserLogger.ts +1 -0
- package/src/infrastructure/logging/BrowserLoggerFactory.ts +14 -0
- package/src/infrastructure/logging/ConsoleLogger.ts +41 -0
- package/src/infrastructure/logging/FilteringLogger.ts +38 -0
- package/src/infrastructure/logging/LogLevelPolicy.ts +148 -0
- package/src/infrastructure/logging/LogLevelPolicyFactory.ts +16 -0
- package/src/infrastructure/logging/PerformanceLogPolicy.ts +10 -0
- package/src/infrastructure/logging/PerformanceLogPolicyFactory.ts +14 -0
- package/src/infrastructure/logging/ServerLogger.ts +1 -0
- package/src/infrastructure/logging/ServerLoggerFactory.ts +28 -0
- package/src/infrastructure/persistence/CodemationPostgresPrismaClientFactory.ts +9 -0
- package/src/infrastructure/persistence/CredentialPersistenceStore.ts +139 -0
- package/src/infrastructure/persistence/DatabasePersistenceResolver.ts +91 -0
- package/src/infrastructure/persistence/InMemoryTriggerSetupStateRepository.ts +23 -0
- package/src/infrastructure/persistence/InMemoryWorkflowActivationRepository.ts +18 -0
- package/src/infrastructure/persistence/InMemoryWorkflowDebuggerOverlayRepository.ts +16 -0
- package/src/infrastructure/persistence/InMemoryWorkflowRunRepository.ts +94 -0
- package/src/infrastructure/persistence/PrismaClientFactory.ts +26 -0
- package/src/infrastructure/persistence/PrismaCredentialStore.ts +368 -0
- package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +184 -0
- package/src/infrastructure/persistence/PrismaTriggerSetupStateRepository.ts +68 -0
- package/src/infrastructure/persistence/PrismaWorkflowActivationRepository.ts +36 -0
- package/src/infrastructure/persistence/PrismaWorkflowDebuggerOverlayRepository.ts +65 -0
- package/src/infrastructure/persistence/PrismaWorkflowRunRepository.ts +243 -0
- package/src/infrastructure/persistence/RuntimeWorkflowActivationPolicy.ts +27 -0
- package/src/infrastructure/persistence/SchedulerPersistenceCompatibilityValidator.ts +20 -0
- package/src/infrastructure/persistence/WorkflowDefinitionRepositoryAdapter.ts +31 -0
- package/src/infrastructure/persistence/WorkflowRunRepository.ts +46 -0
- package/src/infrastructure/persistence/generated/prisma/client.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma/default.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma/edge.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma/index.d.ts +4766 -0
- package/src/infrastructure/persistence/generated/prisma/package.json +144 -0
- package/src/infrastructure/persistence/generated/prisma/query_compiler_fast_bg.wasm +0 -0
- package/src/infrastructure/persistence/generated/prisma/runtime/client.d.ts +3358 -0
- package/src/infrastructure/persistence/generated/prisma/runtime/index-browser.d.ts +90 -0
- package/src/infrastructure/persistence/generated/prisma/schema.prisma +35 -0
- package/src/infrastructure/persistence/generated/prisma/wasm-edge-light-loader.mjs +5 -0
- package/src/infrastructure/persistence/generated/prisma/wasm-worker-loader.mjs +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/client.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/client.js +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/default.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/default.js +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/edge.d.ts +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/edge.js +299 -0
- package/src/infrastructure/persistence/generated/prisma-client/index-browser.js +325 -0
- package/src/infrastructure/persistence/generated/prisma-client/index.d.ts +21623 -0
- package/src/infrastructure/persistence/generated/prisma-client/index.js +299 -0
- package/src/infrastructure/persistence/generated/prisma-client/package.json +144 -0
- package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.js +2 -0
- package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.wasm +0 -0
- package/src/infrastructure/persistence/generated/prisma-client/query_compiler_fast_bg.wasm-base64.js +2 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/client.d.ts +3358 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/client.js +86 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/client.js.map +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.d.ts +90 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.js +6 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/index-browser.js.map +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/wasm-compiler-edge.js +76 -0
- package/src/infrastructure/persistence/generated/prisma-client/runtime/wasm-compiler-edge.js.map +1 -0
- package/src/infrastructure/persistence/generated/prisma-client/schema.prisma +179 -0
- package/src/infrastructure/persistence/generated/prisma-client/wasm-edge-light-loader.mjs +5 -0
- package/src/infrastructure/persistence/generated/prisma-client/wasm-worker-loader.mjs +5 -0
- package/src/infrastructure/runtime/LiveWorkflowRepository.ts +14 -0
- package/src/infrastructure/runtime/WorkerRuntimeScheduler.ts +35 -0
- package/src/infrastructure/server/http/ServerHttpRouteParams.ts +1 -0
- package/src/infrastructure/webhooks/RequestToWebhookItemMapper.ts +128 -0
- package/src/nextServer.ts +31 -0
- package/src/persistenceServer.ts +5 -0
- package/src/presentation/config/AppConfig.ts +25 -0
- package/src/presentation/config/CodemationAppContext.ts +19 -0
- package/src/presentation/config/CodemationApplicationFacade.ts +5 -0
- package/src/presentation/config/CodemationAuthConfig.ts +31 -0
- package/src/presentation/config/CodemationClassToken.ts +3 -0
- package/src/presentation/config/CodemationConfig.ts +86 -0
- package/src/presentation/config/CodemationConfigNormalizer.ts +179 -0
- package/src/presentation/config/CodemationLogConfig.ts +22 -0
- package/src/presentation/config/CodemationPackageManifest.ts +9 -0
- package/src/presentation/config/CodemationPlugin.ts +20 -0
- package/src/presentation/config/CodemationPluginListMerger.ts +46 -0
- package/src/presentation/config/CodemationWhitelabelConfig.ts +9 -0
- package/src/presentation/config/CodemationWorkflowDiscovery.ts +3 -0
- package/src/presentation/http/ApiPaths.ts +165 -0
- package/src/presentation/http/CodemationServerGatewayFactory.ts +120 -0
- package/src/presentation/http/HttpRequestJsonBodyReader.ts +12 -0
- package/src/presentation/http/ServerHttpErrorResponseFactory.ts +33 -0
- package/src/presentation/http/ServerHttpRouteParams.ts +1 -0
- package/src/presentation/http/hono/CodemationHonoApiAppFactory.ts +64 -0
- package/src/presentation/http/hono/HonoApiRouteRegistrar.ts +5 -0
- package/src/presentation/http/hono/HonoHttpAnonymousRoutePolicyRegistry.ts +27 -0
- package/src/presentation/http/hono/registrars/BinaryHonoApiRouteRegistrar.ts +21 -0
- package/src/presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar.ts +34 -0
- package/src/presentation/http/hono/registrars/DevHonoApiRouteRegistrar.ts +17 -0
- package/src/presentation/http/hono/registrars/OAuth2HonoApiRouteRegistrar.ts +18 -0
- package/src/presentation/http/hono/registrars/RunHonoApiRouteRegistrar.ts +31 -0
- package/src/presentation/http/hono/registrars/UserHonoApiRouteRegistrar.ts +24 -0
- package/src/presentation/http/hono/registrars/WebhookHonoApiRouteRegistrar.ts +23 -0
- package/src/presentation/http/hono/registrars/WhitelabelHonoApiRouteRegistrar.ts +18 -0
- package/src/presentation/http/hono/registrars/WorkflowHonoApiRouteRegistrar.ts +33 -0
- package/src/presentation/http/routeHandlers/BinaryHttpRouteHandlerFactory.ts +101 -0
- package/src/presentation/http/routeHandlers/CredentialHttpRouteHandler.ts +129 -0
- package/src/presentation/http/routeHandlers/DevBootstrapSummaryHttpRouteHandler.ts +21 -0
- package/src/presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory.ts +129 -0
- package/src/presentation/http/routeHandlers/RunHttpRouteHandler.ts +82 -0
- package/src/presentation/http/routeHandlers/UserHttpRouteHandlerFactory.ts +109 -0
- package/src/presentation/http/routeHandlers/WebhookHttpRouteHandler.ts +42 -0
- package/src/presentation/http/routeHandlers/WhitelabelLogoHttpRouteHandler.ts +96 -0
- package/src/presentation/http/routeHandlers/WorkflowHttpRouteHandler.ts +104 -0
- package/src/presentation/server/CodemationConsumerAppResolver.ts +82 -0
- package/src/presentation/server/CodemationConsumerConfigExportsResolver.ts +33 -0
- package/src/presentation/server/CodemationConsumerConfigLoader.ts +270 -0
- package/src/presentation/server/CodemationPluginDiscovery.ts +151 -0
- package/src/presentation/server/CodemationTsyringeParamInfoReader.ts +26 -0
- package/src/presentation/server/CodemationTsyringeTypeInfoRegistrar.ts +121 -0
- package/src/presentation/server/DevelopmentRuntimeRouteGuard.ts +59 -0
- package/src/presentation/server/DiscoveredWorkflowsEmptyMessageFactory.ts +11 -0
- package/src/presentation/server/WorkflowDefinitionExportsResolver.ts +24 -0
- package/src/presentation/server/WorkflowDiscoveryPathSegmentsComputer.ts +53 -0
- package/src/presentation/server/WorkflowModulePathFinder.ts +47 -0
- package/src/presentation/websocket/WorkflowWebsocketServer.ts +169 -0
- package/src/server.ts +14 -0
- package/tsconfig.json +10 -0
- package/vitest.shared.ts +45 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { PGLiteSocketServer } from "@electric-sql/pglite-socket";
|
|
3
|
+
import { injectable } from "@codemation/core";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import type { ResolvedDatabasePersistence } from "./DatabasePersistenceResolver";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Runs `prisma migrate deploy` against TCP PostgreSQL or against a PGlite data directory
|
|
13
|
+
* by temporarily exposing PGlite on a local Postgres protocol socket (see `@electric-sql/pglite-socket`).
|
|
14
|
+
*/
|
|
15
|
+
@injectable()
|
|
16
|
+
export class PrismaMigrationDeployer {
|
|
17
|
+
private readonly require = createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
async deployPersistence(persistence: ResolvedDatabasePersistence, env?: Readonly<NodeJS.ProcessEnv>): Promise<void> {
|
|
20
|
+
if (persistence.kind === "none") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (persistence.kind === "postgresql") {
|
|
24
|
+
await this.deployPostgres({ databaseUrl: persistence.databaseUrl, env });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
await this.deployPgliteViaPrismaCli({ dataDir: persistence.dataDir, env });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async deploy(args: Readonly<{ databaseUrl: string; env?: Readonly<NodeJS.ProcessEnv> }>): Promise<void> {
|
|
31
|
+
await this.deployPostgres(args);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private async deployPgliteViaPrismaCli(
|
|
35
|
+
args: Readonly<{ dataDir: string; env?: Readonly<NodeJS.ProcessEnv> }>,
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
let pglite: PGlite;
|
|
38
|
+
try {
|
|
39
|
+
pglite = new PGlite(args.dataDir);
|
|
40
|
+
await pglite.waitReady;
|
|
41
|
+
} catch (cause) {
|
|
42
|
+
throw this.createPgliteOpenFailureError(args.dataDir, cause);
|
|
43
|
+
}
|
|
44
|
+
const server = new PGLiteSocketServer({
|
|
45
|
+
db: pglite,
|
|
46
|
+
port: 0,
|
|
47
|
+
host: "127.0.0.1",
|
|
48
|
+
// Prisma migrate may use multiple connections; default maxConnections is 1.
|
|
49
|
+
maxConnections: 32,
|
|
50
|
+
});
|
|
51
|
+
await server.start();
|
|
52
|
+
try {
|
|
53
|
+
const databaseUrl = this.pgliteSocketConnectionToPostgresUrl(server.getServerConn());
|
|
54
|
+
await this.deployPostgres({ databaseUrl, env: args.env });
|
|
55
|
+
} finally {
|
|
56
|
+
await server.stop();
|
|
57
|
+
await pglite.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async deployPostgres(
|
|
62
|
+
args: Readonly<{ databaseUrl: string; env?: Readonly<NodeJS.ProcessEnv> }>,
|
|
63
|
+
): Promise<void> {
|
|
64
|
+
await new Promise<void>((resolve, reject) => {
|
|
65
|
+
const command = spawn(
|
|
66
|
+
process.execPath,
|
|
67
|
+
[this.resolvePrismaCliPath(), "migrate", "deploy", "--config", this.resolvePrismaConfigPath()],
|
|
68
|
+
{
|
|
69
|
+
cwd: this.resolvePackageRoot(),
|
|
70
|
+
env: this.createProcessEnvironment(args.databaseUrl, args.env),
|
|
71
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
let stdout = "";
|
|
75
|
+
let stderr = "";
|
|
76
|
+
command.stdout.on("data", (chunk: Buffer | string) => {
|
|
77
|
+
stdout += chunk.toString();
|
|
78
|
+
});
|
|
79
|
+
command.stderr.on("data", (chunk: Buffer | string) => {
|
|
80
|
+
stderr += chunk.toString();
|
|
81
|
+
});
|
|
82
|
+
command.once("error", (error) => {
|
|
83
|
+
reject(error);
|
|
84
|
+
});
|
|
85
|
+
command.once("close", (exitCode) => {
|
|
86
|
+
if (exitCode === 0) {
|
|
87
|
+
resolve();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
reject(this.createDeployError(exitCode, stdout, stderr));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* {@link PGLiteSocketServer.getServerConn} returns `host:port` or a unix socket path — Prisma requires a `postgresql://` URL.
|
|
97
|
+
* The query engine expects `sslmode=disable` on this loopback socket and a user (PGlite accepts `postgres`).
|
|
98
|
+
*/
|
|
99
|
+
private pgliteSocketConnectionToPostgresUrl(raw: string): string {
|
|
100
|
+
if (raw.startsWith("postgresql://") || raw.startsWith("postgres://")) {
|
|
101
|
+
return raw.includes("sslmode=") ? raw : `${raw}${raw.includes("?") ? "&" : "?"}sslmode=disable`;
|
|
102
|
+
}
|
|
103
|
+
if (raw.startsWith("/")) {
|
|
104
|
+
return `postgresql://postgres@localhost/postgres?host=${encodeURIComponent(raw)}&sslmode=disable`;
|
|
105
|
+
}
|
|
106
|
+
const colon = raw.lastIndexOf(":");
|
|
107
|
+
if (colon <= 0 || colon === raw.length - 1) {
|
|
108
|
+
throw new Error(`Unexpected PGlite socket connection string: ${raw}`);
|
|
109
|
+
}
|
|
110
|
+
const host = raw.slice(0, colon);
|
|
111
|
+
const port = raw.slice(colon + 1);
|
|
112
|
+
return `postgresql://postgres@${host}:${port}/postgres?sslmode=disable`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private createProcessEnvironment(databaseUrl: string, env?: Readonly<NodeJS.ProcessEnv>): NodeJS.ProcessEnv {
|
|
116
|
+
return {
|
|
117
|
+
...process.env,
|
|
118
|
+
...(env ?? {}),
|
|
119
|
+
DATABASE_URL: databaseUrl,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private resolvePrismaCliPath(): string {
|
|
124
|
+
const configuredPath = process.env.CODEMATION_PRISMA_CLI_PATH;
|
|
125
|
+
if (configuredPath && existsSync(configuredPath)) {
|
|
126
|
+
return configuredPath;
|
|
127
|
+
}
|
|
128
|
+
const packageManagerCandidates = [
|
|
129
|
+
path.resolve(process.cwd(), "node_modules", "prisma", "build", "index.js"),
|
|
130
|
+
path.resolve(this.resolvePackageRoot(), "node_modules", "prisma", "build", "index.js"),
|
|
131
|
+
];
|
|
132
|
+
for (const candidate of packageManagerCandidates) {
|
|
133
|
+
if (existsSync(candidate)) {
|
|
134
|
+
return candidate;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
return this.require.resolve("prisma/build/index.js", {
|
|
139
|
+
paths: [process.cwd(), this.resolvePackageRoot()],
|
|
140
|
+
});
|
|
141
|
+
} catch {
|
|
142
|
+
throw new Error(
|
|
143
|
+
"Unable to resolve the Prisma CLI required for startup migrations. Ensure `prisma` is installed.",
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private resolvePrismaConfigPath(): string {
|
|
149
|
+
const configuredPath = process.env.CODEMATION_PRISMA_CONFIG_PATH;
|
|
150
|
+
if (configuredPath) {
|
|
151
|
+
return configuredPath;
|
|
152
|
+
}
|
|
153
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "prisma.config.ts");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
resolvePackageRoot(): string {
|
|
157
|
+
const configuredRoot = process.env.CODEMATION_HOST_PACKAGE_ROOT;
|
|
158
|
+
if (configuredRoot) {
|
|
159
|
+
return configuredRoot;
|
|
160
|
+
}
|
|
161
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private createPgliteOpenFailureError(dataDir: string, cause: unknown): Error {
|
|
165
|
+
const underlying = cause instanceof Error ? cause.message : String(cause);
|
|
166
|
+
return new Error(
|
|
167
|
+
[
|
|
168
|
+
`PGlite could not open "${dataDir}".`,
|
|
169
|
+
"Embedded PGlite files are sometimes left in a bad state after a crash, kill -9, or interrupted migration.",
|
|
170
|
+
"If this is a dev database you can recreate, delete that directory and run again.",
|
|
171
|
+
`Underlying error: ${underlying}`,
|
|
172
|
+
].join(" "),
|
|
173
|
+
{ cause: cause instanceof Error ? cause : undefined },
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private createDeployError(exitCode: number | null, stdout: string, stderr: string): Error {
|
|
178
|
+
const output = stderr.trim() || stdout.trim();
|
|
179
|
+
if (!output) {
|
|
180
|
+
return new Error(`Prisma migrate deploy failed during startup with exit code ${exitCode ?? "unknown"}.`);
|
|
181
|
+
}
|
|
182
|
+
return new Error(`Prisma migrate deploy failed during startup with exit code ${exitCode ?? "unknown"}.\n${output}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PersistedTriggerSetupState, TriggerInstanceId, TriggerSetupStateRepository } from "@codemation/core";
|
|
2
|
+
import { inject, injectable } from "@codemation/core";
|
|
3
|
+
import { PrismaClient } from "./generated/prisma-client/client.js";
|
|
4
|
+
|
|
5
|
+
type TriggerSetupStateJson = Readonly<{
|
|
6
|
+
state: PersistedTriggerSetupState["state"];
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
@injectable()
|
|
10
|
+
export class PrismaTriggerSetupStateRepository implements TriggerSetupStateRepository {
|
|
11
|
+
constructor(@inject(PrismaClient) private readonly prisma: PrismaClient) {}
|
|
12
|
+
|
|
13
|
+
async load(trigger: TriggerInstanceId): Promise<PersistedTriggerSetupState | undefined> {
|
|
14
|
+
const row = await this.prisma.triggerSetupState.findUnique({
|
|
15
|
+
where: {
|
|
16
|
+
workflowId_nodeId: {
|
|
17
|
+
workflowId: trigger.workflowId,
|
|
18
|
+
nodeId: trigger.nodeId,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
if (!row) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
trigger: {
|
|
27
|
+
workflowId: row.workflowId,
|
|
28
|
+
nodeId: row.nodeId,
|
|
29
|
+
},
|
|
30
|
+
updatedAt: row.updatedAt,
|
|
31
|
+
state: (JSON.parse(row.stateJson) as TriggerSetupStateJson).state,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async save(state: PersistedTriggerSetupState): Promise<void> {
|
|
36
|
+
await this.prisma.triggerSetupState.upsert({
|
|
37
|
+
where: {
|
|
38
|
+
workflowId_nodeId: {
|
|
39
|
+
workflowId: state.trigger.workflowId,
|
|
40
|
+
nodeId: state.trigger.nodeId,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
create: {
|
|
44
|
+
workflowId: state.trigger.workflowId,
|
|
45
|
+
nodeId: state.trigger.nodeId,
|
|
46
|
+
updatedAt: state.updatedAt,
|
|
47
|
+
stateJson: JSON.stringify({
|
|
48
|
+
state: state.state,
|
|
49
|
+
} satisfies TriggerSetupStateJson),
|
|
50
|
+
},
|
|
51
|
+
update: {
|
|
52
|
+
updatedAt: state.updatedAt,
|
|
53
|
+
stateJson: JSON.stringify({
|
|
54
|
+
state: state.state,
|
|
55
|
+
} satisfies TriggerSetupStateJson),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async delete(trigger: TriggerInstanceId): Promise<void> {
|
|
61
|
+
await this.prisma.triggerSetupState.deleteMany({
|
|
62
|
+
where: {
|
|
63
|
+
workflowId: trigger.workflowId,
|
|
64
|
+
nodeId: trigger.nodeId,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { inject, injectable } from "@codemation/core";
|
|
2
|
+
import { PrismaClient } from "./generated/prisma-client/client.js";
|
|
3
|
+
import type {
|
|
4
|
+
WorkflowActivationRepository,
|
|
5
|
+
WorkflowActivationRow,
|
|
6
|
+
} from "../../domain/workflows/WorkflowActivationRepository";
|
|
7
|
+
|
|
8
|
+
@injectable()
|
|
9
|
+
export class PrismaWorkflowActivationRepository implements WorkflowActivationRepository {
|
|
10
|
+
constructor(@inject(PrismaClient) private readonly prisma: PrismaClient) {}
|
|
11
|
+
|
|
12
|
+
async loadAll(): Promise<ReadonlyArray<WorkflowActivationRow>> {
|
|
13
|
+
const rows = await this.prisma.workflowActivation.findMany();
|
|
14
|
+
return rows.map((row) => ({
|
|
15
|
+
workflowId: row.workflowId,
|
|
16
|
+
isActive: row.isActive,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async upsert(workflowId: string, active: boolean): Promise<void> {
|
|
21
|
+
const id = decodeURIComponent(workflowId);
|
|
22
|
+
const updatedAt = new Date().toISOString();
|
|
23
|
+
await this.prisma.workflowActivation.upsert({
|
|
24
|
+
where: { workflowId: id },
|
|
25
|
+
create: {
|
|
26
|
+
workflowId: id,
|
|
27
|
+
isActive: active,
|
|
28
|
+
updatedAt,
|
|
29
|
+
},
|
|
30
|
+
update: {
|
|
31
|
+
isActive: active,
|
|
32
|
+
updatedAt,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { RunCurrentState } from "@codemation/core";
|
|
2
|
+
import { inject, injectable } from "@codemation/core";
|
|
3
|
+
import type { WorkflowDebuggerOverlayRepository } from "../../domain/workflows/WorkflowDebuggerOverlayRepository";
|
|
4
|
+
import type { WorkflowDebuggerOverlayState } from "../../domain/workflows/WorkflowDebuggerOverlayState";
|
|
5
|
+
import { PrismaClient } from "./generated/prisma-client/client.js";
|
|
6
|
+
|
|
7
|
+
type DebuggerOverlayStateJson = Readonly<{
|
|
8
|
+
currentState: RunCurrentState;
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
@injectable()
|
|
12
|
+
export class PrismaWorkflowDebuggerOverlayRepository implements WorkflowDebuggerOverlayRepository {
|
|
13
|
+
constructor(@inject(PrismaClient) private readonly prisma: PrismaClient) {}
|
|
14
|
+
|
|
15
|
+
async load(workflowId: string): Promise<WorkflowDebuggerOverlayState | undefined> {
|
|
16
|
+
const decodedWorkflowId = decodeURIComponent(workflowId);
|
|
17
|
+
const row = await this.prisma.workflowDebuggerOverlay.findUnique({
|
|
18
|
+
where: { workflowId: decodedWorkflowId },
|
|
19
|
+
});
|
|
20
|
+
if (!row) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return this.rowToState(row);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async save(state: WorkflowDebuggerOverlayState): Promise<void> {
|
|
27
|
+
await this.prisma.workflowDebuggerOverlay.upsert({
|
|
28
|
+
where: { workflowId: state.workflowId },
|
|
29
|
+
create: {
|
|
30
|
+
workflowId: state.workflowId,
|
|
31
|
+
updatedAt: state.updatedAt,
|
|
32
|
+
copiedFromRunId: state.copiedFromRunId ?? null,
|
|
33
|
+
stateJson: JSON.stringify(this.toStateJson(state)),
|
|
34
|
+
},
|
|
35
|
+
update: {
|
|
36
|
+
updatedAt: state.updatedAt,
|
|
37
|
+
copiedFromRunId: state.copiedFromRunId ?? null,
|
|
38
|
+
stateJson: JSON.stringify(this.toStateJson(state)),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private rowToState(
|
|
44
|
+
row: Readonly<{
|
|
45
|
+
workflowId: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
copiedFromRunId: string | null;
|
|
48
|
+
stateJson: string;
|
|
49
|
+
}>,
|
|
50
|
+
): WorkflowDebuggerOverlayState {
|
|
51
|
+
const parsed = JSON.parse(row.stateJson) as DebuggerOverlayStateJson;
|
|
52
|
+
return {
|
|
53
|
+
workflowId: row.workflowId,
|
|
54
|
+
updatedAt: row.updatedAt,
|
|
55
|
+
copiedFromRunId: row.copiedFromRunId ?? undefined,
|
|
56
|
+
currentState: parsed.currentState,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private toStateJson(state: WorkflowDebuggerOverlayState): DebuggerOverlayStateJson {
|
|
61
|
+
return {
|
|
62
|
+
currentState: state.currentState,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NodeId,
|
|
3
|
+
NodeOutputs,
|
|
4
|
+
ParentExecutionRef,
|
|
5
|
+
PersistedRunState,
|
|
6
|
+
RunId,
|
|
7
|
+
RunPruneCandidate,
|
|
8
|
+
RunSummary,
|
|
9
|
+
WorkflowExecutionRepository,
|
|
10
|
+
WorkflowId,
|
|
11
|
+
} from "@codemation/core";
|
|
12
|
+
import { inject, injectable } from "@codemation/core";
|
|
13
|
+
import type { WorkflowRunRepository } from "../../domain/runs/WorkflowRunRepository";
|
|
14
|
+
import { PrismaClient } from "./generated/prisma-client/client.js";
|
|
15
|
+
|
|
16
|
+
/** JSON blob stored in stateJson: workflowSnapshot, mutableState, pending, queue, outputsByNode, nodeSnapshotsByNodeId, connectionInvocations, engineCounters */
|
|
17
|
+
interface StateJsonBlob {
|
|
18
|
+
control?: PersistedRunState["control"];
|
|
19
|
+
workflowSnapshot?: PersistedRunState["workflowSnapshot"];
|
|
20
|
+
mutableState?: PersistedRunState["mutableState"];
|
|
21
|
+
policySnapshot?: PersistedRunState["policySnapshot"];
|
|
22
|
+
engineCounters?: PersistedRunState["engineCounters"];
|
|
23
|
+
pending?: PersistedRunState["pending"];
|
|
24
|
+
queue: PersistedRunState["queue"];
|
|
25
|
+
outputsByNode: Record<NodeId, NodeOutputs>;
|
|
26
|
+
nodeSnapshotsByNodeId: PersistedRunState["nodeSnapshotsByNodeId"];
|
|
27
|
+
connectionInvocations?: PersistedRunState["connectionInvocations"];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@injectable()
|
|
31
|
+
export class PrismaWorkflowRunRepository implements WorkflowRunRepository, WorkflowExecutionRepository {
|
|
32
|
+
constructor(@inject(PrismaClient) private readonly prisma: PrismaClient) {}
|
|
33
|
+
|
|
34
|
+
async createRun(args: {
|
|
35
|
+
runId: RunId;
|
|
36
|
+
workflowId: WorkflowId;
|
|
37
|
+
startedAt: string;
|
|
38
|
+
parent?: ParentExecutionRef;
|
|
39
|
+
executionOptions?: PersistedRunState["executionOptions"];
|
|
40
|
+
control?: PersistedRunState["control"];
|
|
41
|
+
workflowSnapshot?: PersistedRunState["workflowSnapshot"];
|
|
42
|
+
mutableState?: PersistedRunState["mutableState"];
|
|
43
|
+
policySnapshot?: PersistedRunState["policySnapshot"];
|
|
44
|
+
engineCounters?: PersistedRunState["engineCounters"];
|
|
45
|
+
}): Promise<void> {
|
|
46
|
+
const now = new Date().toISOString();
|
|
47
|
+
const state: PersistedRunState = {
|
|
48
|
+
runId: args.runId,
|
|
49
|
+
workflowId: args.workflowId,
|
|
50
|
+
startedAt: args.startedAt,
|
|
51
|
+
parent: args.parent,
|
|
52
|
+
executionOptions: args.executionOptions,
|
|
53
|
+
control: args.control,
|
|
54
|
+
workflowSnapshot: args.workflowSnapshot,
|
|
55
|
+
mutableState: args.mutableState,
|
|
56
|
+
policySnapshot: args.policySnapshot,
|
|
57
|
+
engineCounters: args.engineCounters,
|
|
58
|
+
status: "running",
|
|
59
|
+
queue: [],
|
|
60
|
+
outputsByNode: {} as Record<NodeId, NodeOutputs>,
|
|
61
|
+
nodeSnapshotsByNodeId: {},
|
|
62
|
+
connectionInvocations: [],
|
|
63
|
+
};
|
|
64
|
+
const stateJson = this.serializeStateBlob(state);
|
|
65
|
+
await this.prisma.run.create({
|
|
66
|
+
data: {
|
|
67
|
+
runId: args.runId,
|
|
68
|
+
workflowId: args.workflowId,
|
|
69
|
+
startedAt: args.startedAt,
|
|
70
|
+
status: "running",
|
|
71
|
+
parentJson: args.parent ? JSON.stringify(args.parent) : null,
|
|
72
|
+
executionOptionsJson: args.executionOptions ? JSON.stringify(args.executionOptions) : null,
|
|
73
|
+
updatedAt: now,
|
|
74
|
+
stateJson,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async load(runId: string): Promise<PersistedRunState | undefined> {
|
|
80
|
+
const id = decodeURIComponent(runId) as RunId;
|
|
81
|
+
const row = await this.prisma.run.findUnique({ where: { runId: id } });
|
|
82
|
+
if (!row) return undefined;
|
|
83
|
+
return this.rowToPersistedRunState(row);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async save(state: PersistedRunState): Promise<void> {
|
|
87
|
+
const now = new Date().toISOString();
|
|
88
|
+
const stateJson = this.serializeStateBlob(state);
|
|
89
|
+
await this.prisma.run.upsert({
|
|
90
|
+
where: { runId: state.runId },
|
|
91
|
+
create: {
|
|
92
|
+
runId: state.runId,
|
|
93
|
+
workflowId: state.workflowId,
|
|
94
|
+
startedAt: state.startedAt,
|
|
95
|
+
status: state.status,
|
|
96
|
+
parentJson: state.parent ? JSON.stringify(state.parent) : null,
|
|
97
|
+
executionOptionsJson: state.executionOptions ? JSON.stringify(state.executionOptions) : null,
|
|
98
|
+
updatedAt: now,
|
|
99
|
+
stateJson,
|
|
100
|
+
},
|
|
101
|
+
update: {
|
|
102
|
+
status: state.status,
|
|
103
|
+
parentJson: state.parent ? JSON.stringify(state.parent) : null,
|
|
104
|
+
executionOptionsJson: state.executionOptions ? JSON.stringify(state.executionOptions) : null,
|
|
105
|
+
updatedAt: now,
|
|
106
|
+
stateJson,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async listRuns(args: Readonly<{ workflowId?: string; limit?: number }>): Promise<ReadonlyArray<RunSummary>> {
|
|
112
|
+
const limit = args?.limit ?? 50;
|
|
113
|
+
const workflowId = args?.workflowId ? decodeURIComponent(args.workflowId) : undefined;
|
|
114
|
+
const rows = await this.prisma.run.findMany({
|
|
115
|
+
where: workflowId ? { workflowId } : undefined,
|
|
116
|
+
orderBy: { startedAt: "desc" },
|
|
117
|
+
take: limit,
|
|
118
|
+
});
|
|
119
|
+
return rows.map((r) => this.rowToRunSummary(r));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async deleteRun(runId: RunId): Promise<void> {
|
|
123
|
+
const id = decodeURIComponent(runId);
|
|
124
|
+
await this.prisma.run.delete({ where: { runId: id } });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async listRunsOlderThan(
|
|
128
|
+
args: Readonly<{ beforeIso: string; limit?: number }>,
|
|
129
|
+
): Promise<ReadonlyArray<RunPruneCandidate>> {
|
|
130
|
+
const limit = args.limit ?? 100;
|
|
131
|
+
const rows = await this.prisma.run.findMany({
|
|
132
|
+
where: {
|
|
133
|
+
status: { in: ["completed", "failed"] },
|
|
134
|
+
updatedAt: { lt: args.beforeIso },
|
|
135
|
+
},
|
|
136
|
+
orderBy: { updatedAt: "asc" },
|
|
137
|
+
take: limit,
|
|
138
|
+
});
|
|
139
|
+
return rows.map((r) => this.rowToPruneCandidate(r));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private serializeStateBlob(state: PersistedRunState): string {
|
|
143
|
+
const blob: StateJsonBlob = {
|
|
144
|
+
control: state.control,
|
|
145
|
+
workflowSnapshot: state.workflowSnapshot,
|
|
146
|
+
mutableState: state.mutableState,
|
|
147
|
+
policySnapshot: state.policySnapshot,
|
|
148
|
+
engineCounters: state.engineCounters,
|
|
149
|
+
pending: state.pending,
|
|
150
|
+
queue: state.queue,
|
|
151
|
+
outputsByNode: state.outputsByNode,
|
|
152
|
+
nodeSnapshotsByNodeId: state.nodeSnapshotsByNodeId,
|
|
153
|
+
connectionInvocations: state.connectionInvocations,
|
|
154
|
+
};
|
|
155
|
+
return JSON.stringify(blob);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private parseStateBlob(json: string): StateJsonBlob {
|
|
159
|
+
const parsed = JSON.parse(json) as StateJsonBlob;
|
|
160
|
+
return {
|
|
161
|
+
control: parsed.control,
|
|
162
|
+
workflowSnapshot: parsed.workflowSnapshot,
|
|
163
|
+
mutableState: parsed.mutableState,
|
|
164
|
+
policySnapshot: parsed.policySnapshot,
|
|
165
|
+
engineCounters: parsed.engineCounters,
|
|
166
|
+
pending: parsed.pending,
|
|
167
|
+
queue: parsed.queue ?? [],
|
|
168
|
+
outputsByNode: (parsed.outputsByNode ?? {}) as Record<NodeId, NodeOutputs>,
|
|
169
|
+
nodeSnapshotsByNodeId: parsed.nodeSnapshotsByNodeId ?? {},
|
|
170
|
+
connectionInvocations: parsed.connectionInvocations,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private rowToPersistedRunState(row: {
|
|
175
|
+
runId: string;
|
|
176
|
+
workflowId: string;
|
|
177
|
+
startedAt: string;
|
|
178
|
+
status: string;
|
|
179
|
+
parentJson: string | null;
|
|
180
|
+
executionOptionsJson: string | null;
|
|
181
|
+
stateJson: string;
|
|
182
|
+
}): PersistedRunState {
|
|
183
|
+
const blob = this.parseStateBlob(row.stateJson);
|
|
184
|
+
return {
|
|
185
|
+
runId: row.runId as RunId,
|
|
186
|
+
workflowId: row.workflowId as WorkflowId,
|
|
187
|
+
startedAt: row.startedAt,
|
|
188
|
+
status: row.status as PersistedRunState["status"],
|
|
189
|
+
parent: row.parentJson ? (JSON.parse(row.parentJson) as ParentExecutionRef) : undefined,
|
|
190
|
+
executionOptions: row.executionOptionsJson
|
|
191
|
+
? (JSON.parse(row.executionOptionsJson) as PersistedRunState["executionOptions"])
|
|
192
|
+
: undefined,
|
|
193
|
+
control: blob.control,
|
|
194
|
+
workflowSnapshot: blob.workflowSnapshot,
|
|
195
|
+
mutableState: blob.mutableState,
|
|
196
|
+
policySnapshot: blob.policySnapshot,
|
|
197
|
+
engineCounters: blob.engineCounters,
|
|
198
|
+
pending: blob.pending,
|
|
199
|
+
queue: blob.queue,
|
|
200
|
+
outputsByNode: blob.outputsByNode,
|
|
201
|
+
nodeSnapshotsByNodeId: blob.nodeSnapshotsByNodeId,
|
|
202
|
+
connectionInvocations: blob.connectionInvocations,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private rowToPruneCandidate(row: {
|
|
207
|
+
runId: string;
|
|
208
|
+
workflowId: string;
|
|
209
|
+
startedAt: string;
|
|
210
|
+
updatedAt: string;
|
|
211
|
+
}): RunPruneCandidate {
|
|
212
|
+
return {
|
|
213
|
+
runId: row.runId as RunId,
|
|
214
|
+
workflowId: row.workflowId as WorkflowId,
|
|
215
|
+
startedAt: row.startedAt,
|
|
216
|
+
finishedAt: row.updatedAt,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private rowToRunSummary(row: {
|
|
221
|
+
runId: string;
|
|
222
|
+
workflowId: string;
|
|
223
|
+
startedAt: string;
|
|
224
|
+
status: string;
|
|
225
|
+
parentJson: string | null;
|
|
226
|
+
executionOptionsJson: string | null;
|
|
227
|
+
updatedAt: string;
|
|
228
|
+
}): RunSummary {
|
|
229
|
+
const status = row.status as RunSummary["status"];
|
|
230
|
+
const finishedAt = status === "completed" || status === "failed" ? row.updatedAt : undefined;
|
|
231
|
+
return {
|
|
232
|
+
runId: row.runId as RunId,
|
|
233
|
+
workflowId: row.workflowId as WorkflowId,
|
|
234
|
+
startedAt: row.startedAt,
|
|
235
|
+
status,
|
|
236
|
+
finishedAt,
|
|
237
|
+
parent: row.parentJson ? (JSON.parse(row.parentJson) as ParentExecutionRef) : undefined,
|
|
238
|
+
executionOptions: row.executionOptionsJson
|
|
239
|
+
? (JSON.parse(row.executionOptionsJson) as RunSummary["executionOptions"])
|
|
240
|
+
: undefined,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WorkflowActivationPolicy, WorkflowId } from "@codemation/core";
|
|
2
|
+
import { injectable } from "@codemation/core";
|
|
3
|
+
import type { WorkflowActivationRepository } from "../../domain/workflows/WorkflowActivationRepository";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In-memory activation map: missing workflow id ⇒ inactive. Hydrated from persistence at startup and updated on command.
|
|
7
|
+
*/
|
|
8
|
+
@injectable()
|
|
9
|
+
export class RuntimeWorkflowActivationPolicy implements WorkflowActivationPolicy {
|
|
10
|
+
private readonly activeByWorkflowId = new Map<string, boolean>();
|
|
11
|
+
|
|
12
|
+
async hydrateFromRepository(repository: WorkflowActivationRepository): Promise<void> {
|
|
13
|
+
const rows = await repository.loadAll();
|
|
14
|
+
this.activeByWorkflowId.clear();
|
|
15
|
+
for (const row of rows) {
|
|
16
|
+
this.activeByWorkflowId.set(decodeURIComponent(row.workflowId), row.isActive);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
set(workflowId: string, active: boolean): void {
|
|
21
|
+
this.activeByWorkflowId.set(decodeURIComponent(workflowId), active);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
isActive(workflowId: WorkflowId): boolean {
|
|
25
|
+
return this.activeByWorkflowId.get(workflowId) ?? false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ResolvedDatabasePersistence } from "./DatabasePersistenceResolver";
|
|
2
|
+
import type { CodemationSchedulerKind } from "../../presentation/config/CodemationConfig";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ensures scheduler and database selections are compatible (e.g. BullMQ requires shared TCP PostgreSQL).
|
|
6
|
+
*/
|
|
7
|
+
export class SchedulerPersistenceCompatibilityValidator {
|
|
8
|
+
validate(args: Readonly<{ schedulerKind: CodemationSchedulerKind; persistence: ResolvedDatabasePersistence }>): void {
|
|
9
|
+
if (args.schedulerKind === "bullmq" && args.persistence.kind === "none") {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"BullMQ requires PostgreSQL persistence. Configure runtime.database with a postgresql URL (embedded PGlite is not compatible with BullMQ).",
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
if (args.schedulerKind === "bullmq" && args.persistence.kind === "pglite") {
|
|
15
|
+
throw new Error(
|
|
16
|
+
'BullMQ requires a shared PostgreSQL database. PGlite cannot be used with the BullMQ scheduler. Set runtime.database.kind to "postgresql" with a PostgreSQL URL, or use the local scheduler when using PGlite.',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { WorkflowDefinition, WorkflowExecutionRepository, WorkflowRepository } from "@codemation/core";
|
|
2
|
+
import { CoreTokens, inject, injectable } from "@codemation/core";
|
|
3
|
+
import { Engine } from "@codemation/core/bootstrap";
|
|
4
|
+
import { WorkflowDefinitionRepository } from "../../domain/workflows/WorkflowDefinitionRepository";
|
|
5
|
+
|
|
6
|
+
@injectable()
|
|
7
|
+
export class WorkflowDefinitionRepositoryAdapter implements WorkflowDefinitionRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@inject(Engine) private readonly engine: Engine,
|
|
10
|
+
@inject(CoreTokens.WorkflowRepository) private readonly workflowRepository: WorkflowRepository,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async listDefinitions(): Promise<ReadonlyArray<WorkflowDefinition>> {
|
|
14
|
+
return [...this.workflowRepository.list()];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getDefinition(workflowId: string): Promise<WorkflowDefinition | undefined> {
|
|
18
|
+
return this.workflowRepository.get(decodeURIComponent(workflowId));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async resolveSnapshot(
|
|
22
|
+
args: Readonly<{ workflowId: string; workflowSnapshot?: unknown }>,
|
|
23
|
+
): Promise<WorkflowDefinition | undefined> {
|
|
24
|
+
return this.engine.resolveWorkflowSnapshot({
|
|
25
|
+
workflowId: decodeURIComponent(args.workflowId),
|
|
26
|
+
workflowSnapshot: args.workflowSnapshot as NonNullable<
|
|
27
|
+
Awaited<ReturnType<WorkflowExecutionRepository["load"]>>
|
|
28
|
+
>["workflowSnapshot"],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|