@db3.ai/app 0.1.0-beta.1 → 0.1.0
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 -17
- package/agent-instructions.md +76 -0
- package/dist/ai/AIErrors.d.ts +7 -1
- package/dist/ai/AIErrors.js +8 -1
- package/dist/ai/AIFailover.d.ts +10 -0
- package/dist/ai/AIFailover.js +3 -2
- package/dist/ai/AIProviderAdmission.d.ts +101 -0
- package/dist/ai/AIProviderAdmission.js +336 -0
- package/dist/ai/AIRateLimiter.d.ts +11 -2
- package/dist/ai/AIRateLimiter.js +125 -10
- package/dist/ai/AIRequestTrackingError.d.ts +22 -0
- package/dist/ai/AIRequestTrackingError.js +33 -0
- package/dist/ai/Agent.d.ts +7 -7
- package/dist/ai/Agent.js +84 -56
- package/dist/ai/Ai.d.ts +11 -3
- package/dist/ai/Ai.js +94 -44
- package/dist/ai/OpenAIProviderError.js +1 -1
- package/dist/ai/ProviderSseObserver.d.ts +19 -0
- package/dist/ai/ProviderSseObserver.js +98 -0
- package/dist/ai/aiServiceTier.d.ts +5 -0
- package/dist/ai/aiServiceTier.js +14 -0
- package/dist/ai/chunkEmbeddingText.d.ts +14 -0
- package/dist/ai/chunkEmbeddingText.js +147 -0
- package/dist/ai/contracts/AI.d.ts +16 -0
- package/dist/ai/contracts/AIRequestErrorDiagnostics.d.ts +12 -0
- package/dist/ai/contracts/AIRequestErrorDiagnostics.js +1 -0
- package/dist/ai/contracts/AIServiceTier.d.ts +2 -0
- package/dist/ai/contracts/AIServiceTier.js +1 -0
- package/dist/ai/contracts/Agent.d.ts +3 -0
- package/dist/ai/contracts/EmbeddingTextChunk.d.ts +25 -0
- package/dist/ai/contracts/EmbeddingTextChunk.js +1 -0
- package/dist/ai/contracts/Pricing.d.ts +7 -1
- package/dist/ai/contracts/Providers.d.ts +2 -0
- package/dist/ai/contracts/index.d.ts +2 -0
- package/dist/ai/contracts/index.js +1 -0
- package/dist/ai/index.d.ts +8 -2
- package/dist/ai/index.js +5 -2
- package/dist/ai/{Models.d.ts → modelPricing.d.ts} +2 -2
- package/dist/ai/{Models.js → modelPricing.js} +38 -4
- package/dist/apps/AppInstallation.d.ts +21 -0
- package/dist/apps/AppInstallation.js +16 -0
- package/dist/apps/AppRouteError.d.ts +6 -0
- package/dist/apps/AppRouteError.js +10 -0
- package/dist/apps/AppService.d.ts +24 -0
- package/dist/apps/AppService.js +21 -0
- package/dist/apps/Apps.d.ts +59 -0
- package/dist/apps/Apps.js +566 -0
- package/dist/apps/appsPlugin.d.ts +3 -0
- package/dist/apps/appsPlugin.js +36 -0
- package/dist/apps/commands/disableApp.d.ts +2 -0
- package/dist/apps/commands/disableApp.js +5 -0
- package/dist/apps/commands/enableApp.d.ts +2 -0
- package/dist/apps/commands/enableApp.js +5 -0
- package/dist/apps/commands/index.d.ts +10 -0
- package/dist/apps/commands/index.js +27 -0
- package/dist/apps/commands/installApp.d.ts +2 -0
- package/dist/apps/commands/installApp.js +5 -0
- package/dist/apps/commands/listApps.d.ts +2 -0
- package/dist/apps/commands/listApps.js +5 -0
- package/dist/apps/commands/makeAppMigration.d.ts +2 -0
- package/dist/apps/commands/makeAppMigration.js +9 -0
- package/dist/apps/commands/rollbackApp.d.ts +2 -0
- package/dist/apps/commands/rollbackApp.js +5 -0
- package/dist/apps/commands/uninstallApp.d.ts +2 -0
- package/dist/apps/commands/uninstallApp.js +5 -0
- package/dist/apps/contracts/AppAction.d.ts +2 -0
- package/dist/apps/contracts/AppAction.js +1 -0
- package/dist/apps/contracts/AppDefinition.d.ts +45 -0
- package/dist/apps/contracts/AppDefinition.js +1 -0
- package/dist/apps/contracts/AppDescription.d.ts +32 -0
- package/dist/apps/contracts/AppDescription.js +1 -0
- package/dist/apps/contracts/AppManifest.d.ts +30 -0
- package/dist/apps/contracts/AppManifest.js +1 -0
- package/dist/apps/contracts/AppNavigation.d.ts +9 -0
- package/dist/apps/contracts/AppNavigation.js +1 -0
- package/dist/apps/contracts/AppNavigationBadge.d.ts +6 -0
- package/dist/apps/contracts/AppNavigationBadge.js +1 -0
- package/dist/apps/contracts/AppNavigationContext.d.ts +8 -0
- package/dist/apps/contracts/AppNavigationContext.js +1 -0
- package/dist/apps/contracts/AppNavigationResult.d.ts +12 -0
- package/dist/apps/contracts/AppNavigationResult.js +1 -0
- package/dist/apps/contracts/AppRoute.d.ts +19 -0
- package/dist/apps/contracts/AppRoute.js +1 -0
- package/dist/apps/contracts/DiscoveredApp.d.ts +10 -0
- package/dist/apps/contracts/DiscoveredApp.js +1 -0
- package/dist/apps/contracts/InstalledApps.d.ts +3 -0
- package/dist/apps/contracts/InstalledApps.js +1 -0
- package/dist/apps/contracts/index.d.ts +11 -0
- package/dist/apps/contracts/index.js +1 -0
- package/dist/apps/defineApp.d.ts +7 -0
- package/dist/apps/defineApp.js +8 -0
- package/dist/apps/discoverApps.d.ts +3 -0
- package/dist/apps/discoverApps.js +62 -0
- package/dist/apps/fastify.d.ts +1 -0
- package/dist/apps/fastify.js +1 -0
- package/dist/apps/index.d.ts +7 -0
- package/dist/apps/index.js +7 -0
- package/dist/apps/normalizeAppNavigation.d.ts +3 -0
- package/dist/apps/normalizeAppNavigation.js +30 -0
- package/dist/apps/registerAppRoutes.d.ts +6 -0
- package/dist/apps/registerAppRoutes.js +52 -0
- package/dist/apps/validateAppDefinitions.d.ts +3 -0
- package/dist/apps/validateAppDefinitions.js +65 -0
- package/dist/apps/vite.d.ts +1 -0
- package/dist/apps/vite.js +1 -0
- package/dist/apps/writeAppTypes.d.ts +2 -0
- package/dist/apps/writeAppTypes.js +13 -0
- package/dist/auth/Auth.d.ts +18 -0
- package/dist/auth/Auth.js +89 -13
- package/dist/auth/PasswordLoginAttempt.d.ts +50 -0
- package/dist/auth/PasswordLoginAttempt.js +60 -0
- package/dist/auth/PasswordSuspendedError.d.ts +10 -0
- package/dist/auth/PasswordSuspendedError.js +13 -0
- package/dist/auth/contracts/PasswordAuthProviderOptions.d.ts +26 -0
- package/dist/auth/contracts/PasswordAuthProviderOptions.js +1 -0
- package/dist/auth/contracts/PasswordSuspension.d.ts +7 -0
- package/dist/auth/contracts/PasswordSuspension.js +1 -0
- package/dist/auth/contracts/PasswordSuspensionOptions.d.ts +10 -0
- package/dist/auth/contracts/PasswordSuspensionOptions.js +1 -0
- package/dist/auth/contracts/index.d.ts +3 -0
- package/dist/auth/contracts/index.js +3 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/providers/PasswordAuthProvider.d.ts +19 -23
- package/dist/auth/providers/PasswordAuthProvider.js +96 -8
- package/dist/auth/providers/resolveAuthProviders.js +1 -0
- package/dist/cli/Cli.d.ts +2 -0
- package/dist/cli/Cli.js +8 -0
- package/dist/cli/commands/repl.js +2 -1
- package/dist/cli/contracts/CliCommand.d.ts +2 -0
- package/dist/cli/contracts/CliCommandInfo.d.ts +12 -0
- package/dist/cli/contracts/CliCommandInfo.js +1 -0
- package/dist/cli/contracts/index.d.ts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/listDb3Commands.d.ts +8 -0
- package/dist/cli/listDb3Commands.js +10 -0
- package/dist/cli/runDb3.d.ts +3 -6
- package/dist/cli/runDb3.js +5 -59
- package/dist/cli/withDb3Cli.d.ts +4 -0
- package/dist/cli/withDb3Cli.js +60 -0
- package/dist/db/ActiveQueryBuilder.d.ts +8 -0
- package/dist/db/ActiveQueryBuilder.js +11 -0
- package/dist/db/ActiveRecord.d.ts +6 -0
- package/dist/db/ActiveRecord.js +8 -0
- package/dist/db/connection.js +14 -2
- package/dist/db/fields/TimestampField.d.ts +1 -1
- package/dist/db/fields/TimestampField.js +7 -12
- package/dist/db/migrations/DatabaseMigrationManager.d.ts +3 -1
- package/dist/db/migrations/DatabaseMigrationManager.js +9 -3
- package/dist/db/migrations/contracts/DatabaseMigration.d.ts +7 -0
- package/dist/db/migrations/index.d.ts +1 -1
- package/dist/db/migrations/index.js +1 -1
- package/dist/db/migrations/{KnexMigrationRenderer.d.ts → renderKnexMigration.d.ts} +4 -3
- package/dist/db/migrations/{KnexMigrationRenderer.js → renderKnexMigration.js} +7 -6
- package/dist/flows/FlowCompiler.js +1 -1
- package/dist/flows/Flows.js +1 -1
- package/dist/flows/index.d.ts +1 -1
- package/dist/flows/index.js +1 -1
- package/dist/health/Health.d.ts +41 -0
- package/dist/health/Health.js +153 -0
- package/dist/health/contracts/Health.d.ts +36 -0
- package/dist/health/contracts/Health.js +1 -0
- package/dist/health/contracts/HealthHttp.d.ts +15 -0
- package/dist/health/contracts/HealthHttp.js +1 -0
- package/dist/health/contracts/index.d.ts +2 -0
- package/dist/health/contracts/index.js +1 -0
- package/dist/health/databaseHealthCheck.d.ts +15 -0
- package/dist/health/databaseHealthCheck.js +18 -0
- package/dist/health/fastify.d.ts +13 -0
- package/dist/health/fastify.js +44 -0
- package/dist/health/index.d.ts +3 -0
- package/dist/health/index.js +2 -0
- package/dist/in-app/InApp.d.ts +33 -0
- package/dist/in-app/InApp.js +191 -0
- package/dist/in-app/InAppError.d.ts +6 -0
- package/dist/in-app/InAppError.js +10 -0
- package/dist/in-app/InAppRecord.d.ts +36 -0
- package/dist/in-app/InAppRecord.js +24 -0
- package/dist/in-app/contracts/InAppInbox.d.ts +45 -0
- package/dist/in-app/contracts/InAppInbox.js +1 -0
- package/dist/in-app/contracts/InAppMessage.d.ts +22 -0
- package/dist/in-app/contracts/InAppMessage.js +1 -0
- package/dist/in-app/contracts/InAppScope.d.ts +17 -0
- package/dist/in-app/contracts/InAppScope.js +1 -0
- package/dist/in-app/contracts/index.d.ts +3 -0
- package/dist/in-app/contracts/index.js +3 -0
- package/dist/in-app/index.d.ts +4 -0
- package/dist/in-app/index.js +4 -0
- package/dist/in-app/validation.d.ts +21 -0
- package/dist/in-app/validation.js +50 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.js +2 -5
- package/dist/logging/DevelopmentConsole.d.ts +42 -0
- package/dist/logging/DevelopmentConsole.js +162 -0
- package/dist/logging/Log.d.ts +3 -1
- package/dist/logging/Log.js +5 -2
- package/dist/logging/PrettyLogFormatter.d.ts +16 -0
- package/dist/logging/PrettyLogFormatter.js +151 -0
- package/dist/logging/acquireDevelopmentConsole.d.ts +6 -0
- package/dist/logging/acquireDevelopmentConsole.js +21 -0
- package/dist/logging/contracts/DevelopmentConsoleOptions.d.ts +16 -0
- package/dist/logging/contracts/DevelopmentConsoleOptions.js +1 -0
- package/dist/logging/contracts/EmailLogOptions.d.ts +8 -0
- package/dist/logging/contracts/EmailLogOptions.js +1 -0
- package/dist/logging/contracts/HttpExchangeMonitorOptions.d.ts +12 -0
- package/dist/logging/contracts/HttpExchangeMonitorOptions.js +1 -0
- package/dist/logging/contracts/LogTransportOptions.d.ts +19 -0
- package/dist/logging/contracts/LogTransportOptions.js +1 -0
- package/dist/logging/contracts/LoggingOptions.d.ts +12 -1
- package/dist/logging/contracts/index.d.ts +4 -0
- package/dist/logging/contracts/index.js +4 -0
- package/dist/logging/drivers/PinoLoggerDriver.d.ts +3 -1
- package/dist/logging/drivers/PinoLoggerDriver.js +75 -16
- package/dist/logging/formatLogEmail.d.ts +4 -0
- package/dist/logging/formatLogEmail.js +21 -0
- package/dist/logging/highlightQueueMessage.d.ts +11 -0
- package/dist/logging/highlightQueueMessage.js +36 -0
- package/dist/logging/httpBodyCapture.d.ts +24 -0
- package/dist/logging/httpBodyCapture.js +321 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/redactLogEmail.d.ts +2 -0
- package/dist/logging/redactLogEmail.js +12 -0
- package/dist/logging/registerHttpExchangeMonitor.d.ts +10 -0
- package/dist/logging/registerHttpExchangeMonitor.js +43 -0
- package/dist/logging/transports/EmailLogTransport.d.ts +18 -0
- package/dist/logging/transports/EmailLogTransport.js +47 -0
- package/dist/mail/Mail.d.ts +2 -0
- package/dist/mail/Mail.js +3 -0
- package/dist/mail/MailDeliveryError.d.ts +9 -0
- package/dist/mail/MailDeliveryError.js +16 -0
- package/dist/mail/index.d.ts +1 -0
- package/dist/mail/index.js +1 -0
- package/dist/mail/transports/MailgunTransport.js +2 -0
- package/dist/mail/transports/ResendTransport.d.ts +3 -2
- package/dist/mail/transports/ResendTransport.js +22 -14
- package/dist/media/MediaManager.d.ts +4 -2
- package/dist/media/MediaManager.js +40 -8
- package/dist/network/BlockedUrlError.d.ts +16 -0
- package/dist/network/BlockedUrlError.js +19 -0
- package/dist/network/assertPublicUrl.d.ts +22 -0
- package/dist/network/assertPublicUrl.js +67 -0
- package/dist/network/contracts/GuardedFetch.d.ts +35 -0
- package/dist/network/contracts/GuardedFetch.js +1 -0
- package/dist/network/contracts/PublicUrlOptions.d.ts +17 -0
- package/dist/network/contracts/PublicUrlOptions.js +1 -0
- package/dist/network/contracts/index.d.ts +2 -0
- package/dist/network/contracts/index.js +2 -0
- package/dist/network/guardedFetch.d.ts +29 -0
- package/dist/network/guardedFetch.js +133 -0
- package/dist/network/index.d.ts +6 -0
- package/dist/network/index.js +6 -0
- package/dist/network/playwright/GuardedBrowserProxy.d.ts +32 -0
- package/dist/network/playwright/GuardedBrowserProxy.js +172 -0
- package/dist/network/playwright/contracts/GuardedBrowserContextOptions.d.ts +37 -0
- package/dist/network/playwright/contracts/GuardedBrowserContextOptions.js +1 -0
- package/dist/network/playwright/contracts/index.d.ts +1 -0
- package/dist/network/playwright/contracts/index.js +1 -0
- package/dist/network/playwright/index.d.ts +2 -0
- package/dist/network/playwright/index.js +2 -0
- package/dist/network/playwright/newGuardedBrowserContext.d.ts +21 -0
- package/dist/network/playwright/newGuardedBrowserContext.js +86 -0
- package/dist/network/privateNetworkAddresses.d.ts +44 -0
- package/dist/network/privateNetworkAddresses.js +157 -0
- package/dist/network/publicAddressLookup.d.ts +26 -0
- package/dist/network/publicAddressLookup.js +42 -0
- package/dist/notifications/Notifications.d.ts +27 -0
- package/dist/notifications/Notifications.js +99 -0
- package/dist/notifications/contracts/Notification.d.ts +56 -0
- package/dist/notifications/contracts/Notification.js +1 -0
- package/dist/notifications/contracts/NotificationDelivery.d.ts +11 -0
- package/dist/notifications/contracts/NotificationDelivery.js +1 -0
- package/dist/notifications/contracts/index.d.ts +2 -0
- package/dist/notifications/contracts/index.js +2 -0
- package/dist/notifications/index.d.ts +2 -0
- package/dist/notifications/index.js +2 -0
- package/dist/queue/JobRunAttempt.d.ts +16 -0
- package/dist/queue/JobRunAttempt.js +17 -0
- package/dist/queue/JobRunEvent.d.ts +15 -0
- package/dist/queue/JobRunEvent.js +16 -0
- package/dist/queue/JobRunStoppedError.d.ts +6 -0
- package/dist/queue/JobRunStoppedError.js +10 -0
- package/dist/queue/Queue.d.ts +19 -4
- package/dist/queue/Queue.js +122 -9
- package/dist/queue/QueueTerminalError.d.ts +9 -0
- package/dist/queue/QueueTerminalError.js +12 -0
- package/dist/queue/QueueWorker.d.ts +12 -5
- package/dist/queue/QueueWorker.js +94 -9
- package/dist/queue/QueueWorkerReporter.d.ts +17 -0
- package/dist/queue/QueueWorkerReporter.js +71 -0
- package/dist/queue/QueueableJob.d.ts +2 -2
- package/dist/queue/RunnableJob.d.ts +78 -0
- package/dist/queue/RunnableJob.js +284 -0
- package/dist/queue/console.d.ts +8 -0
- package/dist/queue/console.js +53 -19
- package/dist/queue/contracts/QueueDriver.d.ts +8 -0
- package/dist/queue/contracts/QueueJobRunner.d.ts +4 -0
- package/dist/queue/contracts/QueueJobRunner.js +1 -0
- package/dist/queue/contracts/QueuePayload.d.ts +1 -1
- package/dist/queue/contracts/QueueSelection.d.ts +11 -0
- package/dist/queue/contracts/QueueSelection.js +1 -0
- package/dist/queue/contracts/QueueService.d.ts +18 -4
- package/dist/queue/contracts/QueueWorkerLifecycle.d.ts +2 -2
- package/dist/queue/contracts/QueueWorkerSnapshot.d.ts +14 -0
- package/dist/queue/contracts/QueueWorkerSnapshot.js +1 -0
- package/dist/queue/contracts/QueueableJob.d.ts +7 -3
- package/dist/queue/contracts/QueueableJobContract.d.ts +12 -0
- package/dist/queue/contracts/QueueableJobContract.js +1 -0
- package/dist/queue/contracts/index.d.ts +4 -0
- package/dist/queue/contracts/index.js +2 -0
- package/dist/queue/drivers/DatabaseQueueDriver.d.ts +4 -0
- package/dist/queue/drivers/DatabaseQueueDriver.js +27 -3
- package/dist/queue/drivers/RedisQueueDriver.d.ts +7 -0
- package/dist/queue/drivers/RedisQueueDriver.js +37 -0
- package/dist/queue/index.d.ts +5 -0
- package/dist/queue/index.js +5 -0
- package/dist/queue/jobEnvelopeHasPrefix.d.ts +3 -0
- package/dist/queue/jobEnvelopeHasPrefix.js +4 -0
- package/dist/scheduler/ScheduledEvent.d.ts +8 -4
- package/dist/scheduler/ScheduledEvent.js +17 -3
- package/dist/scheduler/ScheduledJob.d.ts +1 -1
- package/dist/scheduler/Scheduler.d.ts +5 -0
- package/dist/scheduler/Scheduler.js +92 -28
- package/dist/scheduler/SchedulerCheckpointRecord.d.ts +16 -0
- package/dist/scheduler/SchedulerCheckpointRecord.js +53 -0
- package/dist/scheduler/SchedulerWorker.d.ts +3 -5
- package/dist/scheduler/SchedulerWorker.js +58 -14
- package/dist/scheduler/console.js +3 -1
- package/dist/scheduler/contracts/Schedule.d.ts +19 -0
- package/dist/scheduler/contracts/Schedule.js +1 -0
- package/dist/scheduler/contracts/Scheduler.d.ts +18 -6
- package/dist/scheduler/contracts/SchedulerCheckpoint.d.ts +23 -0
- package/dist/scheduler/contracts/SchedulerCheckpoint.js +1 -0
- package/dist/scheduler/contracts/SchedulerConsole.d.ts +5 -0
- package/dist/scheduler/contracts/SchedulerWorker.d.ts +6 -1
- package/dist/scheduler/contracts/index.d.ts +2 -0
- package/dist/scheduler/contracts/index.js +2 -0
- package/dist/scheduler/index.d.ts +1 -0
- package/dist/scheduler/index.js +1 -0
- package/dist/server/App.d.ts +36 -4
- package/dist/server/App.js +57 -7
- package/dist/server/contracts/HttpErrorHandlerOptions.d.ts +29 -0
- package/dist/server/contracts/HttpErrorHandlerOptions.js +1 -0
- package/dist/server/contracts/index.d.ts +1 -0
- package/dist/server/contracts/index.js +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +4 -0
- package/dist/server/publicServerErrorMessage.d.ts +11 -0
- package/dist/server/publicServerErrorMessage.js +16 -0
- package/dist/server/registerBrowserJsonFormatting.d.ts +16 -0
- package/dist/server/registerBrowserJsonFormatting.js +100 -0
- package/dist/server/registerHttpErrorHandler.d.ts +20 -0
- package/dist/server/registerHttpErrorHandler.js +93 -0
- package/dist/ssr/vite/contracts/ViteSsrOptions.d.ts +2 -0
- package/dist/ssr/vite/fastifyViteSsr.js +4 -3
- package/dist/storage/drivers/FlystorageDisk.js +2 -2
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +2 -2
- package/dist/websocket/WebSocketChannels.d.ts +18 -0
- package/dist/websocket/WebSocketChannels.js +129 -0
- package/dist/websocket/WebSocketConnection.d.ts +25 -0
- package/dist/websocket/WebSocketConnection.js +244 -0
- package/dist/websocket/WebSockets.d.ts +41 -0
- package/dist/websocket/WebSockets.js +194 -0
- package/dist/websocket/client/WebSocketClient.d.ts +21 -0
- package/dist/websocket/client/WebSocketClient.js +230 -0
- package/dist/websocket/client/index.d.ts +3 -0
- package/dist/websocket/client/index.js +1 -0
- package/dist/websocket/contracts/WebSocketChannel.d.ts +20 -0
- package/dist/websocket/contracts/WebSocketChannel.js +1 -0
- package/dist/websocket/contracts/WebSocketClient.d.ts +45 -0
- package/dist/websocket/contracts/WebSocketClient.js +1 -0
- package/dist/websocket/contracts/WebSocketEndpoint.d.ts +43 -0
- package/dist/websocket/contracts/WebSocketEndpoint.js +1 -0
- package/dist/websocket/contracts/WebSocketOptions.d.ts +48 -0
- package/dist/websocket/contracts/WebSocketOptions.js +1 -0
- package/dist/websocket/contracts/WebSocketPresence.d.ts +6 -0
- package/dist/websocket/contracts/WebSocketPresence.js +1 -0
- package/dist/websocket/contracts/WebSocketServiceOptions.d.ts +12 -0
- package/dist/websocket/contracts/WebSocketServiceOptions.js +1 -0
- package/dist/websocket/contracts/index.d.ts +6 -0
- package/dist/websocket/contracts/index.js +1 -0
- package/dist/websocket/defineChannel.d.ts +8 -0
- package/dist/websocket/defineChannel.js +13 -0
- package/dist/websocket/defineWebSocket.d.ts +14 -0
- package/dist/websocket/defineWebSocket.js +4 -0
- package/dist/websocket/fastify.d.ts +11 -0
- package/dist/websocket/fastify.js +38 -0
- package/dist/websocket/index.d.ts +5 -0
- package/dist/websocket/index.js +4 -0
- package/package.json +108 -7
- package/src/ai/AIErrors.ts +10 -0
- package/src/ai/AIFailover.ts +3 -2
- package/src/ai/AIProviderAdmission.ts +329 -0
- package/src/ai/AIRateLimiter.ts +134 -10
- package/src/ai/AIRequestTrackingError.ts +37 -0
- package/src/ai/Agent.ts +85 -71
- package/src/ai/Ai.ts +104 -48
- package/src/ai/OpenAIProviderError.ts +1 -1
- package/src/ai/ProviderSseObserver.ts +89 -0
- package/src/ai/README.md +216 -11
- package/src/ai/aiServiceTier.ts +14 -0
- package/src/ai/chunkEmbeddingText.ts +137 -0
- package/src/ai/contracts/AI.ts +17 -0
- package/src/ai/contracts/AIRequestErrorDiagnostics.ts +12 -0
- package/src/ai/contracts/AIServiceTier.ts +2 -0
- package/src/ai/contracts/Agent.ts +3 -0
- package/src/ai/contracts/EmbeddingTextChunk.ts +26 -0
- package/src/ai/contracts/Pricing.ts +7 -1
- package/src/ai/contracts/Providers.ts +2 -0
- package/src/ai/contracts/index.ts +2 -0
- package/src/ai/examples/prepareDocumentEmbeddings.ts +20 -0
- package/src/ai/index.ts +9 -2
- package/src/ai/{Models.ts → modelPricing.ts} +37 -4
- package/src/apps/AppInstallation.ts +25 -0
- package/src/apps/AppRouteError.ts +8 -0
- package/src/apps/AppService.ts +30 -0
- package/src/apps/Apps.ts +508 -0
- package/src/apps/README.md +354 -0
- package/src/apps/appsPlugin.ts +34 -0
- package/src/apps/commands/disableApp.ts +6 -0
- package/src/apps/commands/enableApp.ts +6 -0
- package/src/apps/commands/index.ts +29 -0
- package/src/apps/commands/installApp.ts +6 -0
- package/src/apps/commands/listApps.ts +6 -0
- package/src/apps/commands/makeAppMigration.ts +9 -0
- package/src/apps/commands/rollbackApp.ts +6 -0
- package/src/apps/commands/uninstallApp.ts +6 -0
- package/src/apps/contracts/AppAction.ts +2 -0
- package/src/apps/contracts/AppDefinition.ts +49 -0
- package/src/apps/contracts/AppDescription.ts +27 -0
- package/src/apps/contracts/AppManifest.ts +32 -0
- package/src/apps/contracts/AppNavigation.ts +10 -0
- package/src/apps/contracts/AppNavigationBadge.ts +6 -0
- package/src/apps/contracts/AppNavigationContext.ts +6 -0
- package/src/apps/contracts/AppNavigationResult.ts +9 -0
- package/src/apps/contracts/AppRoute.ts +18 -0
- package/src/apps/contracts/DiscoveredApp.ts +11 -0
- package/src/apps/contracts/InstalledApps.ts +2 -0
- package/src/apps/contracts/index.ts +11 -0
- package/src/apps/defineApp.ts +10 -0
- package/src/apps/discoverApps.ts +56 -0
- package/src/apps/fastify.ts +1 -0
- package/src/apps/index.ts +7 -0
- package/src/apps/normalizeAppNavigation.ts +29 -0
- package/src/apps/registerAppRoutes.ts +48 -0
- package/src/apps/validateAppDefinitions.ts +52 -0
- package/src/apps/vite.ts +1 -0
- package/src/apps/writeAppTypes.ts +14 -0
- package/src/auth/Auth.ts +89 -23
- package/src/auth/PasswordLoginAttempt.ts +72 -0
- package/src/auth/PasswordSuspendedError.ts +13 -0
- package/src/auth/README.md +94 -4
- package/src/auth/contracts/PasswordAuthProviderOptions.ts +30 -0
- package/src/auth/contracts/PasswordSuspension.ts +7 -0
- package/src/auth/contracts/PasswordSuspensionOptions.ts +10 -0
- package/src/auth/contracts/index.ts +3 -0
- package/src/auth/examples/runPasswordAuth.ts +6 -6
- package/src/auth/index.ts +2 -0
- package/src/auth/providers/PasswordAuthProvider.ts +96 -30
- package/src/auth/providers/resolveAuthProviders.ts +1 -0
- package/src/cli/Cli.ts +9 -0
- package/src/cli/README.md +19 -0
- package/src/cli/commands/repl.ts +2 -1
- package/src/cli/contracts/CliCommand.ts +2 -0
- package/src/cli/contracts/CliCommandInfo.ts +13 -0
- package/src/cli/contracts/index.ts +1 -0
- package/src/cli/index.ts +1 -0
- package/src/cli/listDb3Commands.ts +12 -0
- package/src/cli/runDb3.ts +5 -51
- package/src/cli/withDb3Cli.ts +55 -0
- package/src/db/ActiveQueryBuilder.ts +12 -0
- package/src/db/ActiveRecord.ts +9 -0
- package/src/db/README.md +45 -1
- package/src/db/connection.ts +12 -1
- package/src/db/examples/FieldNote.ts +7 -13
- package/src/db/examples/KnowledgeNote.ts +7 -13
- package/src/db/examples/runNoteMigrations.ts +11 -11
- package/src/db/fields/TimestampField.ts +8 -17
- package/src/db/migrations/DatabaseMigrationManager.ts +12 -4
- package/src/db/migrations/contracts/DatabaseMigration.ts +9 -0
- package/src/db/migrations/index.ts +1 -1
- package/src/db/migrations/{KnexMigrationRenderer.ts → renderKnexMigration.ts} +8 -14
- package/src/flows/FlowCompiler.ts +1 -1
- package/src/flows/Flows.ts +1 -1
- package/src/flows/index.ts +1 -1
- package/src/health/Health.ts +163 -0
- package/src/health/README.md +46 -0
- package/src/health/contracts/Health.ts +47 -0
- package/src/health/contracts/HealthHttp.ts +19 -0
- package/src/health/contracts/index.ts +2 -0
- package/src/health/databaseHealthCheck.ts +21 -0
- package/src/health/fastify.ts +49 -0
- package/src/health/index.ts +3 -0
- package/src/in-app/InApp.ts +173 -0
- package/src/in-app/InAppError.ts +8 -0
- package/src/in-app/InAppRecord.ts +41 -0
- package/src/in-app/README.md +193 -0
- package/src/in-app/contracts/InAppInbox.ts +51 -0
- package/src/in-app/contracts/InAppMessage.ts +19 -0
- package/src/in-app/contracts/InAppScope.ts +12 -0
- package/src/in-app/contracts/index.ts +3 -0
- package/src/in-app/examples/sendReportReady.ts +14 -0
- package/src/in-app/index.ts +4 -0
- package/src/in-app/validation.ts +49 -0
- package/src/index.ts +2 -22
- package/src/logging/DevelopmentConsole.ts +154 -0
- package/src/logging/Log.ts +5 -2
- package/src/logging/PrettyLogFormatter.ts +165 -0
- package/src/logging/README.md +52 -109
- package/src/logging/acquireDevelopmentConsole.ts +19 -0
- package/src/logging/contracts/DevelopmentConsoleOptions.ts +13 -0
- package/src/logging/contracts/EmailLogOptions.ts +9 -0
- package/src/logging/contracts/HttpExchangeMonitorOptions.ts +13 -0
- package/src/logging/contracts/LogTransportOptions.ts +10 -0
- package/src/logging/contracts/LoggingOptions.ts +12 -1
- package/src/logging/contracts/index.ts +4 -0
- package/src/logging/development/README.md +88 -0
- package/src/logging/drivers/PinoLoggerDriver.ts +72 -20
- package/src/logging/examples/runDevelopmentLogs.ts +36 -0
- package/src/logging/formatLogEmail.ts +24 -0
- package/src/logging/highlightQueueMessage.ts +38 -0
- package/src/logging/httpBodyCapture.ts +393 -0
- package/src/logging/index.ts +2 -0
- package/src/logging/redactLogEmail.ts +12 -0
- package/src/logging/registerHttpExchangeMonitor.ts +45 -0
- package/src/logging/transports/EmailLogTransport.ts +46 -0
- package/src/mail/Mail.ts +5 -0
- package/src/mail/MailDeliveryError.ts +8 -0
- package/src/mail/README.md +11 -1
- package/src/mail/index.ts +1 -0
- package/src/mail/transports/MailgunTransport.ts +2 -0
- package/src/mail/transports/ResendTransport.ts +24 -22
- package/src/media/MediaManager.ts +31 -10
- package/src/media/README.md +4 -0
- package/src/media/examples/runPrivateFiles.ts +2 -2
- package/src/network/BlockedUrlError.ts +19 -0
- package/src/network/README.md +133 -0
- package/src/network/assertPublicUrl.ts +77 -0
- package/src/network/contracts/GuardedFetch.ts +40 -0
- package/src/network/contracts/PublicUrlOptions.ts +17 -0
- package/src/network/contracts/index.ts +2 -0
- package/src/network/examples/runGuardedFetch.ts +35 -0
- package/src/network/guardedFetch.ts +150 -0
- package/src/network/index.ts +6 -0
- package/src/network/playwright/GuardedBrowserProxy.ts +172 -0
- package/src/network/playwright/contracts/GuardedBrowserContextOptions.ts +43 -0
- package/src/network/playwright/contracts/index.ts +1 -0
- package/src/network/playwright/index.ts +2 -0
- package/src/network/playwright/newGuardedBrowserContext.ts +74 -0
- package/src/network/privateNetworkAddresses.ts +166 -0
- package/src/network/publicAddressLookup.ts +49 -0
- package/src/notifications/Notifications.ts +105 -0
- package/src/notifications/README.md +59 -0
- package/src/notifications/contracts/Notification.ts +65 -0
- package/src/notifications/contracts/NotificationDelivery.ts +11 -0
- package/src/notifications/contracts/index.ts +2 -0
- package/src/notifications/examples/ReportReadyNotification.ts +31 -0
- package/src/notifications/index.ts +2 -0
- package/src/queue/JobRunAttempt.ts +17 -0
- package/src/queue/JobRunEvent.ts +16 -0
- package/src/queue/JobRunStoppedError.ts +8 -0
- package/src/queue/Queue.ts +112 -11
- package/src/queue/QueueTerminalError.ts +12 -0
- package/src/queue/QueueWorker.ts +86 -7
- package/src/queue/QueueWorkerReporter.ts +59 -0
- package/src/queue/QueueableJob.ts +2 -2
- package/src/queue/README.md +142 -1
- package/src/queue/RunnableJob.ts +272 -0
- package/src/queue/console.ts +54 -21
- package/src/queue/contracts/QueueDriver.ts +9 -0
- package/src/queue/contracts/QueueJobRunner.ts +4 -0
- package/src/queue/contracts/QueuePayload.ts +1 -1
- package/src/queue/contracts/QueueSelection.ts +11 -0
- package/src/queue/contracts/QueueService.ts +19 -4
- package/src/queue/contracts/QueueWorkerLifecycle.ts +2 -2
- package/src/queue/contracts/QueueWorkerSnapshot.ts +15 -0
- package/src/queue/contracts/QueueableJob.ts +7 -3
- package/src/queue/contracts/QueueableJobContract.ts +13 -0
- package/src/queue/contracts/index.ts +6 -0
- package/src/queue/drivers/DatabaseQueueDriver.ts +25 -3
- package/src/queue/drivers/RedisQueueDriver.ts +36 -0
- package/src/queue/examples/runQueueSelection.ts +34 -0
- package/src/queue/index.ts +7 -0
- package/src/queue/jobEnvelopeHasPrefix.ts +6 -0
- package/src/scheduler/README.md +50 -9
- package/src/scheduler/ScheduledEvent.ts +20 -5
- package/src/scheduler/ScheduledJob.ts +1 -1
- package/src/scheduler/Scheduler.ts +73 -27
- package/src/scheduler/SchedulerCheckpointRecord.ts +51 -0
- package/src/scheduler/SchedulerWorker.ts +54 -19
- package/src/scheduler/console.ts +3 -1
- package/src/scheduler/contracts/Schedule.ts +22 -0
- package/src/scheduler/contracts/Scheduler.ts +21 -6
- package/src/scheduler/contracts/SchedulerCheckpoint.ts +23 -0
- package/src/scheduler/contracts/SchedulerConsole.ts +5 -0
- package/src/scheduler/contracts/SchedulerWorker.ts +6 -1
- package/src/scheduler/contracts/index.ts +2 -0
- package/src/scheduler/examples/runSchedulerWindow.ts +54 -0
- package/src/scheduler/index.ts +1 -0
- package/src/server/App.ts +73 -10
- package/src/server/README.md +95 -2
- package/src/server/contracts/HttpErrorHandlerOptions.ts +29 -0
- package/src/server/contracts/index.ts +1 -0
- package/src/server/examples/createFirstServer.ts +5 -3
- package/src/server/index.ts +4 -0
- package/src/server/publicServerErrorMessage.ts +17 -0
- package/src/server/registerBrowserJsonFormatting.ts +94 -0
- package/src/server/registerHttpErrorHandler.ts +96 -0
- package/src/ssr/README.md +6 -0
- package/src/ssr/vite/contracts/ViteSsrOptions.ts +2 -0
- package/src/ssr/vite/fastifyViteSsr.ts +4 -3
- package/src/storage/drivers/FlystorageDisk.ts +2 -2
- package/src/storage/index.ts +2 -2
- package/src/websocket/README.md +458 -0
- package/src/websocket/WebSocketChannels.ts +99 -0
- package/src/websocket/WebSocketConnection.ts +162 -0
- package/src/websocket/WebSockets.ts +157 -0
- package/src/websocket/client/WebSocketClient.ts +188 -0
- package/src/websocket/client/index.ts +3 -0
- package/src/websocket/contracts/WebSocketChannel.ts +23 -0
- package/src/websocket/contracts/WebSocketClient.ts +48 -0
- package/src/websocket/contracts/WebSocketEndpoint.ts +46 -0
- package/src/websocket/contracts/WebSocketOptions.ts +50 -0
- package/src/websocket/contracts/WebSocketPresence.ts +6 -0
- package/src/websocket/contracts/WebSocketServiceOptions.ts +12 -0
- package/src/websocket/contracts/index.ts +6 -0
- package/src/websocket/defineChannel.ts +14 -0
- package/src/websocket/defineWebSocket.ts +15 -0
- package/src/websocket/examples/board/LiveBoard.ts +97 -0
- package/src/websocket/examples/board/SummarizeBoardJob.ts +52 -0
- package/src/websocket/examples/board/boardSnapshot.ts +16 -0
- package/src/websocket/examples/board/createBoardClient.ts +43 -0
- package/src/websocket/examples/board/createBoardStore.ts +58 -0
- package/src/websocket/examples/board/registerBoardRoutes.ts +31 -0
- package/src/websocket/examples/createChannelSync.ts +66 -0
- package/src/websocket/examples/deploymentEndpoint.ts +13 -0
- package/src/websocket/examples/deploymentSnapshot.ts +36 -0
- package/src/websocket/examples/resourceChannels.ts +18 -0
- package/src/websocket/examples/userEndpoint.ts +27 -0
- package/src/websocket/fastify.ts +39 -0
- package/src/websocket/index.ts +5 -0
- package/templates/AGENTS.md +33 -2
- /package/dist/flows/{FlowValueValidator.d.ts → flowValueValidator.d.ts} +0 -0
- /package/dist/flows/{FlowValueValidator.js → flowValueValidator.js} +0 -0
- /package/dist/storage/{mime.d.ts → mimeTypeFromPath.d.ts} +0 -0
- /package/dist/storage/{mime.js → mimeTypeFromPath.js} +0 -0
- /package/dist/storage/{contents.d.ts → storageContentsToBuffer.d.ts} +0 -0
- /package/dist/storage/{contents.js → storageContentsToBuffer.js} +0 -0
- /package/src/flows/{FlowValueValidator.ts → flowValueValidator.ts} +0 -0
- /package/src/storage/{mime.ts → mimeTypeFromPath.ts} +0 -0
- /package/src/storage/{contents.ts → storageContentsToBuffer.ts} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ActiveRecord
|
|
1
|
+
import { ActiveRecord } from '@db3.ai/app/db';
|
|
2
2
|
import { NoteCodeField } from './NoteCodeField';
|
|
3
3
|
|
|
4
4
|
/** A disposable guide model demonstrating reusable and JSON-backed field values. */
|
|
5
|
-
export class FieldNote extends ActiveRecord
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export class FieldNote extends ActiveRecord.define({
|
|
6
|
+
table: 'field_notes',
|
|
7
|
+
requestFillable: ['code', 'tags', 'metadata'],
|
|
8
8
|
|
|
9
9
|
/** Declares one place for input, validation, storage and public-output policy. */
|
|
10
|
-
|
|
10
|
+
fields(field) {
|
|
11
11
|
return {
|
|
12
12
|
id: field.ulid(),
|
|
13
13
|
owner: field.string({ column: 'owner_id', required: true, index: true }),
|
|
@@ -16,12 +16,6 @@ export class FieldNote extends ActiveRecord {
|
|
|
16
16
|
metadata: field.json<{ client: { name: string }; draft: boolean }>(),
|
|
17
17
|
integration: field.encryptedJson<{ token: string }>({ column: 'integration_secret', selectedByDefault: false }),
|
|
18
18
|
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare id: string | null;
|
|
22
|
-
declare owner: string | null;
|
|
23
|
-
declare code: string | null;
|
|
24
|
-
declare tags: string[];
|
|
25
|
-
declare metadata: { client: { name: string }; draft: boolean } | null;
|
|
26
|
-
declare integration: { token: string } | null;
|
|
19
|
+
},
|
|
20
|
+
}) {
|
|
27
21
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ActiveRecord
|
|
1
|
+
import { ActiveRecord } from '@db3.ai/app/db';
|
|
2
2
|
|
|
3
3
|
/** A workspace-owned note used by the ActiveRecord guide and executable recipe. */
|
|
4
|
-
export class KnowledgeNote extends ActiveRecord
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export class KnowledgeNote extends ActiveRecord.define({
|
|
5
|
+
table: 'knowledge_notes',
|
|
6
|
+
requestFillable: ['title', 'body'],
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Defines storage, validation and transport behaviour for each logical field.
|
|
@@ -11,7 +11,7 @@ export class KnowledgeNote extends ActiveRecord {
|
|
|
11
11
|
* @param field - Framework field factory.
|
|
12
12
|
* @returns The note's schema; workspace ownership is assigned by trusted code.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
fields(field) {
|
|
15
15
|
return {
|
|
16
16
|
id: field.ulid(),
|
|
17
17
|
workspace: field.string({ column: 'workspace_id', required: true, maxLength: 26, index: true }),
|
|
@@ -19,11 +19,5 @@ export class KnowledgeNote extends ActiveRecord {
|
|
|
19
19
|
body: field.text(),
|
|
20
20
|
createdAt: field.timestamp({ column: 'created_at', auto: 'create' }),
|
|
21
21
|
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare id: string | null;
|
|
25
|
-
declare workspace: string | null;
|
|
26
|
-
declare title: string | null;
|
|
27
|
-
declare body: string | null;
|
|
28
|
-
declare createdAt: Date | null;
|
|
29
|
-
}
|
|
22
|
+
},
|
|
23
|
+
}) {}
|
|
@@ -2,27 +2,27 @@ import { mkdtemp, readFile, readdir, rm } from 'node:fs/promises';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { ActiveRecord, DatabaseMigrationManager, mariaDbDialect
|
|
5
|
+
import { ActiveRecord, DatabaseMigrationManager, mariaDbDialect } from '@db3.ai/app/db';
|
|
6
6
|
import { createGeneratedTestDatabase } from '@db3.ai/app/db/test/db';
|
|
7
7
|
|
|
8
8
|
/** Initial version of a disposable note table, before a schema change. */
|
|
9
|
-
class InitialNote extends ActiveRecord
|
|
10
|
-
|
|
9
|
+
class InitialNote extends ActiveRecord.define({
|
|
10
|
+
table: 'migration_guide_notes',
|
|
11
11
|
/** Defines the initial committed schema. */
|
|
12
|
-
|
|
13
|
-
}
|
|
12
|
+
fields(field) { return { id: field.ulid(), title: field.string({ required: true }) }; },
|
|
13
|
+
}) {}
|
|
14
14
|
|
|
15
15
|
/** Unsafe proposal: existing rows have no value for this required column. */
|
|
16
|
-
class RequiredCategoryNote extends InitialNote
|
|
16
|
+
class RequiredCategoryNote extends InitialNote.define({
|
|
17
17
|
/** Adds a required field without pretending existing data has a value. */
|
|
18
|
-
|
|
19
|
-
}
|
|
18
|
+
fields(field) { return { category: field.string({ required: true }) }; },
|
|
19
|
+
}) {}
|
|
20
20
|
|
|
21
21
|
/** Repaired additive change that can be deployed before backfilling existing rows. */
|
|
22
|
-
class OptionalCategoryNote extends InitialNote
|
|
22
|
+
class OptionalCategoryNote extends InitialNote.define({
|
|
23
23
|
/** Adds a nullable field safe for the existing note. */
|
|
24
|
-
|
|
25
|
-
}
|
|
24
|
+
fields(field) { return { category: field.string() }; },
|
|
25
|
+
}) {}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Generates, applies and checks migrations against an owned disposable database.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { utcDate } from '@db3.ai/pure/dates';
|
|
1
2
|
import {
|
|
2
3
|
BasicFieldState,
|
|
3
4
|
DbSchemaPart,
|
|
@@ -46,21 +47,7 @@ export class TimestampField extends FieldType<
|
|
|
46
47
|
* Parses app input into a Date object.
|
|
47
48
|
*/
|
|
48
49
|
protected override parse(input: unknown): Date | null {
|
|
49
|
-
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (input instanceof Date) {
|
|
54
|
-
return input;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const date = new Date(String(input));
|
|
58
|
-
|
|
59
|
-
if (Number.isNaN(date.getTime())) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return date;
|
|
50
|
+
return input instanceof Date || typeof input === 'string' ? utcDate(input) : null;
|
|
64
51
|
}
|
|
65
52
|
|
|
66
53
|
/**
|
|
@@ -73,12 +60,16 @@ export class TimestampField extends FieldType<
|
|
|
73
60
|
/**
|
|
74
61
|
* Converts app-memory Date to database value.
|
|
75
62
|
*/
|
|
76
|
-
protected override toDbValue(input: Date | null): Date | null {
|
|
63
|
+
protected override toDbValue(input: Date | null): Date | string | null {
|
|
77
64
|
if (input === null || input === undefined) {
|
|
78
65
|
return null;
|
|
79
66
|
}
|
|
80
67
|
|
|
81
|
-
|
|
68
|
+
// PostgreSQL timestamp-without-timezone ignores offsets on Date parameters.
|
|
69
|
+
// Send UTC calendar components explicitly rather than the driver's local rendering.
|
|
70
|
+
return this.schemaDialect().name === 'postgres'
|
|
71
|
+
? input.toISOString().replace('T', ' ').replace('Z', '')
|
|
72
|
+
: input;
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
protected override defaultFormComponent(): string {
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
MakeMigrationResult,
|
|
27
27
|
MigrateOptions,
|
|
28
28
|
MigrateResult,
|
|
29
|
+
RollbackResult,
|
|
29
30
|
SchemaMigrationPlan,
|
|
30
31
|
SchemaSnapshot,
|
|
31
32
|
} from './contracts';
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
DatabaseMigrationLockError,
|
|
36
37
|
DatabaseMigrationSourceGenerationError,
|
|
37
38
|
} from './errors';
|
|
38
|
-
import { renderKnexMigration } from './
|
|
39
|
+
import { renderKnexMigration } from './renderKnexMigration';
|
|
39
40
|
import { collectModelSchema } from './ModelSchemaCollector';
|
|
40
41
|
import { diffSchemaSnapshots } from './SchemaDiffer';
|
|
41
42
|
import { promoteDestructiveSchemaChanges } from './promoteDestructiveSchemaChanges';
|
|
@@ -57,7 +58,7 @@ const DEFAULT_LOAD_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'] as const;
|
|
|
57
58
|
export class DatabaseMigrationManager {
|
|
58
59
|
readonly #options: Required<Pick<
|
|
59
60
|
DatabaseMigrationManagerOptions,
|
|
60
|
-
'migrationTableName' | 'loadExtensions' | 'environment' | 'generationLockFile' | 'now'
|
|
61
|
+
'migrationTableName' | 'loadExtensions' | 'migrationExtension' | 'environment' | 'generationLockFile' | 'now'
|
|
61
62
|
>> & DatabaseMigrationManagerOptions;
|
|
62
63
|
|
|
63
64
|
/**
|
|
@@ -82,6 +83,7 @@ export class DatabaseMigrationManager {
|
|
|
82
83
|
...options,
|
|
83
84
|
models: [...options.models],
|
|
84
85
|
migrationTableName: options.migrationTableName ?? DEFAULT_MIGRATION_TABLE,
|
|
86
|
+
migrationExtension: options.migrationExtension ?? '.ts',
|
|
85
87
|
loadExtensions: options.loadExtensions ?? DEFAULT_LOAD_EXTENSIONS,
|
|
86
88
|
environment: options.environment ?? process.env.NODE_ENV ?? 'development',
|
|
87
89
|
generationLockFile,
|
|
@@ -200,6 +202,12 @@ export class DatabaseMigrationManager {
|
|
|
200
202
|
};
|
|
201
203
|
}
|
|
202
204
|
|
|
205
|
+
/** Runs the latest committed migration's own down function. The caller must quiesce consumers first. */
|
|
206
|
+
async rollback(): Promise<RollbackResult> {
|
|
207
|
+
const [batch, names] = await this.#options.db.migrate.down(this.#knexConfig());
|
|
208
|
+
return { reverted: names.map(String), batch: typeof batch === 'number' ? batch : null };
|
|
209
|
+
}
|
|
210
|
+
|
|
203
211
|
/**
|
|
204
212
|
* Runs the development convenience flow under one generation lock.
|
|
205
213
|
*
|
|
@@ -272,9 +280,9 @@ export class DatabaseMigrationManager {
|
|
|
272
280
|
const name = migrationName(options.name, plan);
|
|
273
281
|
const file = join(
|
|
274
282
|
this.#options.migrationsDirectory,
|
|
275
|
-
`${formatMigrationTimestamp(this.#options.now())}_${name}.
|
|
283
|
+
`${formatMigrationTimestamp(this.#options.now())}_${name}${this.#options.migrationExtension}`,
|
|
276
284
|
);
|
|
277
|
-
const source = renderKnexMigration(plan);
|
|
285
|
+
const source = renderKnexMigration(plan, this.#options.migrationExtension === '.mjs' ? 'javascript' : 'typescript');
|
|
278
286
|
|
|
279
287
|
await writeMigrationAndSnapshotAtomically(
|
|
280
288
|
file,
|
|
@@ -31,6 +31,9 @@ export interface DatabaseMigrationManagerOptions {
|
|
|
31
31
|
/** Migration file extensions Knex may load. */
|
|
32
32
|
loadExtensions?: readonly string[];
|
|
33
33
|
|
|
34
|
+
/** Generated migration format. Use .mjs for assets shared unchanged with npm packages. */
|
|
35
|
+
migrationExtension?: '.ts' | '.mjs';
|
|
36
|
+
|
|
34
37
|
/** Current application environment. Source generation is refused in production. */
|
|
35
38
|
environment?: string;
|
|
36
39
|
|
|
@@ -141,3 +144,9 @@ export interface DatabaseSyncResult {
|
|
|
141
144
|
migrate: MigrateResult | null;
|
|
142
145
|
check: DatabaseCheckResult | null;
|
|
143
146
|
}
|
|
147
|
+
|
|
148
|
+
/** Result of executing the latest migration's app-authored down function. */
|
|
149
|
+
export interface RollbackResult {
|
|
150
|
+
reverted: string[];
|
|
151
|
+
batch: number | null;
|
|
152
|
+
}
|
|
@@ -2,7 +2,7 @@ export * from './contracts';
|
|
|
2
2
|
export * from './DatabaseMigrationManager';
|
|
3
3
|
export * from './DatabaseSchemaInspector';
|
|
4
4
|
export * from './errors';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './renderKnexMigration';
|
|
6
6
|
export * from './ModelSchemaCollector';
|
|
7
7
|
export * from './promoteDestructiveSchemaChanges';
|
|
8
8
|
export * from './SchemaDiffer';
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SafeSchemaChange,
|
|
3
|
-
SchemaColumn,
|
|
4
|
-
SchemaForeignKey,
|
|
5
|
-
SchemaIndex,
|
|
6
|
-
SchemaMigrationPlan,
|
|
7
|
-
SchemaTable,
|
|
8
|
-
} from './contracts';
|
|
1
|
+
import type { SafeSchemaChange, SchemaColumn, SchemaForeignKey, SchemaIndex, SchemaMigrationPlan, SchemaTable } from './contracts';
|
|
9
2
|
|
|
10
3
|
/**
|
|
11
|
-
* Renders a frozen TypeScript Knex migration from a safe schema plan.
|
|
4
|
+
* Renders a frozen TypeScript or JavaScript Knex migration from a safe schema plan.
|
|
12
5
|
*
|
|
13
6
|
* Generated source contains literal table, column, index, and foreign-key
|
|
14
7
|
* operations. It never imports current models or field implementations.
|
|
15
8
|
*
|
|
16
9
|
* @param plan - Pure schema plan with no blocked changes.
|
|
17
|
-
* @
|
|
10
|
+
* @param language - JavaScript keeps migration bytes identical in local and packaged apps.
|
|
11
|
+
* @returns Deterministic migration source.
|
|
18
12
|
*/
|
|
19
|
-
export function renderKnexMigration(plan: SchemaMigrationPlan): string {
|
|
13
|
+
export function renderKnexMigration(plan: SchemaMigrationPlan, language: 'typescript' | 'javascript' = 'typescript'): string {
|
|
20
14
|
if (plan.blockedChanges.length > 0) {
|
|
21
15
|
throw new Error('Cannot render a migration plan containing blocked changes.');
|
|
22
16
|
}
|
|
@@ -26,7 +20,7 @@ export function renderKnexMigration(plan: SchemaMigrationPlan): string {
|
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
const lines = [
|
|
29
|
-
"import type { Knex } from 'knex';",
|
|
23
|
+
...(language === 'typescript' ? ["import type { Knex } from 'knex';"] : []),
|
|
30
24
|
'',
|
|
31
25
|
'/** Knex migration settings for MariaDB non-transactional DDL. */',
|
|
32
26
|
'export const config = { transaction: false };',
|
|
@@ -43,7 +37,7 @@ export function renderKnexMigration(plan: SchemaMigrationPlan): string {
|
|
|
43
37
|
' * @param knex - Knex connection managed by the application migration runner.',
|
|
44
38
|
' * @returns Promise that resolves after every schema operation completes.',
|
|
45
39
|
' */',
|
|
46
|
-
'export async function up(knex: Knex): Promise<void> {',
|
|
40
|
+
language === 'typescript' ? 'export async function up(knex: Knex): Promise<void> {' : 'export async function up(knex) {',
|
|
47
41
|
];
|
|
48
42
|
|
|
49
43
|
const body = renderMigrationBody(plan.safeChanges);
|
|
@@ -58,7 +52,7 @@ export function renderKnexMigration(plan: SchemaMigrationPlan): string {
|
|
|
58
52
|
' * @param _knex - Unused Knex connection supplied by the migration runner.',
|
|
59
53
|
' * @returns Promise that always rejects before performing database DDL.',
|
|
60
54
|
' */',
|
|
61
|
-
'export async function down(_knex: Knex): Promise<void> {',
|
|
55
|
+
language === 'typescript' ? 'export async function down(_knex: Knex): Promise<void> {' : 'export async function down(_knex) {',
|
|
62
56
|
"\tthrow new Error('Generated database migrations are forward-only.');",
|
|
63
57
|
'}',
|
|
64
58
|
'',
|
|
@@ -4,7 +4,7 @@ import { FLOW_INPUT_BLOCK_TYPE, FLOW_OUTPUT_BLOCK_TYPE } from './blocks';
|
|
|
4
4
|
import type { CompiledFlowBlock, CompiledFlowDefinition, FlowBlockDefinition, FlowBlockInstance, FlowConnection, FlowDefinition, FlowExecutionDefinition, FlowValueDefinition, FlowValueDefinitions } from './contracts';
|
|
5
5
|
import { FlowBlockRegistry } from './FlowBlockRegistry';
|
|
6
6
|
import { FlowDefinitionError, type FlowDefinitionIssue } from './FlowDefinitionError';
|
|
7
|
-
import { matchesDefinition, validateFlowValues } from './
|
|
7
|
+
import { matchesDefinition, validateFlowValues } from './flowValueValidator';
|
|
8
8
|
|
|
9
9
|
const FLOW_VALUE_TYPES = new Set([
|
|
10
10
|
'string',
|
package/src/flows/Flows.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { FlowCompiler } from './FlowCompiler';
|
|
|
8
8
|
import { FlowDefinitionError } from './FlowDefinitionError';
|
|
9
9
|
import { flowErrorSnapshot } from './errors';
|
|
10
10
|
import { FlowStepJob } from './FlowStepJob';
|
|
11
|
-
import { validateFlowValues } from './
|
|
11
|
+
import { validateFlowValues } from './flowValueValidator';
|
|
12
12
|
import { FlowRun, FlowRunEvent, FlowStepRun } from './models';
|
|
13
13
|
|
|
14
14
|
const DEFAULT_MAX_PAYLOAD_BYTES = 1024 * 1024;
|
package/src/flows/index.ts
CHANGED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type * as health from './contracts';
|
|
2
|
+
|
|
3
|
+
const STATUS_PRIORITY: Record<health.HealthStatus, number> = {
|
|
4
|
+
ok: 0,
|
|
5
|
+
degraded: 1,
|
|
6
|
+
unhealthy: 2,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Aggregates framework and application component checks into one safe report. */
|
|
10
|
+
export class Health {
|
|
11
|
+
readonly #service: string;
|
|
12
|
+
readonly #timeoutMs: number;
|
|
13
|
+
readonly #checks = new Map<string, health.HealthCheck>();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates an application health registry with the framework runtime check.
|
|
17
|
+
*
|
|
18
|
+
* @param options - Service identity and initial application checks.
|
|
19
|
+
*/
|
|
20
|
+
constructor(options: health.HealthOptions = {}) {
|
|
21
|
+
this.#service = options.service?.trim() || 'application';
|
|
22
|
+
this.#timeoutMs = positiveTimeout(options.timeoutMs);
|
|
23
|
+
this.register('application', () => ({ status: 'ok' }));
|
|
24
|
+
|
|
25
|
+
for (const [name, check] of Object.entries(options.checks ?? {})) {
|
|
26
|
+
this.register(name, check);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Registers or replaces one named component check.
|
|
32
|
+
*
|
|
33
|
+
* Stable names let applications override a framework default without
|
|
34
|
+
* producing duplicate output.
|
|
35
|
+
*
|
|
36
|
+
* @param name - Public component name used as the report key.
|
|
37
|
+
* @param check - Bounded check that returns only public-safe details.
|
|
38
|
+
* @returns This health service for fluent registration.
|
|
39
|
+
*/
|
|
40
|
+
register(name: string, check: health.HealthCheck): this {
|
|
41
|
+
const normalized = normalizeCheckName(name);
|
|
42
|
+
|
|
43
|
+
if (typeof check !== 'function') throw new TypeError(`Health check "${normalized}" must be a function.`);
|
|
44
|
+
this.#checks.set(normalized, check);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Removes one optional component check.
|
|
50
|
+
*
|
|
51
|
+
* The framework-owned application check cannot be removed because it makes
|
|
52
|
+
* the default endpoint useful without any application configuration.
|
|
53
|
+
*
|
|
54
|
+
* @param name - Registered component name.
|
|
55
|
+
* @returns Whether an application-owned check was removed.
|
|
56
|
+
*/
|
|
57
|
+
remove(name: string): boolean {
|
|
58
|
+
const normalized = normalizeCheckName(name);
|
|
59
|
+
if (normalized === 'application') return false;
|
|
60
|
+
return this.#checks.delete(normalized);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Executes all checks concurrently and returns a public-safe aggregate.
|
|
65
|
+
*
|
|
66
|
+
* Thrown values are contained and converted to a generic unhealthy result;
|
|
67
|
+
* applications must log diagnostic details inside their check when needed.
|
|
68
|
+
*
|
|
69
|
+
* @returns Current aggregate and per-component health state.
|
|
70
|
+
*/
|
|
71
|
+
async report(): Promise<health.HealthReport> {
|
|
72
|
+
const entries = await Promise.all(
|
|
73
|
+
[...this.#checks.entries()].map(async ([name, check]) => {
|
|
74
|
+
const startedAt = performance.now();
|
|
75
|
+
let result: health.HealthCheckResult;
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
result = normalizeCheckResult(await withTimeout(check(), this.#timeoutMs));
|
|
79
|
+
} catch {
|
|
80
|
+
result = { status: 'unhealthy', message: 'Health check failed.' };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return [name, {
|
|
84
|
+
...result,
|
|
85
|
+
durationMs: Math.max(0, Math.round(performance.now() - startedAt)),
|
|
86
|
+
}] as const;
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
const checks = Object.fromEntries(entries);
|
|
90
|
+
const status = entries.reduce<health.HealthStatus>((current, [, result]) => {
|
|
91
|
+
return STATUS_PRIORITY[result.status] > STATUS_PRIORITY[current] ? result.status : current;
|
|
92
|
+
}, 'ok');
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
status,
|
|
96
|
+
service: this.#service,
|
|
97
|
+
timestamp: new Date().toISOString(),
|
|
98
|
+
checks,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Normalizes and validates a public component name.
|
|
105
|
+
*
|
|
106
|
+
* @param name - Caller-supplied check name.
|
|
107
|
+
* @returns Trimmed stable report key.
|
|
108
|
+
*/
|
|
109
|
+
function normalizeCheckName(name: string): string {
|
|
110
|
+
const normalized = name.trim();
|
|
111
|
+
if (!normalized) throw new TypeError('Health check names cannot be empty.');
|
|
112
|
+
return normalized;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Applies the healthy default and validates a component result.
|
|
117
|
+
*
|
|
118
|
+
* @param result - Value returned by a registered health check.
|
|
119
|
+
* @returns Validated public-safe component result.
|
|
120
|
+
*/
|
|
121
|
+
function normalizeCheckResult(result: health.HealthCheckResult | void): health.HealthCheckResult {
|
|
122
|
+
if (result === undefined) return { status: 'ok' };
|
|
123
|
+
if (!Object.hasOwn(STATUS_PRIORITY, result.status)) throw new TypeError(`Unsupported health status "${String(result.status)}".`);
|
|
124
|
+
|
|
125
|
+
return result.message
|
|
126
|
+
? { status: result.status, message: result.message }
|
|
127
|
+
: { status: result.status };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Resolves the bounded per-check timeout.
|
|
132
|
+
*
|
|
133
|
+
* @param timeoutMs - Optional application override.
|
|
134
|
+
* @returns Positive timeout in milliseconds.
|
|
135
|
+
*/
|
|
136
|
+
function positiveTimeout(timeoutMs: number | undefined): number {
|
|
137
|
+
if (timeoutMs === undefined) return 3000;
|
|
138
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new TypeError('Health timeoutMs must be a positive number.');
|
|
139
|
+
return timeoutMs;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Prevents a stuck dependency from hanging the aggregate health endpoint.
|
|
144
|
+
*
|
|
145
|
+
* @param result - Check result or promise returned by the application.
|
|
146
|
+
* @param timeoutMs - Maximum time allowed for the check.
|
|
147
|
+
* @returns Check result before the timeout expires.
|
|
148
|
+
*/
|
|
149
|
+
async function withTimeout(result: ReturnType<health.HealthCheck>, timeoutMs: number): Promise<health.HealthCheckResult | void> {
|
|
150
|
+
let timer: NodeJS.Timeout | undefined;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
return await Promise.race([
|
|
154
|
+
Promise.resolve(result),
|
|
155
|
+
new Promise<never>((_resolve, reject) => {
|
|
156
|
+
timer = setTimeout(() => reject(new Error('Health check timed out.')), timeoutMs);
|
|
157
|
+
timer.unref();
|
|
158
|
+
}),
|
|
159
|
+
]);
|
|
160
|
+
} finally {
|
|
161
|
+
if (timer) clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Health
|
|
2
|
+
|
|
3
|
+
`@db3.ai/app/health` provides a small application health registry. It owns the
|
|
4
|
+
safe aggregate result while concrete HTTP adapters expose it to load balancers,
|
|
5
|
+
deployment gates and uptime monitors.
|
|
6
|
+
|
|
7
|
+
Every `App` has an `app().health` service with an `application` check, so a new
|
|
8
|
+
application can expose `/health` without defining custom checks. Applications
|
|
9
|
+
extend the report with stable names:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { databaseHealthCheck } from '@db3.ai/app/health';
|
|
13
|
+
|
|
14
|
+
application.health
|
|
15
|
+
.register('database', databaseHealthCheck(application.db))
|
|
16
|
+
.register('search-provider', async () => ({
|
|
17
|
+
status: providerConfigured ? 'ok' : 'degraded',
|
|
18
|
+
message: providerConfigured ? undefined : 'Optional search features are unavailable.',
|
|
19
|
+
}));
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Checks run concurrently with a three-second per-check timeout by default. A thrown value becomes a generic unhealthy result and
|
|
23
|
+
does not leak its error message through the public endpoint. Log private details
|
|
24
|
+
inside the application check when an operator needs them.
|
|
25
|
+
|
|
26
|
+
## Fastify
|
|
27
|
+
|
|
28
|
+
Register the canonical endpoint from `@db3.ai/app/health/fastify`:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { registerHealthRoute } from '@db3.ai/app/health/fastify';
|
|
32
|
+
|
|
33
|
+
registerHealthRoute(server, {
|
|
34
|
+
app: application,
|
|
35
|
+
path: '/health',
|
|
36
|
+
aliases: ['/healthz'],
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The endpoint returns `200` for `ok` and `degraded`, `503` for `unhealthy`, and
|
|
41
|
+
always sends `Cache-Control: no-store`. `/health` is the recommended public path;
|
|
42
|
+
aliases exist only for compatibility with existing infrastructure.
|
|
43
|
+
|
|
44
|
+
Health is deliberately narrower than telemetry. It answers whether this process
|
|
45
|
+
should receive traffic now. Metrics, traces and logs explain performance and
|
|
46
|
+
incidents over time.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Health states shared by aggregate reports and individual component checks. */
|
|
2
|
+
export type HealthStatus = 'ok' | 'degraded' | 'unhealthy';
|
|
3
|
+
|
|
4
|
+
/** Public-safe result returned by one named health check. */
|
|
5
|
+
export interface HealthCheckResult {
|
|
6
|
+
/** Current component state. Unhealthy checks make the aggregate endpoint unavailable. */
|
|
7
|
+
status: HealthStatus;
|
|
8
|
+
|
|
9
|
+
/** Optional public-safe explanation suitable for an operator or external monitor. */
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Recorded result for one component in an aggregate health report. */
|
|
14
|
+
export interface HealthCheckReport extends HealthCheckResult {
|
|
15
|
+
/** Time spent executing this check, rounded to milliseconds. */
|
|
16
|
+
durationMs: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Complete application health report returned by the HTTP adapter. */
|
|
20
|
+
export interface HealthReport {
|
|
21
|
+
/** Aggregate state derived from every registered component check. */
|
|
22
|
+
status: HealthStatus;
|
|
23
|
+
|
|
24
|
+
/** Stable service name configured by the application. */
|
|
25
|
+
service: string;
|
|
26
|
+
|
|
27
|
+
/** ISO timestamp recorded after all component checks complete. */
|
|
28
|
+
timestamp: string;
|
|
29
|
+
|
|
30
|
+
/** Results keyed by the stable names used when checks were registered. */
|
|
31
|
+
checks: Record<string, HealthCheckReport>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Function used to inspect one framework or application component. */
|
|
35
|
+
export type HealthCheck = () => HealthCheckResult | void | Promise<HealthCheckResult | void>;
|
|
36
|
+
|
|
37
|
+
/** Configuration accepted when the application health service is created. */
|
|
38
|
+
export interface HealthOptions {
|
|
39
|
+
/** Stable service name included in every report. */
|
|
40
|
+
service?: string;
|
|
41
|
+
|
|
42
|
+
/** Maximum time allowed for each check, defaulting to 3,000 milliseconds. */
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
|
|
45
|
+
/** Initial framework or application checks keyed by stable component name. */
|
|
46
|
+
checks?: Record<string, HealthCheck>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Health } from '../Health';
|
|
2
|
+
|
|
3
|
+
/** Minimal application shape required by the health HTTP adapter. */
|
|
4
|
+
export interface HealthApplication {
|
|
5
|
+
/** Health service whose aggregate report is exposed over HTTP. */
|
|
6
|
+
health: Health;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** HTTP route configuration shared by supported server adapters. */
|
|
10
|
+
export interface HealthRouteOptions {
|
|
11
|
+
/** Application that owns the health checks. */
|
|
12
|
+
app: HealthApplication;
|
|
13
|
+
|
|
14
|
+
/** Canonical endpoint path, defaulting to `/health`. */
|
|
15
|
+
path?: string;
|
|
16
|
+
|
|
17
|
+
/** Compatibility paths that return the same report. */
|
|
18
|
+
aliases?: string[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Database } from '../db';
|
|
2
|
+
import type { HealthCheck } from './contracts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates the standard database dependency check used by HTTP applications.
|
|
6
|
+
*
|
|
7
|
+
* The query proves the active connection can accept work without inspecting
|
|
8
|
+
* application tables or mutating customer data.
|
|
9
|
+
*
|
|
10
|
+
* @param database - Framework database service to query.
|
|
11
|
+
* @returns Health check suitable for `app().health.register()`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* app().health.register('database', databaseHealthCheck(app().db));
|
|
15
|
+
*/
|
|
16
|
+
export function databaseHealthCheck(database: Database): HealthCheck {
|
|
17
|
+
return async () => {
|
|
18
|
+
await database.knex.raw('SELECT 1');
|
|
19
|
+
return { status: 'ok' };
|
|
20
|
+
};
|
|
21
|
+
}
|