@db3.ai/app 0.1.0-beta.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/LICENSE +31 -0
- package/README.md +241 -0
- package/agent-instructions.md +69 -0
- package/bin/db3-agents.mjs +140 -0
- package/bin/db3.mjs +11 -0
- package/dist/ai/AIErrors.d.ts +33 -0
- package/dist/ai/AIErrors.js +43 -0
- package/dist/ai/AIFailover.d.ts +25 -0
- package/dist/ai/AIFailover.js +96 -0
- package/dist/ai/AIProviders.d.ts +35 -0
- package/dist/ai/AIProviders.js +197 -0
- package/dist/ai/AIQuotaDeferredError.d.ts +19 -0
- package/dist/ai/AIQuotaDeferredError.js +25 -0
- package/dist/ai/AIRateLimiter.d.ts +103 -0
- package/dist/ai/AIRateLimiter.js +690 -0
- package/dist/ai/Agent.d.ts +633 -0
- package/dist/ai/Agent.js +2976 -0
- package/dist/ai/AgentHistory.d.ts +11 -0
- package/dist/ai/AgentHistory.js +495 -0
- package/dist/ai/AgentRunJob.d.ts +21 -0
- package/dist/ai/AgentRunJob.js +53 -0
- package/dist/ai/Ai.d.ts +375 -0
- package/dist/ai/Ai.js +1771 -0
- package/dist/ai/AiConversation.d.ts +17 -0
- package/dist/ai/AiConversation.js +38 -0
- package/dist/ai/AiExecutionContext.d.ts +7 -0
- package/dist/ai/AiExecutionContext.js +16 -0
- package/dist/ai/AiMessage.d.ts +43 -0
- package/dist/ai/AiMessage.js +105 -0
- package/dist/ai/AiRateLimitBucket.d.ts +69 -0
- package/dist/ai/AiRateLimitBucket.js +138 -0
- package/dist/ai/AiRateLimitReservation.d.ts +56 -0
- package/dist/ai/AiRateLimitReservation.js +101 -0
- package/dist/ai/AiRequest.d.ts +78 -0
- package/dist/ai/AiRequest.js +384 -0
- package/dist/ai/Estimates.d.ts +26 -0
- package/dist/ai/Estimates.js +34 -0
- package/dist/ai/Models.d.ts +88 -0
- package/dist/ai/Models.js +328 -0
- package/dist/ai/OpenAIProviderError.d.ts +30 -0
- package/dist/ai/OpenAIProviderError.js +77 -0
- package/dist/ai/OpenAIQuotaRetry.d.ts +27 -0
- package/dist/ai/OpenAIQuotaRetry.js +144 -0
- package/dist/ai/ProviderCosts.d.ts +55 -0
- package/dist/ai/ProviderCosts.js +108 -0
- package/dist/ai/ResponsesProviderCall.d.ts +13 -0
- package/dist/ai/ResponsesProviderCall.js +29 -0
- package/dist/ai/agentCitations.d.ts +27 -0
- package/dist/ai/agentCitations.js +153 -0
- package/dist/ai/contracts/AI.d.ts +347 -0
- package/dist/ai/contracts/AI.js +13 -0
- package/dist/ai/contracts/Agent.d.ts +476 -0
- package/dist/ai/contracts/Agent.js +1 -0
- package/dist/ai/contracts/AiRequestRunCostSummary.d.ts +31 -0
- package/dist/ai/contracts/AiRequestRunCostSummary.js +1 -0
- package/dist/ai/contracts/Pricing.d.ts +88 -0
- package/dist/ai/contracts/Pricing.js +1 -0
- package/dist/ai/contracts/Providers.d.ts +68 -0
- package/dist/ai/contracts/Providers.js +1 -0
- package/dist/ai/contracts/QuotaRetry.d.ts +38 -0
- package/dist/ai/contracts/QuotaRetry.js +1 -0
- package/dist/ai/contracts/RateLimits.d.ts +45 -0
- package/dist/ai/contracts/RateLimits.js +1 -0
- package/dist/ai/contracts/ResponsesProviderCall.d.ts +28 -0
- package/dist/ai/contracts/ResponsesProviderCall.js +1 -0
- package/dist/ai/contracts/index.d.ts +8 -0
- package/dist/ai/contracts/index.js +8 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/index.js +27 -0
- package/dist/ai/registry.d.ts +28 -0
- package/dist/ai/registry.js +49 -0
- package/dist/ai/sdkNodeCompatibility.d.ts +76 -0
- package/dist/ai/toolCallRecovery.d.ts +16 -0
- package/dist/ai/toolCallRecovery.js +71 -0
- package/dist/ai/toolHelpers.d.ts +65 -0
- package/dist/ai/toolHelpers.js +106 -0
- package/dist/auth/Auth.d.ts +641 -0
- package/dist/auth/Auth.js +927 -0
- package/dist/auth/AuthProvider.d.ts +104 -0
- package/dist/auth/AuthProvider.js +185 -0
- package/dist/auth/AuthToken.d.ts +123 -0
- package/dist/auth/AuthToken.js +156 -0
- package/dist/auth/PasswordResetToken.d.ts +33 -0
- package/dist/auth/PasswordResetToken.js +64 -0
- package/dist/auth/UserIdentity.d.ts +46 -0
- package/dist/auth/UserIdentity.js +72 -0
- package/dist/auth/contracts/AuthProviderDriver.d.ts +94 -0
- package/dist/auth/contracts/AuthProviderDriver.js +1 -0
- package/dist/auth/contracts/index.d.ts +1 -0
- package/dist/auth/contracts/index.js +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/passwordHash.d.ts +26 -0
- package/dist/auth/passwordHash.js +96 -0
- package/dist/auth/providers/GoogleAuthProvider.d.ts +135 -0
- package/dist/auth/providers/GoogleAuthProvider.js +305 -0
- package/dist/auth/providers/PasswordAuthProvider.d.ts +115 -0
- package/dist/auth/providers/PasswordAuthProvider.js +195 -0
- package/dist/auth/providers/index.d.ts +3 -0
- package/dist/auth/providers/index.js +3 -0
- package/dist/auth/providers/resolveAuthProviders.d.ts +29 -0
- package/dist/auth/providers/resolveAuthProviders.js +111 -0
- package/dist/cache/Cache.d.ts +67 -0
- package/dist/cache/Cache.js +115 -0
- package/dist/cache/contracts/CacheDriver.d.ts +10 -0
- package/dist/cache/contracts/CacheDriver.js +1 -0
- package/dist/cache/contracts/CacheOperations.d.ts +26 -0
- package/dist/cache/contracts/CacheOperations.js +1 -0
- package/dist/cache/contracts/CacheOptions.d.ts +51 -0
- package/dist/cache/contracts/CacheOptions.js +1 -0
- package/dist/cache/contracts/CacheRepository.d.ts +45 -0
- package/dist/cache/contracts/CacheRepository.js +1 -0
- package/dist/cache/contracts/index.d.ts +4 -0
- package/dist/cache/contracts/index.js +4 -0
- package/dist/cache/drivers/CacheManagerDriver.d.ts +55 -0
- package/dist/cache/drivers/CacheManagerDriver.js +68 -0
- package/dist/cache/drivers/createCacheDriver.d.ts +8 -0
- package/dist/cache/drivers/createCacheDriver.js +147 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.js +2 -0
- package/dist/cli/Cli.d.ts +17 -0
- package/dist/cli/Cli.js +120 -0
- package/dist/cli/commands/repl.d.ts +9 -0
- package/dist/cli/commands/repl.js +27 -0
- package/dist/cli/contracts/CliCommand.d.ts +30 -0
- package/dist/cli/contracts/CliCommand.js +1 -0
- package/dist/cli/contracts/CliConfig.d.ts +9 -0
- package/dist/cli/contracts/CliConfig.js +1 -0
- package/dist/cli/contracts/CliOptions.d.ts +13 -0
- package/dist/cli/contracts/CliOptions.js +1 -0
- package/dist/cli/contracts/CommandDefinition.d.ts +18 -0
- package/dist/cli/contracts/CommandDefinition.js +1 -0
- package/dist/cli/contracts/ReplOptions.d.ts +11 -0
- package/dist/cli/contracts/ReplOptions.js +1 -0
- package/dist/cli/contracts/index.d.ts +5 -0
- package/dist/cli/contracts/index.js +1 -0
- package/dist/cli/defineCommand.d.ts +10 -0
- package/dist/cli/defineCommand.js +25 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +5 -0
- package/dist/cli/runDb3.d.ts +11 -0
- package/dist/cli/runDb3.js +70 -0
- package/dist/cli/runRepl.d.ts +12 -0
- package/dist/cli/runRepl.js +54 -0
- package/dist/config/Config.d.ts +48 -0
- package/dist/config/Config.js +80 -0
- package/dist/config/env.d.ts +26 -0
- package/dist/config/env.js +117 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/db/ActiveProjection.d.ts +90 -0
- package/dist/db/ActiveProjection.js +134 -0
- package/dist/db/ActiveQueryBuilder.d.ts +268 -0
- package/dist/db/ActiveQueryBuilder.js +621 -0
- package/dist/db/ActiveRecord.d.ts +483 -0
- package/dist/db/ActiveRecord.js +765 -0
- package/dist/db/Database.d.ts +277 -0
- package/dist/db/Database.js +827 -0
- package/dist/db/FieldType.d.ts +540 -0
- package/dist/db/FieldType.js +706 -0
- package/dist/db/SoftDeletes.d.ts +30 -0
- package/dist/db/SoftDeletes.js +93 -0
- package/dist/db/commands/check.d.ts +6 -0
- package/dist/db/commands/check.js +8 -0
- package/dist/db/commands/index.d.ts +6 -0
- package/dist/db/commands/index.js +17 -0
- package/dist/db/commands/makeMigration.d.ts +7 -0
- package/dist/db/commands/makeMigration.js +9 -0
- package/dist/db/commands/migrate.d.ts +6 -0
- package/dist/db/commands/migrate.js +8 -0
- package/dist/db/connection.d.ts +10 -0
- package/dist/db/connection.js +55 -0
- package/dist/db/contracts/ActiveRecordDefinition.d.ts +64 -0
- package/dist/db/contracts/ActiveRecordDefinition.js +1 -0
- package/dist/db/contracts/DatabaseBackup.d.ts +7 -0
- package/dist/db/contracts/DatabaseBackup.js +1 -0
- package/dist/db/contracts/DatabaseMigrationsConfig.d.ts +9 -0
- package/dist/db/contracts/DatabaseMigrationsConfig.js +1 -0
- package/dist/db/contracts/index.d.ts +3 -0
- package/dist/db/contracts/index.js +3 -0
- package/dist/db/dialects/columnTypes.d.ts +20 -0
- package/dist/db/dialects/columnTypes.js +67 -0
- package/dist/db/dialects/index.d.ts +6 -0
- package/dist/db/dialects/index.js +6 -0
- package/dist/db/dialects/mariadb.d.ts +7 -0
- package/dist/db/dialects/mariadb.js +35 -0
- package/dist/db/dialects/mysql.d.ts +14 -0
- package/dist/db/dialects/mysql.js +203 -0
- package/dist/db/dialects/postgres.d.ts +5 -0
- package/dist/db/dialects/postgres.js +106 -0
- package/dist/db/dialects/resolveDialect.d.ts +14 -0
- package/dist/db/dialects/resolveDialect.js +57 -0
- package/dist/db/dialects/types.d.ts +44 -0
- package/dist/db/dialects/types.js +1 -0
- package/dist/db/errors.d.ts +15 -0
- package/dist/db/errors.js +20 -0
- package/dist/db/fields/BooleanField.d.ts +29 -0
- package/dist/db/fields/BooleanField.js +89 -0
- package/dist/db/fields/CharUuidField.d.ts +29 -0
- package/dist/db/fields/CharUuidField.js +63 -0
- package/dist/db/fields/ChoiceStringField.d.ts +25 -0
- package/dist/db/fields/ChoiceStringField.js +58 -0
- package/dist/db/fields/DecimalField.d.ts +20 -0
- package/dist/db/fields/DecimalField.js +105 -0
- package/dist/db/fields/EmailField.d.ts +31 -0
- package/dist/db/fields/EmailField.js +52 -0
- package/dist/db/fields/EncryptedJsonField.d.ts +82 -0
- package/dist/db/fields/EncryptedJsonField.js +169 -0
- package/dist/db/fields/IntegerField.d.ts +35 -0
- package/dist/db/fields/IntegerField.js +139 -0
- package/dist/db/fields/JsonField.d.ts +40 -0
- package/dist/db/fields/JsonField.js +79 -0
- package/dist/db/fields/JsonStringField.d.ts +21 -0
- package/dist/db/fields/JsonStringField.js +41 -0
- package/dist/db/fields/LinkField.d.ts +180 -0
- package/dist/db/fields/LinkField.js +359 -0
- package/dist/db/fields/PasswordField.d.ts +93 -0
- package/dist/db/fields/PasswordField.js +180 -0
- package/dist/db/fields/StringField.d.ts +43 -0
- package/dist/db/fields/StringField.js +102 -0
- package/dist/db/fields/StringListField.d.ts +54 -0
- package/dist/db/fields/StringListField.js +124 -0
- package/dist/db/fields/TextField.d.ts +25 -0
- package/dist/db/fields/TextField.js +44 -0
- package/dist/db/fields/TimestampField.d.ts +47 -0
- package/dist/db/fields/TimestampField.js +97 -0
- package/dist/db/fields/UlidField.d.ts +69 -0
- package/dist/db/fields/UlidField.js +114 -0
- package/dist/db/fields/UrlField.d.ts +30 -0
- package/dist/db/fields/UrlField.js +61 -0
- package/dist/db/fields/VectorField.d.ts +64 -0
- package/dist/db/fields/VectorField.js +180 -0
- package/dist/db/fields/createField.d.ts +2 -0
- package/dist/db/fields/createField.js +13 -0
- package/dist/db/fields/field.d.ts +36 -0
- package/dist/db/fields/field.js +101 -0
- package/dist/db/fields/index.d.ts +18 -0
- package/dist/db/fields/index.js +18 -0
- package/dist/db/fields/resolveFields.d.ts +17 -0
- package/dist/db/fields/resolveFields.js +38 -0
- package/dist/db/index.d.ts +13 -0
- package/dist/db/index.js +13 -0
- package/dist/db/migrations/DatabaseMigrationManager.d.ts +57 -0
- package/dist/db/migrations/DatabaseMigrationManager.js +589 -0
- package/dist/db/migrations/DatabaseSchemaInspector.d.ts +19 -0
- package/dist/db/migrations/DatabaseSchemaInspector.js +384 -0
- package/dist/db/migrations/KnexMigrationRenderer.d.ts +11 -0
- package/dist/db/migrations/KnexMigrationRenderer.js +390 -0
- package/dist/db/migrations/ModelSchemaCollector.d.ts +29 -0
- package/dist/db/migrations/ModelSchemaCollector.js +183 -0
- package/dist/db/migrations/SchemaDiffer.d.ts +13 -0
- package/dist/db/migrations/SchemaDiffer.js +427 -0
- package/dist/db/migrations/SchemaNames.d.ts +27 -0
- package/dist/db/migrations/SchemaNames.js +46 -0
- package/dist/db/migrations/SchemaSnapshotSerializer.d.ts +30 -0
- package/dist/db/migrations/SchemaSnapshotSerializer.js +49 -0
- package/dist/db/migrations/contracts/DatabaseMigration.d.ts +118 -0
- package/dist/db/migrations/contracts/DatabaseMigration.js +1 -0
- package/dist/db/migrations/contracts/SchemaChange.d.ts +83 -0
- package/dist/db/migrations/contracts/SchemaChange.js +1 -0
- package/dist/db/migrations/contracts/SchemaSnapshot.d.ts +94 -0
- package/dist/db/migrations/contracts/SchemaSnapshot.js +1 -0
- package/dist/db/migrations/contracts/index.d.ts +3 -0
- package/dist/db/migrations/contracts/index.js +3 -0
- package/dist/db/migrations/errors.d.ts +35 -0
- package/dist/db/migrations/errors.js +45 -0
- package/dist/db/migrations/index.d.ts +10 -0
- package/dist/db/migrations/index.js +10 -0
- package/dist/db/migrations/promoteDestructiveSchemaChanges.d.ts +19 -0
- package/dist/db/migrations/promoteDestructiveSchemaChanges.js +102 -0
- package/dist/db/queryMonitor.d.ts +142 -0
- package/dist/db/queryMonitor.js +357 -0
- package/dist/db/sqlErrors.d.ts +11 -0
- package/dist/db/sqlErrors.js +17 -0
- package/dist/db/test/db.d.ts +11 -0
- package/dist/db/test/db.js +109 -0
- package/dist/devtools/HttpEventDispatcher.d.ts +19 -0
- package/dist/devtools/HttpEventDispatcher.js +180 -0
- package/dist/devtools/contracts/DevtoolsEventDispatcher.d.ts +53 -0
- package/dist/devtools/contracts/DevtoolsEventDispatcher.js +1 -0
- package/dist/devtools/contracts/index.d.ts +1 -0
- package/dist/devtools/contracts/index.js +1 -0
- package/dist/devtools/environment.d.ts +10 -0
- package/dist/devtools/environment.js +14 -0
- package/dist/devtools/index.d.ts +3 -0
- package/dist/devtools/index.js +3 -0
- package/dist/events/Events.d.ts +70 -0
- package/dist/events/Events.js +126 -0
- package/dist/events/contracts/EventConstructor.d.ts +12 -0
- package/dist/events/contracts/EventConstructor.js +1 -0
- package/dist/events/contracts/EventListener.d.ts +6 -0
- package/dist/events/contracts/EventListener.js +1 -0
- package/dist/events/contracts/EventUnsubscribe.d.ts +4 -0
- package/dist/events/contracts/EventUnsubscribe.js +1 -0
- package/dist/events/contracts/index.d.ts +3 -0
- package/dist/events/contracts/index.js +3 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +2 -0
- package/dist/flows/FlowBlockRegistry.d.ts +39 -0
- package/dist/flows/FlowBlockRegistry.js +66 -0
- package/dist/flows/FlowCompiler.d.ts +26 -0
- package/dist/flows/FlowCompiler.js +488 -0
- package/dist/flows/FlowDefinitionError.d.ts +21 -0
- package/dist/flows/FlowDefinitionError.js +16 -0
- package/dist/flows/FlowStepJob.d.ts +28 -0
- package/dist/flows/FlowStepJob.js +31 -0
- package/dist/flows/FlowValueValidator.d.ts +32 -0
- package/dist/flows/FlowValueValidator.js +105 -0
- package/dist/flows/Flows.d.ts +102 -0
- package/dist/flows/Flows.js +871 -0
- package/dist/flows/blocks/FlowInput.d.ts +10 -0
- package/dist/flows/blocks/FlowInput.js +29 -0
- package/dist/flows/blocks/FlowOutput.d.ts +10 -0
- package/dist/flows/blocks/FlowOutput.js +29 -0
- package/dist/flows/blocks/Subflow.d.ts +10 -0
- package/dist/flows/blocks/Subflow.js +21 -0
- package/dist/flows/blocks/index.d.ts +6 -0
- package/dist/flows/blocks/index.js +8 -0
- package/dist/flows/constants.d.ts +55 -0
- package/dist/flows/constants.js +47 -0
- package/dist/flows/contracts/FlowBlock.d.ts +64 -0
- package/dist/flows/contracts/FlowBlock.js +1 -0
- package/dist/flows/contracts/FlowCompiler.d.ts +30 -0
- package/dist/flows/contracts/FlowCompiler.js +1 -0
- package/dist/flows/contracts/FlowDefinition.d.ts +118 -0
- package/dist/flows/contracts/FlowDefinition.js +1 -0
- package/dist/flows/contracts/FlowDefinitionStore.d.ts +47 -0
- package/dist/flows/contracts/FlowDefinitionStore.js +1 -0
- package/dist/flows/contracts/FlowRun.d.ts +40 -0
- package/dist/flows/contracts/FlowRun.js +1 -0
- package/dist/flows/contracts/FlowValue.d.ts +49 -0
- package/dist/flows/contracts/FlowValue.js +1 -0
- package/dist/flows/contracts/FlowsService.d.ts +37 -0
- package/dist/flows/contracts/FlowsService.js +1 -0
- package/dist/flows/contracts/index.d.ts +7 -0
- package/dist/flows/contracts/index.js +7 -0
- package/dist/flows/defineBlock.d.ts +18 -0
- package/dist/flows/defineBlock.js +19 -0
- package/dist/flows/drivers/FileFlowDefinitionStore.d.ts +53 -0
- package/dist/flows/drivers/FileFlowDefinitionStore.js +313 -0
- package/dist/flows/drivers/index.d.ts +1 -0
- package/dist/flows/drivers/index.js +1 -0
- package/dist/flows/errors.d.ts +8 -0
- package/dist/flows/errors.js +19 -0
- package/dist/flows/index.d.ts +13 -0
- package/dist/flows/index.js +13 -0
- package/dist/flows/models/FlowRun.d.ts +55 -0
- package/dist/flows/models/FlowRun.js +126 -0
- package/dist/flows/models/FlowRunEvent.d.ts +41 -0
- package/dist/flows/models/FlowRunEvent.js +85 -0
- package/dist/flows/models/FlowStepRun.d.ts +56 -0
- package/dist/flows/models/FlowStepRun.js +137 -0
- package/dist/flows/models/index.d.ts +10 -0
- package/dist/flows/models/index.js +14 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +16 -0
- package/dist/logging/Log.d.ts +66 -0
- package/dist/logging/Log.js +79 -0
- package/dist/logging/contracts/HttpExchange.d.ts +50 -0
- package/dist/logging/contracts/HttpExchange.js +1 -0
- package/dist/logging/contracts/Logger.d.ts +41 -0
- package/dist/logging/contracts/Logger.js +1 -0
- package/dist/logging/contracts/LoggerDriver.d.ts +16 -0
- package/dist/logging/contracts/LoggerDriver.js +1 -0
- package/dist/logging/contracts/LoggingOptions.d.ts +49 -0
- package/dist/logging/contracts/LoggingOptions.js +1 -0
- package/dist/logging/contracts/index.d.ts +4 -0
- package/dist/logging/contracts/index.js +4 -0
- package/dist/logging/drivers/PinoLoggerDriver.d.ts +24 -0
- package/dist/logging/drivers/PinoLoggerDriver.js +291 -0
- package/dist/logging/drivers/index.d.ts +1 -0
- package/dist/logging/drivers/index.js +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/transports/DevtoolsLogTransport.d.ts +35 -0
- package/dist/logging/transports/DevtoolsLogTransport.js +96 -0
- package/dist/mail/Mail.d.ts +62 -0
- package/dist/mail/Mail.js +98 -0
- package/dist/mail/index.d.ts +4 -0
- package/dist/mail/index.js +4 -0
- package/dist/mail/transports/FileMailTransport.d.ts +12 -0
- package/dist/mail/transports/FileMailTransport.js +41 -0
- package/dist/mail/transports/MailgunTransport.d.ts +22 -0
- package/dist/mail/transports/MailgunTransport.js +57 -0
- package/dist/mail/transports/ResendTransport.d.ts +14 -0
- package/dist/mail/transports/ResendTransport.js +55 -0
- package/dist/media/MediaFile.d.ts +48 -0
- package/dist/media/MediaFile.js +104 -0
- package/dist/media/MediaItem.d.ts +47 -0
- package/dist/media/MediaItem.js +106 -0
- package/dist/media/MediaLibrary.d.ts +42 -0
- package/dist/media/MediaLibrary.js +94 -0
- package/dist/media/MediaManager.d.ts +159 -0
- package/dist/media/MediaManager.js +754 -0
- package/dist/media/constants.d.ts +27 -0
- package/dist/media/constants.js +19 -0
- package/dist/media/contracts/MediaOptions.d.ts +8 -0
- package/dist/media/contracts/MediaOptions.js +1 -0
- package/dist/media/contracts/index.d.ts +1 -0
- package/dist/media/contracts/index.js +1 -0
- package/dist/media/image/ImageReconstructionError.d.ts +15 -0
- package/dist/media/image/ImageReconstructionError.js +18 -0
- package/dist/media/image/ImageVariantRenderer.d.ts +44 -0
- package/dist/media/image/ImageVariantRenderer.js +337 -0
- package/dist/media/image/ImageVariantRequest.d.ts +28 -0
- package/dist/media/image/ImageVariantRequest.js +55 -0
- package/dist/media/image/contracts/ImageProcessor.d.ts +46 -0
- package/dist/media/image/contracts/ImageProcessor.js +1 -0
- package/dist/media/image/contracts/ImageVariant.d.ts +31 -0
- package/dist/media/image/contracts/ImageVariant.js +7 -0
- package/dist/media/image/contracts/ImageVariantCacheOptions.d.ts +20 -0
- package/dist/media/image/contracts/ImageVariantCacheOptions.js +1 -0
- package/dist/media/image/contracts/index.d.ts +3 -0
- package/dist/media/image/contracts/index.js +3 -0
- package/dist/media/image/index.d.ts +5 -0
- package/dist/media/image/index.js +5 -0
- package/dist/media/image/processors/SharpImageProcessor.d.ts +25 -0
- package/dist/media/image/processors/SharpImageProcessor.js +112 -0
- package/dist/media/image/processors/index.d.ts +1 -0
- package/dist/media/image/processors/index.js +1 -0
- package/dist/media/index.d.ts +8 -0
- package/dist/media/index.js +8 -0
- package/dist/media/types.d.ts +129 -0
- package/dist/media/types.js +1 -0
- package/dist/queue/FailedJob.d.ts +31 -0
- package/dist/queue/FailedJob.js +41 -0
- package/dist/queue/Queue.d.ts +208 -0
- package/dist/queue/Queue.js +685 -0
- package/dist/queue/QueueEvents.d.ts +31 -0
- package/dist/queue/QueueEvents.js +49 -0
- package/dist/queue/QueueRetryLaterError.d.ts +23 -0
- package/dist/queue/QueueRetryLaterError.js +34 -0
- package/dist/queue/QueueWorker.d.ts +72 -0
- package/dist/queue/QueueWorker.js +236 -0
- package/dist/queue/QueueableJob.d.ts +109 -0
- package/dist/queue/QueueableJob.js +137 -0
- package/dist/queue/QueuedJob.d.ts +31 -0
- package/dist/queue/QueuedJob.js +52 -0
- package/dist/queue/RetryPolicy.d.ts +51 -0
- package/dist/queue/RetryPolicy.js +84 -0
- package/dist/queue/commands/index.d.ts +4 -0
- package/dist/queue/commands/index.js +11 -0
- package/dist/queue/commands/makeJob.d.ts +7 -0
- package/dist/queue/commands/makeJob.js +9 -0
- package/dist/queue/console.d.ts +60 -0
- package/dist/queue/console.js +348 -0
- package/dist/queue/contracts/CreateJob.d.ts +12 -0
- package/dist/queue/contracts/CreateJob.js +1 -0
- package/dist/queue/contracts/QueueDriver.d.ts +122 -0
- package/dist/queue/contracts/QueueDriver.js +1 -0
- package/dist/queue/contracts/QueueEvents.d.ts +61 -0
- package/dist/queue/contracts/QueueEvents.js +1 -0
- package/dist/queue/contracts/QueuePayload.d.ts +136 -0
- package/dist/queue/contracts/QueuePayload.js +1 -0
- package/dist/queue/contracts/QueueRetry.d.ts +43 -0
- package/dist/queue/contracts/QueueRetry.js +1 -0
- package/dist/queue/contracts/QueueService.d.ts +199 -0
- package/dist/queue/contracts/QueueService.js +1 -0
- package/dist/queue/contracts/QueueWorkerLifecycle.d.ts +65 -0
- package/dist/queue/contracts/QueueWorkerLifecycle.js +1 -0
- package/dist/queue/contracts/QueueableJob.d.ts +50 -0
- package/dist/queue/contracts/QueueableJob.js +1 -0
- package/dist/queue/contracts/RedisQueueDriver.d.ts +37 -0
- package/dist/queue/contracts/RedisQueueDriver.js +1 -0
- package/dist/queue/contracts/index.d.ts +9 -0
- package/dist/queue/contracts/index.js +9 -0
- package/dist/queue/createJob.d.ts +18 -0
- package/dist/queue/createJob.js +52 -0
- package/dist/queue/drivers/DatabaseQueueDriver.d.ts +83 -0
- package/dist/queue/drivers/DatabaseQueueDriver.js +393 -0
- package/dist/queue/drivers/RedisQueueDriver.d.ts +102 -0
- package/dist/queue/drivers/RedisQueueDriver.js +641 -0
- package/dist/queue/index.d.ts +13 -0
- package/dist/queue/index.js +13 -0
- package/dist/queue/queueMonitor.d.ts +133 -0
- package/dist/queue/queueMonitor.js +238 -0
- package/dist/scheduler/ScheduledCall.d.ts +25 -0
- package/dist/scheduler/ScheduledCall.js +31 -0
- package/dist/scheduler/ScheduledEvent.d.ts +74 -0
- package/dist/scheduler/ScheduledEvent.js +115 -0
- package/dist/scheduler/ScheduledJob.d.ts +34 -0
- package/dist/scheduler/ScheduledJob.js +50 -0
- package/dist/scheduler/ScheduledOccurrence.d.ts +74 -0
- package/dist/scheduler/ScheduledOccurrence.js +194 -0
- package/dist/scheduler/ScheduledOccurrenceRecorder.d.ts +34 -0
- package/dist/scheduler/ScheduledOccurrenceRecorder.js +106 -0
- package/dist/scheduler/Scheduler.d.ts +76 -0
- package/dist/scheduler/Scheduler.js +186 -0
- package/dist/scheduler/SchedulerWorker.d.ts +37 -0
- package/dist/scheduler/SchedulerWorker.js +119 -0
- package/dist/scheduler/console.d.ts +18 -0
- package/dist/scheduler/console.js +288 -0
- package/dist/scheduler/constants.d.ts +13 -0
- package/dist/scheduler/constants.js +23 -0
- package/dist/scheduler/contracts/Scheduler.d.ts +104 -0
- package/dist/scheduler/contracts/Scheduler.js +1 -0
- package/dist/scheduler/contracts/SchedulerConsole.d.ts +37 -0
- package/dist/scheduler/contracts/SchedulerConsole.js +1 -0
- package/dist/scheduler/contracts/SchedulerWorker.d.ts +18 -0
- package/dist/scheduler/contracts/SchedulerWorker.js +1 -0
- package/dist/scheduler/contracts/index.d.ts +3 -0
- package/dist/scheduler/contracts/index.js +3 -0
- package/dist/scheduler/index.d.ts +9 -0
- package/dist/scheduler/index.js +9 -0
- package/dist/scheduler/scheduleTime.d.ts +30 -0
- package/dist/scheduler/scheduleTime.js +64 -0
- package/dist/security/Security.d.ts +60 -0
- package/dist/security/Security.js +252 -0
- package/dist/security/SecurityError.d.ts +13 -0
- package/dist/security/SecurityError.js +16 -0
- package/dist/security/contracts/SecurityOptions.d.ts +17 -0
- package/dist/security/contracts/SecurityOptions.js +1 -0
- package/dist/security/contracts/SecurityPayload.d.ts +13 -0
- package/dist/security/contracts/SecurityPayload.js +1 -0
- package/dist/security/contracts/index.d.ts +2 -0
- package/dist/security/contracts/index.js +2 -0
- package/dist/security/ensureAppKey.d.ts +16 -0
- package/dist/security/ensureAppKey.js +69 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.js +4 -0
- package/dist/serialization/Serializable.d.ts +17 -0
- package/dist/serialization/Serializable.js +1 -0
- package/dist/serialization/SerializationError.d.ts +40 -0
- package/dist/serialization/SerializationError.js +42 -0
- package/dist/serialization/SerializationRegistry.d.ts +76 -0
- package/dist/serialization/SerializationRegistry.js +153 -0
- package/dist/serialization/SerializationRegistryError.d.ts +18 -0
- package/dist/serialization/SerializationRegistryError.js +18 -0
- package/dist/serialization/Serializer.d.ts +37 -0
- package/dist/serialization/Serializer.js +477 -0
- package/dist/serialization/contracts/SerializableClass.d.ts +20 -0
- package/dist/serialization/contracts/SerializableClass.js +1 -0
- package/dist/serialization/contracts/SerializedValue.d.ts +59 -0
- package/dist/serialization/contracts/SerializedValue.js +19 -0
- package/dist/serialization/contracts/SerializerOptions.d.ts +17 -0
- package/dist/serialization/contracts/SerializerOptions.js +1 -0
- package/dist/serialization/contracts/SerializerService.d.ts +26 -0
- package/dist/serialization/contracts/SerializerService.js +1 -0
- package/dist/serialization/contracts/index.d.ts +4 -0
- package/dist/serialization/contracts/index.js +4 -0
- package/dist/serialization/index.d.ts +6 -0
- package/dist/serialization/index.js +6 -0
- package/dist/server/App.d.ts +141 -0
- package/dist/server/App.js +225 -0
- package/dist/server/RequestContext.d.ts +42 -0
- package/dist/server/RequestContext.js +95 -0
- package/dist/server/appContext.d.ts +34 -0
- package/dist/server/appContext.js +42 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/ssr/constants.d.ts +6 -0
- package/dist/ssr/constants.js +6 -0
- package/dist/ssr/contracts/DocumentHead.d.ts +32 -0
- package/dist/ssr/contracts/DocumentHead.js +1 -0
- package/dist/ssr/contracts/SsrRenderContext.d.ts +23 -0
- package/dist/ssr/contracts/SsrRenderContext.js +1 -0
- package/dist/ssr/contracts/SsrRenderResult.d.ts +21 -0
- package/dist/ssr/contracts/SsrRenderResult.js +1 -0
- package/dist/ssr/contracts/SsrRenderer.d.ts +9 -0
- package/dist/ssr/contracts/SsrRenderer.js +1 -0
- package/dist/ssr/contracts/SsrRequest.d.ts +16 -0
- package/dist/ssr/contracts/SsrRequest.js +1 -0
- package/dist/ssr/contracts/index.d.ts +5 -0
- package/dist/ssr/contracts/index.js +1 -0
- package/dist/ssr/createSsrRenderContext.d.ts +9 -0
- package/dist/ssr/createSsrRenderContext.js +20 -0
- package/dist/ssr/fastify/contracts/FastifySsrOptions.d.ts +21 -0
- package/dist/ssr/fastify/contracts/FastifySsrOptions.js +1 -0
- package/dist/ssr/fastify/contracts/index.d.ts +1 -0
- package/dist/ssr/fastify/contracts/index.js +1 -0
- package/dist/ssr/fastify/fastifySsr.d.ts +25 -0
- package/dist/ssr/fastify/fastifySsr.js +89 -0
- package/dist/ssr/fastify/index.d.ts +2 -0
- package/dist/ssr/fastify/index.js +1 -0
- package/dist/ssr/index.d.ts +6 -0
- package/dist/ssr/index.js +5 -0
- package/dist/ssr/renderDocumentHead.d.ts +8 -0
- package/dist/ssr/renderDocumentHead.js +62 -0
- package/dist/ssr/renderSsrDocument.d.ts +14 -0
- package/dist/ssr/renderSsrDocument.js +28 -0
- package/dist/ssr/serializeSsrState.d.ts +10 -0
- package/dist/ssr/serializeSsrState.js +18 -0
- package/dist/ssr/vite/contracts/ViteSsrOptions.d.ts +45 -0
- package/dist/ssr/vite/contracts/ViteSsrOptions.js +1 -0
- package/dist/ssr/vite/contracts/index.d.ts +1 -0
- package/dist/ssr/vite/contracts/index.js +1 -0
- package/dist/ssr/vite/fastifyViteSsr.d.ts +24 -0
- package/dist/ssr/vite/fastifyViteSsr.js +213 -0
- package/dist/ssr/vite/index.d.ts +4 -0
- package/dist/ssr/vite/index.js +2 -0
- package/dist/ssr/vite/viteSsrManifest.d.ts +16 -0
- package/dist/ssr/vite/viteSsrManifest.js +63 -0
- package/dist/storage/Storage.d.ts +244 -0
- package/dist/storage/Storage.js +348 -0
- package/dist/storage/contents.d.ts +8 -0
- package/dist/storage/contents.js +18 -0
- package/dist/storage/contracts/StorageListing.d.ts +50 -0
- package/dist/storage/contracts/StorageListing.js +1 -0
- package/dist/storage/contracts/index.d.ts +1 -0
- package/dist/storage/contracts/index.js +1 -0
- package/dist/storage/drivers/FlystorageDisk.d.ts +185 -0
- package/dist/storage/drivers/FlystorageDisk.js +250 -0
- package/dist/storage/drivers/FlystorageListing.d.ts +27 -0
- package/dist/storage/drivers/FlystorageListing.js +69 -0
- package/dist/storage/drivers/LocalStorageDisk.d.ts +25 -0
- package/dist/storage/drivers/LocalStorageDisk.js +38 -0
- package/dist/storage/drivers/S3StorageDisk.d.ts +17 -0
- package/dist/storage/drivers/S3StorageDisk.js +102 -0
- package/dist/storage/drivers/index.d.ts +3 -0
- package/dist/storage/drivers/index.js +3 -0
- package/dist/storage/index.d.ts +7 -0
- package/dist/storage/index.js +7 -0
- package/dist/storage/mime.d.ts +7 -0
- package/dist/storage/mime.js +28 -0
- package/dist/storage/path.d.ts +22 -0
- package/dist/storage/path.js +61 -0
- package/dist/storage/types.d.ts +218 -0
- package/dist/storage/types.js +1 -0
- package/dist/url/UrlGenerator.d.ts +32 -0
- package/dist/url/UrlGenerator.js +61 -0
- package/dist/url/contracts/UrlGeneratorOptions.d.ts +13 -0
- package/dist/url/contracts/UrlGeneratorOptions.js +1 -0
- package/dist/url/contracts/index.d.ts +1 -0
- package/dist/url/contracts/index.js +1 -0
- package/dist/url/index.d.ts +2 -0
- package/dist/url/index.js +2 -0
- package/dist/validation/index.d.ts +28 -0
- package/dist/validation/index.js +260 -0
- package/package.json +290 -0
- package/src/ai/AIErrors.ts +46 -0
- package/src/ai/AIFailover.ts +101 -0
- package/src/ai/AIProviders.ts +228 -0
- package/src/ai/AIQuotaDeferredError.ts +26 -0
- package/src/ai/AIRateLimiter.ts +880 -0
- package/src/ai/Agent.ts +3630 -0
- package/src/ai/AgentHistory.ts +576 -0
- package/src/ai/AgentRunJob.ts +65 -0
- package/src/ai/Ai.ts +2176 -0
- package/src/ai/AiConversation.ts +49 -0
- package/src/ai/AiExecutionContext.ts +19 -0
- package/src/ai/AiMessage.ts +131 -0
- package/src/ai/AiRateLimitBucket.ts +163 -0
- package/src/ai/AiRateLimitReservation.ts +117 -0
- package/src/ai/AiRequest.ts +466 -0
- package/src/ai/Estimates.ts +36 -0
- package/src/ai/Models.ts +373 -0
- package/src/ai/OpenAIProviderError.ts +98 -0
- package/src/ai/OpenAIQuotaRetry.ts +183 -0
- package/src/ai/ProviderCosts.ts +156 -0
- package/src/ai/README.md +187 -0
- package/src/ai/ResponsesProviderCall.ts +34 -0
- package/src/ai/agentCitations.ts +186 -0
- package/src/ai/contracts/AI.ts +380 -0
- package/src/ai/contracts/Agent.ts +539 -0
- package/src/ai/contracts/AiRequestRunCostSummary.ts +31 -0
- package/src/ai/contracts/Pricing.ts +95 -0
- package/src/ai/contracts/Providers.ts +73 -0
- package/src/ai/contracts/QuotaRetry.ts +39 -0
- package/src/ai/contracts/RateLimits.ts +49 -0
- package/src/ai/contracts/ResponsesProviderCall.ts +30 -0
- package/src/ai/contracts/index.ts +8 -0
- package/src/ai/examples/Conversation.ts +12 -0
- package/src/ai/examples/HelpAgent.ts +27 -0
- package/src/ai/examples/createHelpImage.ts +13 -0
- package/src/ai/index.ts +27 -0
- package/src/ai/registry.ts +70 -0
- package/src/ai/sdkNodeCompatibility.d.ts +76 -0
- package/src/ai/toolCallRecovery.ts +82 -0
- package/src/ai/toolHelpers.ts +145 -0
- package/src/auth/Auth.ts +1422 -0
- package/src/auth/AuthProvider.ts +251 -0
- package/src/auth/AuthToken.ts +239 -0
- package/src/auth/PasswordResetToken.ts +93 -0
- package/src/auth/README.md +396 -0
- package/src/auth/UserIdentity.ts +112 -0
- package/src/auth/contracts/AuthProviderDriver.ts +114 -0
- package/src/auth/contracts/index.ts +1 -0
- package/src/auth/examples/runPasswordAuth.ts +45 -0
- package/src/auth/index.ts +8 -0
- package/src/auth/passwordHash.ts +160 -0
- package/src/auth/providers/GoogleAuthProvider.ts +470 -0
- package/src/auth/providers/PasswordAuthProvider.ts +256 -0
- package/src/auth/providers/index.ts +3 -0
- package/src/auth/providers/resolveAuthProviders.ts +166 -0
- package/src/cache/Cache.ts +151 -0
- package/src/cache/README.md +137 -0
- package/src/cache/contracts/CacheDriver.ts +11 -0
- package/src/cache/contracts/CacheOperations.ts +28 -0
- package/src/cache/contracts/CacheOptions.ts +56 -0
- package/src/cache/contracts/CacheRepository.ts +62 -0
- package/src/cache/contracts/index.ts +4 -0
- package/src/cache/drivers/CacheManagerDriver.ts +84 -0
- package/src/cache/drivers/createCacheDriver.ts +191 -0
- package/src/cache/examples/runNoteCache.ts +37 -0
- package/src/cache/index.ts +2 -0
- package/src/cli/Cli.ts +110 -0
- package/src/cli/README.md +164 -0
- package/src/cli/commands/repl.ts +29 -0
- package/src/cli/contracts/CliCommand.ts +33 -0
- package/src/cli/contracts/CliConfig.ts +10 -0
- package/src/cli/contracts/CliOptions.ts +13 -0
- package/src/cli/contracts/CommandDefinition.ts +19 -0
- package/src/cli/contracts/ReplOptions.ts +11 -0
- package/src/cli/contracts/index.ts +5 -0
- package/src/cli/defineCommand.ts +25 -0
- package/src/cli/index.ts +5 -0
- package/src/cli/runDb3.ts +63 -0
- package/src/cli/runRepl.ts +55 -0
- package/src/config/Config.ts +110 -0
- package/src/config/README.md +142 -0
- package/src/config/env.ts +164 -0
- package/src/config/examples/loadNotesConfig.ts +29 -0
- package/src/config/examples/runConfig.ts +40 -0
- package/src/config/index.ts +2 -0
- package/src/db/ActiveProjection.ts +311 -0
- package/src/db/ActiveQueryBuilder.ts +831 -0
- package/src/db/ActiveRecord.ts +1317 -0
- package/src/db/Database.ts +1283 -0
- package/src/db/FieldType.ts +1243 -0
- package/src/db/README.md +508 -0
- package/src/db/SoftDeletes.ts +158 -0
- package/src/db/commands/check.ts +10 -0
- package/src/db/commands/index.ts +19 -0
- package/src/db/commands/makeMigration.ts +11 -0
- package/src/db/commands/migrate.ts +10 -0
- package/src/db/connection.ts +68 -0
- package/src/db/contracts/ActiveRecordDefinition.ts +69 -0
- package/src/db/contracts/DatabaseBackup.ts +7 -0
- package/src/db/contracts/DatabaseMigrationsConfig.ts +10 -0
- package/src/db/contracts/index.ts +3 -0
- package/src/db/dialects/columnTypes.ts +103 -0
- package/src/db/dialects/index.ts +6 -0
- package/src/db/dialects/mariadb.ts +51 -0
- package/src/db/dialects/mysql.ts +277 -0
- package/src/db/dialects/postgres.ts +143 -0
- package/src/db/dialects/resolveDialect.ts +88 -0
- package/src/db/dialects/types.ts +59 -0
- package/src/db/errors.ts +22 -0
- package/src/db/examples/DefinedUser.ts +20 -0
- package/src/db/examples/FieldNote.ts +27 -0
- package/src/db/examples/KnowledgeNote.ts +29 -0
- package/src/db/examples/NoteCodeField.ts +9 -0
- package/src/db/examples/createNotesTogether.ts +24 -0
- package/src/db/examples/outputs/workspace-notes.json +9 -0
- package/src/db/examples/runFieldNotes.ts +51 -0
- package/src/db/examples/runNoteMigrations.ts +64 -0
- package/src/db/examples/runWorkspaceNotes.ts +86 -0
- package/src/db/examples/workspaceNotes.ts +57 -0
- package/src/db/fields/BooleanField.ts +128 -0
- package/src/db/fields/CharUuidField.ts +91 -0
- package/src/db/fields/ChoiceStringField.ts +97 -0
- package/src/db/fields/DecimalField.ts +157 -0
- package/src/db/fields/EmailField.ts +79 -0
- package/src/db/fields/EncryptedJsonField.ts +211 -0
- package/src/db/fields/IntegerField.ts +200 -0
- package/src/db/fields/JsonField.ts +108 -0
- package/src/db/fields/JsonStringField.ts +63 -0
- package/src/db/fields/LinkField.ts +502 -0
- package/src/db/fields/PasswordField.ts +294 -0
- package/src/db/fields/StringField.ts +154 -0
- package/src/db/fields/StringListField.ts +179 -0
- package/src/db/fields/TextField.ts +71 -0
- package/src/db/fields/TimestampField.ts +164 -0
- package/src/db/fields/UlidField.ts +189 -0
- package/src/db/fields/UrlField.ts +97 -0
- package/src/db/fields/VectorField.ts +266 -0
- package/src/db/fields/createField.ts +22 -0
- package/src/db/fields/field.ts +209 -0
- package/src/db/fields/index.ts +76 -0
- package/src/db/fields/resolveFields.ts +69 -0
- package/src/db/index.ts +13 -0
- package/src/db/migrations/DatabaseMigrationManager.ts +756 -0
- package/src/db/migrations/DatabaseSchemaInspector.ts +541 -0
- package/src/db/migrations/KnexMigrationRenderer.ts +490 -0
- package/src/db/migrations/ModelSchemaCollector.ts +240 -0
- package/src/db/migrations/SchemaDiffer.ts +541 -0
- package/src/db/migrations/SchemaNames.ts +62 -0
- package/src/db/migrations/SchemaSnapshotSerializer.ts +59 -0
- package/src/db/migrations/contracts/DatabaseMigration.ts +143 -0
- package/src/db/migrations/contracts/SchemaChange.ts +113 -0
- package/src/db/migrations/contracts/SchemaSnapshot.ts +122 -0
- package/src/db/migrations/contracts/index.ts +3 -0
- package/src/db/migrations/errors.ts +45 -0
- package/src/db/migrations/index.ts +10 -0
- package/src/db/migrations/promoteDestructiveSchemaChanges.ts +120 -0
- package/src/db/queryMonitor.ts +549 -0
- package/src/db/sqlErrors.ts +36 -0
- package/src/db/test/db.ts +159 -0
- package/src/devtools/HttpEventDispatcher.ts +214 -0
- package/src/devtools/contracts/DevtoolsEventDispatcher.ts +57 -0
- package/src/devtools/contracts/index.ts +1 -0
- package/src/devtools/environment.ts +18 -0
- package/src/devtools/index.ts +3 -0
- package/src/events/Events.ts +165 -0
- package/src/events/README.md +106 -0
- package/src/events/contracts/EventConstructor.ts +12 -0
- package/src/events/contracts/EventListener.ts +8 -0
- package/src/events/contracts/EventUnsubscribe.ts +4 -0
- package/src/events/contracts/index.ts +3 -0
- package/src/events/examples/NoteSaved.ts +9 -0
- package/src/events/examples/runNoteEvents.ts +31 -0
- package/src/events/index.ts +2 -0
- package/src/flows/FlowBlockRegistry.ts +79 -0
- package/src/flows/FlowCompiler.ts +624 -0
- package/src/flows/FlowDefinitionError.ts +24 -0
- package/src/flows/FlowStepJob.ts +54 -0
- package/src/flows/FlowValueValidator.ts +120 -0
- package/src/flows/Flows.ts +1118 -0
- package/src/flows/README.md +144 -0
- package/src/flows/blocks/FlowInput.ts +32 -0
- package/src/flows/blocks/FlowOutput.ts +32 -0
- package/src/flows/blocks/Subflow.ts +24 -0
- package/src/flows/blocks/index.ts +11 -0
- package/src/flows/constants.ts +62 -0
- package/src/flows/contracts/FlowBlock.ts +73 -0
- package/src/flows/contracts/FlowCompiler.ts +32 -0
- package/src/flows/contracts/FlowDefinition.ts +126 -0
- package/src/flows/contracts/FlowDefinitionStore.ts +52 -0
- package/src/flows/contracts/FlowRun.ts +44 -0
- package/src/flows/contracts/FlowValue.ts +54 -0
- package/src/flows/contracts/FlowsService.ts +39 -0
- package/src/flows/contracts/index.ts +7 -0
- package/src/flows/defineBlock.ts +25 -0
- package/src/flows/drivers/FileFlowDefinitionStore.ts +372 -0
- package/src/flows/drivers/index.ts +1 -0
- package/src/flows/errors.ts +22 -0
- package/src/flows/examples/FlowExampleApp.ts +15 -0
- package/src/flows/examples/createTextFlow.ts +14 -0
- package/src/flows/examples/normalizeTextBlock.ts +15 -0
- package/src/flows/examples/runTextFlow.ts +46 -0
- package/src/flows/examples/uppercaseTextBlock.ts +11 -0
- package/src/flows/index.ts +13 -0
- package/src/flows/models/FlowRun.ts +164 -0
- package/src/flows/models/FlowRunEvent.ts +108 -0
- package/src/flows/models/FlowStepRun.ts +176 -0
- package/src/flows/models/index.ts +16 -0
- package/src/index.ts +40 -0
- package/src/logging/Log.ts +100 -0
- package/src/logging/README.md +139 -0
- package/src/logging/contracts/HttpExchange.ts +53 -0
- package/src/logging/contracts/Logger.ts +45 -0
- package/src/logging/contracts/LoggerDriver.ts +19 -0
- package/src/logging/contracts/LoggingOptions.ts +51 -0
- package/src/logging/contracts/index.ts +4 -0
- package/src/logging/drivers/PinoLoggerDriver.ts +376 -0
- package/src/logging/drivers/index.ts +1 -0
- package/src/logging/examples/runNoteLogs.ts +38 -0
- package/src/logging/index.ts +3 -0
- package/src/logging/transports/DevtoolsLogTransport.ts +142 -0
- package/src/mail/Mail.ts +188 -0
- package/src/mail/README.md +206 -0
- package/src/mail/examples/runMailPreview.ts +44 -0
- package/src/mail/examples/welcomeMessage.ts +26 -0
- package/src/mail/index.ts +4 -0
- package/src/mail/transports/FileMailTransport.ts +58 -0
- package/src/mail/transports/MailgunTransport.ts +85 -0
- package/src/mail/transports/ResendTransport.ts +80 -0
- package/src/media/MediaFile.ts +132 -0
- package/src/media/MediaItem.ts +132 -0
- package/src/media/MediaLibrary.ts +117 -0
- package/src/media/MediaManager.ts +874 -0
- package/src/media/README.md +358 -0
- package/src/media/constants.ts +31 -0
- package/src/media/contracts/MediaOptions.ts +9 -0
- package/src/media/contracts/index.ts +1 -0
- package/src/media/examples/createPrivateFileServer.ts +55 -0
- package/src/media/examples/runPrivateFiles.ts +45 -0
- package/src/media/examples/runProjectMedia.ts +46 -0
- package/src/media/image/ImageReconstructionError.ts +18 -0
- package/src/media/image/ImageVariantRenderer.ts +386 -0
- package/src/media/image/ImageVariantRequest.ts +65 -0
- package/src/media/image/contracts/ImageProcessor.ts +53 -0
- package/src/media/image/contracts/ImageVariant.ts +37 -0
- package/src/media/image/contracts/ImageVariantCacheOptions.ts +21 -0
- package/src/media/image/contracts/index.ts +3 -0
- package/src/media/image/index.ts +5 -0
- package/src/media/image/processors/SharpImageProcessor.ts +121 -0
- package/src/media/image/processors/index.ts +1 -0
- package/src/media/index.ts +8 -0
- package/src/media/types.ts +168 -0
- package/src/queue/FailedJob.ts +58 -0
- package/src/queue/Queue.ts +938 -0
- package/src/queue/QueueEvents.ts +57 -0
- package/src/queue/QueueRetryLaterError.ts +40 -0
- package/src/queue/QueueWorker.ts +296 -0
- package/src/queue/QueueableJob.ts +167 -0
- package/src/queue/QueuedJob.ts +69 -0
- package/src/queue/README.md +368 -0
- package/src/queue/RetryPolicy.ts +129 -0
- package/src/queue/commands/index.ts +13 -0
- package/src/queue/commands/makeJob.ts +11 -0
- package/src/queue/console.ts +518 -0
- package/src/queue/contracts/CreateJob.ts +13 -0
- package/src/queue/contracts/QueueDriver.ts +135 -0
- package/src/queue/contracts/QueueEvents.ts +77 -0
- package/src/queue/contracts/QueuePayload.ts +150 -0
- package/src/queue/contracts/QueueRetry.ts +47 -0
- package/src/queue/contracts/QueueService.ts +219 -0
- package/src/queue/contracts/QueueWorkerLifecycle.ts +71 -0
- package/src/queue/contracts/QueueableJob.ts +56 -0
- package/src/queue/contracts/RedisQueueDriver.ts +37 -0
- package/src/queue/contracts/index.ts +9 -0
- package/src/queue/createJob.ts +54 -0
- package/src/queue/drivers/DatabaseQueueDriver.ts +449 -0
- package/src/queue/drivers/RedisQueueDriver.ts +733 -0
- package/src/queue/examples/DeferredReportJob.ts +25 -0
- package/src/queue/examples/GenerateReportJob.ts +37 -0
- package/src/queue/examples/WriteReportJob.ts +37 -0
- package/src/queue/examples/createAndProcessReportJob.ts +29 -0
- package/src/queue/examples/dispatchReportWorkflows.ts +40 -0
- package/src/queue/examples/manageReportRetries.ts +47 -0
- package/src/queue/examples/outputs/create-and-process-report-job.json +6 -0
- package/src/queue/examples/outputs/dispatch-report-workflows.json +14 -0
- package/src/queue/examples/outputs/manage-report-retries.json +24 -0
- package/src/queue/examples/outputs/queue-reports.json +11 -0
- package/src/queue/examples/reportConsole.ts +47 -0
- package/src/queue/examples/runBackpressure.ts +27 -0
- package/src/queue/examples/runQueueReports.ts +80 -0
- package/src/queue/examples/runQueueWorkflows.ts +43 -0
- package/src/queue/index.ts +13 -0
- package/src/queue/queueMonitor.ts +368 -0
- package/src/scheduler/README.md +139 -0
- package/src/scheduler/ScheduledCall.ts +36 -0
- package/src/scheduler/ScheduledEvent.ts +149 -0
- package/src/scheduler/ScheduledJob.ts +58 -0
- package/src/scheduler/ScheduledOccurrence.ts +250 -0
- package/src/scheduler/ScheduledOccurrenceRecorder.ts +125 -0
- package/src/scheduler/Scheduler.ts +225 -0
- package/src/scheduler/SchedulerWorker.ts +151 -0
- package/src/scheduler/console.ts +368 -0
- package/src/scheduler/constants.ts +27 -0
- package/src/scheduler/contracts/Scheduler.ts +123 -0
- package/src/scheduler/contracts/SchedulerConsole.ts +40 -0
- package/src/scheduler/contracts/SchedulerWorker.ts +23 -0
- package/src/scheduler/contracts/index.ts +3 -0
- package/src/scheduler/examples/RecoverableSummaryJob.ts +18 -0
- package/src/scheduler/examples/WriteDailySummaryJob.ts +17 -0
- package/src/scheduler/examples/registerDailySummary.ts +13 -0
- package/src/scheduler/examples/runDailySummary.ts +46 -0
- package/src/scheduler/examples/runScheduledReplay.ts +60 -0
- package/src/scheduler/index.ts +9 -0
- package/src/scheduler/scheduleTime.ts +78 -0
- package/src/security/README.md +130 -0
- package/src/security/Security.ts +346 -0
- package/src/security/SecurityError.ts +16 -0
- package/src/security/contracts/SecurityOptions.ts +20 -0
- package/src/security/contracts/SecurityPayload.ts +14 -0
- package/src/security/contracts/index.ts +2 -0
- package/src/security/ensureAppKey.ts +82 -0
- package/src/security/examples/runSecretRoundTrip.ts +42 -0
- package/src/security/index.ts +4 -0
- package/src/serialization/README.md +169 -0
- package/src/serialization/Serializable.ts +17 -0
- package/src/serialization/SerializationError.ts +91 -0
- package/src/serialization/SerializationRegistry.ts +208 -0
- package/src/serialization/SerializationRegistryError.ts +24 -0
- package/src/serialization/Serializer.ts +793 -0
- package/src/serialization/contracts/SerializableClass.ts +26 -0
- package/src/serialization/contracts/SerializedValue.ts +71 -0
- package/src/serialization/contracts/SerializerOptions.ts +19 -0
- package/src/serialization/contracts/SerializerService.ts +29 -0
- package/src/serialization/contracts/index.ts +4 -0
- package/src/serialization/examples/ExportRequest.ts +25 -0
- package/src/serialization/examples/runExportSerialization.ts +24 -0
- package/src/serialization/index.ts +6 -0
- package/src/server/App.ts +326 -0
- package/src/server/README.md +219 -0
- package/src/server/RequestContext.ts +122 -0
- package/src/server/appContext.ts +59 -0
- package/src/server/examples/createFirstServer.ts +25 -0
- package/src/server/examples/startFirstServer.ts +19 -0
- package/src/server/index.ts +16 -0
- package/src/ssr/README.md +158 -0
- package/src/ssr/constants.ts +8 -0
- package/src/ssr/contracts/DocumentHead.ts +35 -0
- package/src/ssr/contracts/SsrRenderContext.ts +25 -0
- package/src/ssr/contracts/SsrRenderResult.ts +23 -0
- package/src/ssr/contracts/SsrRenderer.ts +12 -0
- package/src/ssr/contracts/SsrRequest.ts +17 -0
- package/src/ssr/contracts/index.ts +19 -0
- package/src/ssr/createSsrRenderContext.ts +25 -0
- package/src/ssr/examples/createPublicPageServer.ts +32 -0
- package/src/ssr/examples/runPublicPages.ts +25 -0
- package/src/ssr/fastify/contracts/FastifySsrOptions.ts +24 -0
- package/src/ssr/fastify/contracts/index.ts +5 -0
- package/src/ssr/fastify/fastifySsr.ts +110 -0
- package/src/ssr/fastify/index.ts +2 -0
- package/src/ssr/index.ts +10 -0
- package/src/ssr/renderDocumentHead.ts +72 -0
- package/src/ssr/renderSsrDocument.ts +35 -0
- package/src/ssr/serializeSsrState.ts +19 -0
- package/src/ssr/vite/contracts/ViteSsrOptions.ts +52 -0
- package/src/ssr/vite/contracts/index.ts +6 -0
- package/src/ssr/vite/fastifyViteSsr.ts +279 -0
- package/src/ssr/vite/index.ts +4 -0
- package/src/ssr/vite/viteSsrManifest.ts +92 -0
- package/src/storage/README.md +310 -0
- package/src/storage/Storage.ts +392 -0
- package/src/storage/contents.ts +23 -0
- package/src/storage/contracts/StorageListing.ts +55 -0
- package/src/storage/contracts/index.ts +1 -0
- package/src/storage/drivers/FlystorageDisk.ts +295 -0
- package/src/storage/drivers/FlystorageListing.ts +78 -0
- package/src/storage/drivers/LocalStorageDisk.ts +45 -0
- package/src/storage/drivers/S3StorageDisk.ts +114 -0
- package/src/storage/drivers/index.ts +3 -0
- package/src/storage/examples/runStorage.ts +37 -0
- package/src/storage/examples/runStreamExport.ts +41 -0
- package/src/storage/examples/writeCsvExport.ts +45 -0
- package/src/storage/index.ts +7 -0
- package/src/storage/mime.ts +30 -0
- package/src/storage/path.ts +76 -0
- package/src/storage/types.ts +251 -0
- package/src/url/README.md +41 -0
- package/src/url/UrlGenerator.ts +72 -0
- package/src/url/contracts/UrlGeneratorOptions.ts +14 -0
- package/src/url/contracts/index.ts +1 -0
- package/src/url/examples/runApplicationLinks.ts +33 -0
- package/src/url/index.ts +2 -0
- package/src/validation/README.md +433 -0
- package/src/validation/examples/runNoteValidation.ts +18 -0
- package/src/validation/examples/validateNoteInput.ts +31 -0
- package/src/validation/index.ts +398 -0
- package/templates/AGENTS.md +15 -0
package/src/db/README.md
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
# ActiveRecord + FieldType
|
|
2
|
+
|
|
3
|
+
This DB layer is a FieldType-centred ActiveRecord system. A model field is not
|
|
4
|
+
only a database-column description; it owns the lifecycle of one logical value
|
|
5
|
+
as it moves between request/input data, app memory, storage, and display/API
|
|
6
|
+
data.
|
|
7
|
+
|
|
8
|
+
## Define an inferred model
|
|
9
|
+
|
|
10
|
+
Use `ActiveRecord.define()` to declare fields once and infer model properties
|
|
11
|
+
and constructor/`create()` inputs. Extend the returned class with ordinary
|
|
12
|
+
instance and static methods. The [user example](examples/DefinedUser.ts) is a
|
|
13
|
+
complete model with an inferred email property and a domain method.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { ActiveRecord } from '@db3.ai/app/db';
|
|
17
|
+
|
|
18
|
+
class User extends ActiveRecord.define({
|
|
19
|
+
table: 'users',
|
|
20
|
+
fields: field => ({
|
|
21
|
+
id: field.ulid({ primary: true }),
|
|
22
|
+
email: field.email({ required: true }),
|
|
23
|
+
}),
|
|
24
|
+
}) {}
|
|
25
|
+
|
|
26
|
+
const user = User.create({ email: ' USER@EXAMPLE.COM ' });
|
|
27
|
+
// user.email is string | null, with the value 'user@example.com'.
|
|
28
|
+
// create() returns immediately; the row is not saved yet.
|
|
29
|
+
await user.save();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Configure the active application and table before saving, as described below.
|
|
33
|
+
`define()` itself performs no database work and does not generate migrations.
|
|
34
|
+
|
|
35
|
+
`class Admin extends User { ... }` retains inferred fields. `User.define({
|
|
36
|
+
fields: field => ({ ... }) })` adds another layer, including all inherited
|
|
37
|
+
fields. The normal `create()`, query, lookup, hydration and `useDb()` statics
|
|
38
|
+
retain their actual receiver type, including methods added by later subclasses.
|
|
39
|
+
|
|
40
|
+
A matching field name replaces the entire inherited definition, so repeat any
|
|
41
|
+
configuration you still need. TypeScript requires overrides to preserve the
|
|
42
|
+
application and input value types, protecting methods inherited from the base.
|
|
43
|
+
Fields cannot replace existing non-field public instance members. Other settings
|
|
44
|
+
inherit unless supplied, including table, primary key, request guards and soft
|
|
45
|
+
deletes. Define a new root model if a field needs a different value type.
|
|
46
|
+
|
|
47
|
+
Factories use the existing builder and accept field instances, field classes,
|
|
48
|
+
and `{ type, config }` definitions. Field metadata is resolved per model; each
|
|
49
|
+
record clones and binds its own live fields. Cloneable literal defaults, such
|
|
50
|
+
as JSON objects and arrays, are copied for each record. Use default factories
|
|
51
|
+
for custom objects that cannot be copied safely. Values explicitly assigned by
|
|
52
|
+
reference retain the existing field's parsing and reference semantics.
|
|
53
|
+
|
|
54
|
+
Properties describe application values. `required: true` is a runtime validation
|
|
55
|
+
rule and does not remove `null` from a field's TypeScript value. Inputs use the
|
|
56
|
+
field's existing `TInput`: many built-in fields intentionally accept `unknown`.
|
|
57
|
+
For example, password properties read as `null`; provide plaintext through
|
|
58
|
+
`create({ password })`, the constructor, or `assign({ password })`. Property
|
|
59
|
+
writes use the same field setter at runtime, but TypeScript checks them against
|
|
60
|
+
the application value type. `assign()` and request filling retain their existing
|
|
61
|
+
dynamic input behavior. JSON generics do not validate nested input shapes.
|
|
62
|
+
|
|
63
|
+
`ActiveRecord.InferInput<typeof User>`, `InferValue`, `InferDbRow` and
|
|
64
|
+
`InferDisplay` work with the complete composed field map. Constructor and
|
|
65
|
+
`create()` input fields are optional because records may be filled before
|
|
66
|
+
validation or saving. Unknown keys in object literals are rejected by these
|
|
67
|
+
typed constructors; runtime request filling still follows the existing policy.
|
|
68
|
+
The concrete field map remains available through `typeof User.fields`.
|
|
69
|
+
|
|
70
|
+
Existing `class User extends ActiveRecord` declarations remain supported, and
|
|
71
|
+
can be extended with `define()`. Their static `fields()` overrides keep their
|
|
72
|
+
existing behavior: use `...super.fields(field)` to include parent definitions.
|
|
73
|
+
Dynamic field maps retain runtime behavior but cannot infer names unknown to
|
|
74
|
+
TypeScript. The typed instance `getField()` API is not part of this change;
|
|
75
|
+
`getBoundField(name)` continues to return the existing live field.
|
|
76
|
+
|
|
77
|
+
## Start With Workspace Notes
|
|
78
|
+
|
|
79
|
+
The [note model](examples/KnowledgeNote.ts),
|
|
80
|
+
[scoped operations](examples/workspaceNotes.ts), and
|
|
81
|
+
[transaction example](examples/createNotesTogether.ts) show the normal workflow:
|
|
82
|
+
define fields, fill permitted request values, assign trusted ownership, save,
|
|
83
|
+
query, update and delete. `Model.create()` returns an unsaved record; call
|
|
84
|
+
`save()` to persist it.
|
|
85
|
+
|
|
86
|
+
The [executable lab](examples/runWorkspaceNotes.ts) creates a disposable database,
|
|
87
|
+
asserts workspace scoping, validates input, checks rollback and removes its
|
|
88
|
+
database afterwards. Copy all four files into one directory, configure a TCP
|
|
89
|
+
MariaDB/MySQL test account with CREATE/DROP DATABASE permission, and run the lab
|
|
90
|
+
with `tsx`. The [expected result](examples/outputs/workspace-notes.json) is also
|
|
91
|
+
asserted by the service-owned example tests. The db3.ai workspace notes guide
|
|
92
|
+
provides the full package-install and environment commands.
|
|
93
|
+
|
|
94
|
+
The lab uses `Database.install()` only to bootstrap its disposable schema. Real
|
|
95
|
+
applications use committed migrations. The workspace argument must already be
|
|
96
|
+
authorized by the host application; a fillable list is not authentication.
|
|
97
|
+
|
|
98
|
+
## Run fields and migration changes
|
|
99
|
+
|
|
100
|
+
After [Installation](https://db3.ai/docs/installation) and local MariaDB test-account setup, copy the shipped SQL labs into your app:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
mkdir -p examples
|
|
104
|
+
cp -R node_modules/@db3.ai/app/src/db/examples/. examples/
|
|
105
|
+
npx tsx examples/runFieldNotes.ts
|
|
106
|
+
npx tsx examples/runNoteMigrations.ts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Use Node.js 24, MariaDB and credentials allowed to create/drop generated `db3_app_test_*` databases. `DATABASE_URL` takes precedence over individual `DB_*` values; unset it when targeting a different test server. Each lab owns and cleans up a new database. The migration lab also owns a temporary source directory. Neither modifies your existing app schema or key.
|
|
110
|
+
|
|
111
|
+
The [Fields walkthrough](https://db3.ai/docs/fields) demonstrates a reusable uppercase code field, normalized tags, nested JSON, ownership protection and hidden encrypted storage. Expect `BRIEF-1`, `["SEO", "Agency"]` and true protection flags. JSON generics describe types but do not validate nested shapes.
|
|
112
|
+
|
|
113
|
+
The [Migrations walkthrough](https://db3.ai/docs/migrations) creates a note, refuses an unsafe required column without changing source, then applies a nullable replacement and checks the original data remains. This is the tested foundation for a real app's make/review/migrate/check workflow, not boot-time schema synchronization.
|
|
114
|
+
|
|
115
|
+
`databaseCommands` from `@db3.ai/app/db/commands` registers `db:migrate`,
|
|
116
|
+
`db:check` and `db:make-migration` through the shared [framework CLI](../cli/README.md).
|
|
117
|
+
Each action has its own file under `db/commands/` and uses `app().db.migrations`.
|
|
118
|
+
Supply only the model registry with `dbOptions: { migrations: { models } }`.
|
|
119
|
+
The database service uses `server/database/migrations/` and
|
|
120
|
+
`server/database/schema.snapshot.json` under `app().directory`, supplies the
|
|
121
|
+
connection and dialect, and lazily creates the manager. No app-owned
|
|
122
|
+
`migrations.ts` configuration file or migration path settings are needed.
|
|
123
|
+
Register the command array in `server/cli.config.ts`.
|
|
124
|
+
|
|
125
|
+
The app directory defaults to the working directory when `new App()` runs.
|
|
126
|
+
The starter anchors it with `directory: new URL('../', import.meta.url)` in
|
|
127
|
+
`server/app.ts`, so importing the app from elsewhere still uses its own files.
|
|
128
|
+
The low-level `DatabaseMigrationManager` retains explicit paths for standalone
|
|
129
|
+
tooling and disposable migration labs; app service paths follow the convention.
|
|
130
|
+
|
|
131
|
+
The exported `migrate()`, `check()` and `makeMigration(options)` functions return
|
|
132
|
+
ordinary results for application or authorized UI handlers in an existing app
|
|
133
|
+
context. Commands retain the manager's validation, production restrictions and
|
|
134
|
+
source-generation rules. The CLI owns startup and shutdown; direct action
|
|
135
|
+
callers retain ownership of their app. App migration files and model registries live
|
|
136
|
+
under `server/database/`.
|
|
137
|
+
|
|
138
|
+
Copy the exact website tests to `tests/db/runFieldNotes.test.ts` and `tests/db/runNoteMigrations.test.ts`, then run:
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
npx vitest run tests/db/runFieldNotes.test.ts tests/db/runNoteMigrations.test.ts
|
|
142
|
+
npx tsc --noEmit --target ES2022 --module ESNext --moduleResolution Bundler --types node --skipLibCheck examples/*.ts
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Full references: [Fields](https://db3.ai/docs/fields-api), [record/query APIs](https://db3.ai/docs/active-record-api), and [migration contracts](https://db3.ai/docs/migrations-api). [Transactions](https://db3.ai/docs/cookbook-transactions) and [encrypted model values](https://db3.ai/docs/cookbook-secrets) reuse these same models and tests.
|
|
146
|
+
|
|
147
|
+
## Database Connections
|
|
148
|
+
|
|
149
|
+
The database environment helper reads the driver from loaded process settings; the Config service does not automatically reconfigure a connection. Use `DB_CONNECTION` with `mysql`, `mysql2`, or
|
|
150
|
+
`mariadb`. Both MySQL and MariaDB currently use Knex's `mysql2` client; the
|
|
151
|
+
dialect decides driver-specific schema and value conversion.
|
|
152
|
+
|
|
153
|
+
```env
|
|
154
|
+
DB_CONNECTION=mariadb
|
|
155
|
+
DB_HOST=127.0.0.1
|
|
156
|
+
DB_PORT=3306
|
|
157
|
+
DB_DATABASE=db3_app
|
|
158
|
+
DB_USER=root
|
|
159
|
+
DB_PASSWORD=
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Postgres names (`postgres`, `pgsql`, `pg`) are reserved in the dialect resolver,
|
|
163
|
+
but require the `pg` dependency and pgvector-specific verification before being
|
|
164
|
+
used in production.
|
|
165
|
+
|
|
166
|
+
## Generated Database Migrations
|
|
167
|
+
|
|
168
|
+
`DatabaseMigrationManager` turns an application's complete ActiveRecord model
|
|
169
|
+
registry into permanent Knex migrations. The application supplies absolute
|
|
170
|
+
paths for its migration directory and committed schema snapshot, plus its own
|
|
171
|
+
migration-ledger table name. CLI commands, development HTTP actions, and deploy
|
|
172
|
+
automation should be thin adapters around that one configured manager.
|
|
173
|
+
|
|
174
|
+
The intended command contract is:
|
|
175
|
+
|
|
176
|
+
- `db:make-migration` compares current models with the committed snapshot,
|
|
177
|
+
writes one reviewable Knex migration for supported changes, and advances the
|
|
178
|
+
snapshot. Nullable columns, required columns with static defaults, ordinary
|
|
179
|
+
non-unique indexes, and static default changes are generated automatically.
|
|
180
|
+
Required columns without defaults and constraints that depend on existing
|
|
181
|
+
data remain blocked for an explicit data-aware migration.
|
|
182
|
+
- `db:migrate` applies pending committed migration files through Knex's ledger
|
|
183
|
+
and migration lock. It does not inspect models or generate source files.
|
|
184
|
+
- `db:check` requires models to match the committed snapshot, no migration
|
|
185
|
+
files to be pending or missing, and the live model-owned database subset to
|
|
186
|
+
satisfy current models. Extra tables and columns and database comments are
|
|
187
|
+
ignored so additive blue/green deployments and comment-only legacy differences
|
|
188
|
+
remain compatible. Physical index names and definitions must still match the
|
|
189
|
+
canonical snapshot so future migrations can address them safely.
|
|
190
|
+
- `db:sync` is a development convenience that runs make, migrate, and check
|
|
191
|
+
through the same service.
|
|
192
|
+
|
|
193
|
+
Generation is protected by a cross-process source lock and is refused in
|
|
194
|
+
production. A blocked or unsupported model difference is reported for explicit
|
|
195
|
+
review rather than being silently emitted. Generated migrations and the schema
|
|
196
|
+
snapshot are source-controlled deployment inputs; production applies them but
|
|
197
|
+
never creates or rewrites them.
|
|
198
|
+
|
|
199
|
+
Never edit a migration after it may have been applied. The Knex ledger records
|
|
200
|
+
filenames, so changing an applied file cannot run the new DDL; restore the frozen
|
|
201
|
+
file and add a new forward migration instead.
|
|
202
|
+
|
|
203
|
+
When a baseline-enabled migrate or development sync adopts the sole initial
|
|
204
|
+
migration, it may baseline an existing untracked database only when its
|
|
205
|
+
model-owned schema is runtime-compatible with the initial snapshot. Comments do
|
|
206
|
+
not block adoption, but missing, renamed, or incompatible tables, columns,
|
|
207
|
+
indexes, and foreign keys do. A partial or incompatible database fails instead
|
|
208
|
+
of recording a migration that did not actually run.
|
|
209
|
+
|
|
210
|
+
Committed snapshots and generated migrations still retain canonical comments.
|
|
211
|
+
The comment tolerance applies only when projecting a live database for
|
|
212
|
+
compatibility checks and initial baselining; it does not remove metadata from
|
|
213
|
+
migration generation or source-controlled schema history.
|
|
214
|
+
|
|
215
|
+
Normal API, worker, and scheduler startup must not perform schema work. This
|
|
216
|
+
keeps startup deterministic and prevents application replicas from racing to
|
|
217
|
+
modify the database. `Database.install(...)` remains a low-level, non-versioned
|
|
218
|
+
bootstrap utility for framework tests and disposable databases; it is not an
|
|
219
|
+
application deployment strategy or a substitute for committed migrations.
|
|
220
|
+
|
|
221
|
+
## Application Backups
|
|
222
|
+
|
|
223
|
+
Applications can attach their own dump and storage policy to the database
|
|
224
|
+
service, then invoke it through the same active app shape used by other database
|
|
225
|
+
work:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
app().db.setBackupHandler(request => databaseBackup.create(request));
|
|
229
|
+
|
|
230
|
+
const manifest = await app().db.backup<DatabaseBackupManifest>({
|
|
231
|
+
backupId,
|
|
232
|
+
createdAt,
|
|
233
|
+
trigger: 'manual',
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The framework deliberately owns only the `backup()` invocation seam. The
|
|
238
|
+
application remains responsible for selecting a logical or physical dump,
|
|
239
|
+
storage destinations, retention, locking, and restore verification. Calling
|
|
240
|
+
`backup()` without an application-provided handler fails explicitly.
|
|
241
|
+
|
|
242
|
+
## Field Lifecycle Types
|
|
243
|
+
|
|
244
|
+
Every `FieldType` uses this generic shape:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
FieldType<TValue, TDbValue = TValue, TDisplayValue = TValue, TInput = TValue>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
- `TInput`: values `setValue()` can accept. This is the boundary for app code
|
|
251
|
+
and request filling.
|
|
252
|
+
- `TValue`: hydrated backend/app value used by model properties.
|
|
253
|
+
- `TDbValue`: raw storage value read from or written to the database.
|
|
254
|
+
- `TDisplayValue`: value returned for frontend forms, API transport, and JSON.
|
|
255
|
+
|
|
256
|
+
The standard lifecycle methods are:
|
|
257
|
+
|
|
258
|
+
- `setValue(input)` converts `TInput` into `TValue`.
|
|
259
|
+
- `setFromDb(dbValue)` converts `TDbValue` storage into `TValue`.
|
|
260
|
+
- `toDbValue(value)` converts `TValue` into storage.
|
|
261
|
+
- `toDisplayValue(value)` converts `TValue` into frontend/API-safe data.
|
|
262
|
+
|
|
263
|
+
`toJSON()` is a transport alias for display data. Use `toAppData()` when code
|
|
264
|
+
wants hydrated backend values.
|
|
265
|
+
|
|
266
|
+
## Request Filling
|
|
267
|
+
|
|
268
|
+
Fields do not own request keys. The model/request boundary owns how a specific
|
|
269
|
+
payload maps into logical model keys.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
class Website extends ActiveRecord {
|
|
273
|
+
static override requestGuarded = ['user'];
|
|
274
|
+
|
|
275
|
+
static readonly onboardingRequestMap = {
|
|
276
|
+
website: 'url',
|
|
277
|
+
business: 'businessName',
|
|
278
|
+
audiencePhrases: 'targetAudiencePhrases',
|
|
279
|
+
competitors: 'competitorWebsites',
|
|
280
|
+
} satisfies ActiveRecordRequestMap;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const website = new Website();
|
|
284
|
+
|
|
285
|
+
website.setFromRequestWithMap(request.body, Website.onboardingRequestMap);
|
|
286
|
+
website.assign({ user: currentUser });
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Use:
|
|
290
|
+
|
|
291
|
+
- `assign(input)` for trusted app/internal values keyed by model field name.
|
|
292
|
+
- `setFromRequest(data)` for request/form values keyed by model field name.
|
|
293
|
+
- `setFromRequestWithMap(data, dataToFieldMap)` for endpoint-specific payload
|
|
294
|
+
keys.
|
|
295
|
+
|
|
296
|
+
Request filling skips primary and generated fields by default. It also respects
|
|
297
|
+
model-level `requestFillable` and `requestGuarded` settings. Protected fields
|
|
298
|
+
such as ownership links should stay guarded and be set from trusted app code.
|
|
299
|
+
|
|
300
|
+
## Validation
|
|
301
|
+
|
|
302
|
+
Validation is available outside models through `@db3.ai/app/validation`.
|
|
303
|
+
The full guide lives in
|
|
304
|
+
[`packages/app/src/validation/README.md`](../validation/README.md).
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
import { validate } from '@db3.ai/app/validation';
|
|
308
|
+
|
|
309
|
+
const result = validate(request.body, {
|
|
310
|
+
email: ['required', 'email'],
|
|
311
|
+
age: ['nullable', 'integer', 'min:18'],
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
if (!result.valid) {
|
|
315
|
+
return reply.status(422).send({ errors: result.errors.map(({ field, rule, message }) => ({ field, rule, message })) });
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Supported first-party rules include `required`, `nullable`, `string`, `number`,
|
|
320
|
+
`integer`, `boolean`, `email`, `url`, `array`, `object`, `min`, `max`,
|
|
321
|
+
`minLength`, `maxLength`, `in`, `regex`, `ulid`, and `uuid`.
|
|
322
|
+
|
|
323
|
+
Models can generate request-level validation rules from their fields:
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
const rules = Website.validationRules();
|
|
327
|
+
const result = validate(request.body, rules);
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Field validation still exists for record persistence (`record.validate()` and
|
|
331
|
+
`record.save()`), but request-level validation can now happen before a live
|
|
332
|
+
model is populated.
|
|
333
|
+
|
|
334
|
+
## Projections
|
|
335
|
+
|
|
336
|
+
Use `ActiveProjection` for joined or read-model shapes that are not one
|
|
337
|
+
persisted model row.
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
class ContentPlanItemProjection extends ActiveProjection {
|
|
341
|
+
static override fields(field: ProjectionFieldBuilder) {
|
|
342
|
+
return {
|
|
343
|
+
...field.fromModel(ContentPlanItem),
|
|
344
|
+
|
|
345
|
+
keywordSearchVolume: field.from(Keywords, 'searchVolume', {
|
|
346
|
+
alias: 'keyword_search_volume',
|
|
347
|
+
default: 0,
|
|
348
|
+
}),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
`field.from(Model, key)` reuses the source model field conversion. `alias` is
|
|
355
|
+
only needed when the query renames the source column; otherwise the source field
|
|
356
|
+
already knows its storage column.
|
|
357
|
+
|
|
358
|
+
Projection rows hydrate through fields and expose:
|
|
359
|
+
|
|
360
|
+
- `toAppData()` for hydrated backend values.
|
|
361
|
+
- `toDisplayData()` for frontend/API-safe values.
|
|
362
|
+
- `toJSON()` as a transport alias for `toDisplayData()`.
|
|
363
|
+
|
|
364
|
+
Keep the join query on the projection class when the projection represents a
|
|
365
|
+
specific app read shape.
|
|
366
|
+
|
|
367
|
+
## App Data
|
|
368
|
+
|
|
369
|
+
For ordinary model reads, prefer the field-aware ActiveRecord query API:
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
const keywords = await Keywords
|
|
373
|
+
.where('website', websiteId)
|
|
374
|
+
.orderBy('searchVolume', 'desc')
|
|
375
|
+
.all();
|
|
376
|
+
|
|
377
|
+
return keywords.map(keyword => keyword.toDisplayData());
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Use logical field names in these queries. The model field owns the mapping from
|
|
381
|
+
`website` to `website_id`, `searchVolume` to `search_volume`, and so on.
|
|
382
|
+
|
|
383
|
+
Avoid repeated route/model cleanup such as `stringValue()`, date conversion,
|
|
384
|
+
JSON parsing, array filtering, lowercasing, and URL normalisation when a field
|
|
385
|
+
already represents that lifecycle.
|
|
386
|
+
|
|
387
|
+
For bounded read models and frequently refreshed endpoints, use `select()` with
|
|
388
|
+
logical field names so the database returns only the columns the caller needs.
|
|
389
|
+
Use `count()` when only the number of matching records is required; it executes
|
|
390
|
+
the aggregate in the database without hydrating model rows.
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
const progress = await WebsitePage
|
|
394
|
+
.where('website', websiteId)
|
|
395
|
+
.select('analyzeStatus', 'analyzeData')
|
|
396
|
+
.all();
|
|
397
|
+
|
|
398
|
+
const keywordCount = await Keywords
|
|
399
|
+
.where('website', websiteId)
|
|
400
|
+
.count();
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## JSON Fields
|
|
404
|
+
|
|
405
|
+
Use `field.json<T>()` for permissive JSON storage. It accepts decoded values or
|
|
406
|
+
JSON strings, keeps the decoded value in app memory, and serialises the value
|
|
407
|
+
when writing to the database.
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
metadata: field.json<Record<string, unknown>>({
|
|
411
|
+
column: 'metadata',
|
|
412
|
+
})
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Use `field.encryptedJson<T>()` for JSON-compatible credentials and secrets that
|
|
416
|
+
the application must decrypt later. It stores versioned authenticated
|
|
417
|
+
ciphertext in a long text column, is always hidden from model JSON, and cannot
|
|
418
|
+
be queried directly. Encryption is provided by the active app's central
|
|
419
|
+
`app().security` service. Sensitive fields should normally opt out of default
|
|
420
|
+
selects and be loaded only by the server workflow that needs them.
|
|
421
|
+
|
|
422
|
+
```ts
|
|
423
|
+
blogIntegration: field.encryptedJson<BlogIntegration>({
|
|
424
|
+
column: 'blog_integration',
|
|
425
|
+
selectedByDefault: false,
|
|
426
|
+
})
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
See [../security/README.md](../security/README.md) for key configuration,
|
|
430
|
+
payload behavior, and operational requirements.
|
|
431
|
+
|
|
432
|
+
Specialised JSON fields should build on that lifecycle instead of reimplementing
|
|
433
|
+
schema and JSON conversion. `field.stringList()` stores a normalised string
|
|
434
|
+
array. `field.vector({ dimensions })` stores an embedding/vector as native
|
|
435
|
+
database vector storage while keeping a finite `number[]` in app memory. MySQL
|
|
436
|
+
writes native vector bytes, while MariaDB writes through `VEC_FromText(...)`.
|
|
437
|
+
On dialects with native vector-index support, required vector fields create a
|
|
438
|
+
vector index by default. Nullable vector fields are storage-only by default
|
|
439
|
+
because MariaDB vector indexes cannot include nullable columns. Vector fields
|
|
440
|
+
are omitted from normal ActiveRecord fetches; use
|
|
441
|
+
`Model.query().withField('embedding')` for specialist queries that need the raw
|
|
442
|
+
embedding value.
|
|
443
|
+
|
|
444
|
+
Use `whereVectorSimilarTo()` for dialect-aware nearest-neighbour style queries.
|
|
445
|
+
The query builder owns the SQL differences between MariaDB and PostgreSQL, while
|
|
446
|
+
the caller supplies the logical vector field and query vector.
|
|
447
|
+
|
|
448
|
+
```ts
|
|
449
|
+
const rows = await WebsiteEmbedding
|
|
450
|
+
.query()
|
|
451
|
+
.where('website', websiteId)
|
|
452
|
+
.whereVectorSimilarTo('embedding', queryVector, {
|
|
453
|
+
as: 'distance',
|
|
454
|
+
})
|
|
455
|
+
.limit(10)
|
|
456
|
+
.toKnex();
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
`field.jsonString<T>()` remains available for older model code and text-backed
|
|
460
|
+
JSON columns. Prefer `field.json<T>()` for new arbitrary JSON fields when no
|
|
461
|
+
more specific field exists.
|
|
462
|
+
|
|
463
|
+
## Soft Deletes
|
|
464
|
+
|
|
465
|
+
Models can opt into Laravel-style soft deletes with `static softDeletes = true`.
|
|
466
|
+
The conventional logical field is `deletedAt`; declare it as a timestamp field
|
|
467
|
+
so schema sync and model hydration stay field-aware.
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
class Post extends ActiveRecord {
|
|
471
|
+
static override softDeletes = true;
|
|
472
|
+
|
|
473
|
+
static override fields(field: FieldBuilder) {
|
|
474
|
+
return {
|
|
475
|
+
id: field.ulid(),
|
|
476
|
+
title: field.string({ required: true }),
|
|
477
|
+
deletedAt: field.timestamp({
|
|
478
|
+
column: 'deleted_at',
|
|
479
|
+
index: true,
|
|
480
|
+
}),
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
Default model queries exclude trashed rows. Use `withTrashed()` to include them,
|
|
487
|
+
`onlyTrashed()` to inspect deleted rows, `restore()` to clear `deletedAt`, and
|
|
488
|
+
`forceDelete()` when the row should be physically removed.
|
|
489
|
+
|
|
490
|
+
## Custom Fields
|
|
491
|
+
|
|
492
|
+
When writing a field, implement only the methods that differ from the base
|
|
493
|
+
class:
|
|
494
|
+
|
|
495
|
+
- `createState()` when the field needs custom state.
|
|
496
|
+
- `parse()` or `setValue()` for `TInput` to `TValue`.
|
|
497
|
+
- `fromDbValue()` for `TDbValue` to `TValue`.
|
|
498
|
+
- `toDbValue()` for `TValue` to `TDbValue`.
|
|
499
|
+
- `toDisplayValue()` or `getDisplayValue()` for `TValue` to `TDisplayValue`.
|
|
500
|
+
- `collectErrors()` or `validate()` for field-level validation.
|
|
501
|
+
- `getValidationRules()` for reusable request validation rules.
|
|
502
|
+
- `getDbSchema()` for install/sync/migration metadata.
|
|
503
|
+
- `getQueryValue()` when query values need conversion.
|
|
504
|
+
- UI helpers such as `defaultFormComponent()`.
|
|
505
|
+
|
|
506
|
+
Prefer normalising invalid input into a stable internal value and reporting
|
|
507
|
+
problems through validation errors. Throw from parsing only for programmer
|
|
508
|
+
errors or truly unrecoverable input.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { ActiveRecordClass } from './ActiveRecord';
|
|
2
|
+
import type {
|
|
3
|
+
DbWriteData,
|
|
4
|
+
FieldType,
|
|
5
|
+
} from './FieldType';
|
|
6
|
+
|
|
7
|
+
export type ActiveRecordSoftDeleteConfig = boolean | string;
|
|
8
|
+
|
|
9
|
+
export type ActiveRecordSoftDeleteScope = 'without' | 'with' | 'only';
|
|
10
|
+
|
|
11
|
+
export interface ActiveRecordSoftDeleteField {
|
|
12
|
+
fieldName: string;
|
|
13
|
+
field: FieldType<any, any, any, any, any>;
|
|
14
|
+
column: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const DEFAULT_SOFT_DELETE_FIELD = 'deletedAt';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns true when the model has soft deletes enabled.
|
|
21
|
+
*/
|
|
22
|
+
export function modelUsesSoftDeletes(Model: ActiveRecordClass): boolean {
|
|
23
|
+
return resolveSoftDeleteFieldName(Model) !== null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the configured soft-delete timestamp field for a model, when enabled.
|
|
28
|
+
*/
|
|
29
|
+
export function getSoftDeleteField(
|
|
30
|
+
Model: ActiveRecordClass,
|
|
31
|
+
): ActiveRecordSoftDeleteField | null {
|
|
32
|
+
const fieldName = resolveSoftDeleteFieldName(Model);
|
|
33
|
+
|
|
34
|
+
if (!fieldName) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const field = Model.getFields()[fieldName];
|
|
39
|
+
|
|
40
|
+
if (!field) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Model ${Model.name} enables soft deletes with field "${fieldName}", but that field is not defined.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
fieldName,
|
|
48
|
+
field,
|
|
49
|
+
column: field.column,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns the configured soft-delete field or throws when the model is not soft deletable.
|
|
55
|
+
*/
|
|
56
|
+
export function requireSoftDeleteField(
|
|
57
|
+
Model: ActiveRecordClass,
|
|
58
|
+
): ActiveRecordSoftDeleteField {
|
|
59
|
+
const softDeleteField = getSoftDeleteField(Model);
|
|
60
|
+
|
|
61
|
+
if (!softDeleteField) {
|
|
62
|
+
throw new Error(`Model ${Model.name} does not use soft deletes.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return softDeleteField;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Builds field-aware update data for soft delete or restore operations.
|
|
70
|
+
*/
|
|
71
|
+
export function getSoftDeleteWriteData(
|
|
72
|
+
Model: ActiveRecordClass,
|
|
73
|
+
deletedAt: Date | null,
|
|
74
|
+
updatedAt = new Date(),
|
|
75
|
+
): DbWriteData {
|
|
76
|
+
const softDeleteField = requireSoftDeleteField(Model);
|
|
77
|
+
const ignoredFieldNames = new Set([softDeleteField.fieldName]);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
[softDeleteField.column]: softDeleteField.field.getQueryValue(deletedAt as any),
|
|
81
|
+
...getAutomaticUpdateTimestampWriteData(
|
|
82
|
+
Model,
|
|
83
|
+
updatedAt,
|
|
84
|
+
ignoredFieldNames,
|
|
85
|
+
),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns logical timestamp field names that should update on row updates.
|
|
91
|
+
*/
|
|
92
|
+
export function getAutomaticUpdateTimestampFieldNames(
|
|
93
|
+
Model: ActiveRecordClass,
|
|
94
|
+
ignoredFieldNames: ReadonlySet<string> = new Set(),
|
|
95
|
+
): string[] {
|
|
96
|
+
return Object.entries(Model.getFields())
|
|
97
|
+
.flatMap(([fieldName, field]) => {
|
|
98
|
+
if (ignoredFieldNames.has(fieldName)) return [];
|
|
99
|
+
if (!isAutomaticUpdateTimestampField(field)) return [];
|
|
100
|
+
|
|
101
|
+
return [fieldName];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Builds update timestamp columns for soft delete and restore writes.
|
|
107
|
+
*/
|
|
108
|
+
function getAutomaticUpdateTimestampWriteData(
|
|
109
|
+
Model: ActiveRecordClass,
|
|
110
|
+
updatedAt: Date,
|
|
111
|
+
ignoredFieldNames: ReadonlySet<string>,
|
|
112
|
+
): DbWriteData {
|
|
113
|
+
const row: DbWriteData = {};
|
|
114
|
+
|
|
115
|
+
for (const fieldName of getAutomaticUpdateTimestampFieldNames(Model, ignoredFieldNames)) {
|
|
116
|
+
const field = Model.getField(fieldName);
|
|
117
|
+
|
|
118
|
+
row[field.column] = field.getQueryValue(updatedAt as any);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return row;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Resolves the model's soft-delete config to a logical timestamp field name.
|
|
126
|
+
*/
|
|
127
|
+
function resolveSoftDeleteFieldName(Model: ActiveRecordClass): string | null {
|
|
128
|
+
const config = Model.softDeletes;
|
|
129
|
+
|
|
130
|
+
if (!config) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (config === true) {
|
|
135
|
+
return DEFAULT_SOFT_DELETE_FIELD;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (typeof config === 'string' && config.trim()) {
|
|
139
|
+
return config.trim();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
throw new Error(
|
|
143
|
+
`Model ${Model.name} has an invalid soft delete configuration.`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns true when a field should receive update timestamps automatically.
|
|
149
|
+
*/
|
|
150
|
+
function isAutomaticUpdateTimestampField(
|
|
151
|
+
field: FieldType<any, any, any, any, any>,
|
|
152
|
+
): boolean {
|
|
153
|
+
const config = field.config as {
|
|
154
|
+
auto?: unknown;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return config.auto === 'update' || config.auto === 'both';
|
|
158
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { app } from '../../server';
|
|
2
|
+
import type { DatabaseCheckResult } from '../migrations/contracts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks the active app's database, models, snapshot and migration history.
|
|
6
|
+
* @returns Consistency findings for CLI, application or authorized UI callers.
|
|
7
|
+
*/
|
|
8
|
+
export default async function check(): Promise<DatabaseCheckResult> {
|
|
9
|
+
return app().db.migrations.check();
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineCommand } from '../../cli';
|
|
2
|
+
import migrate from './migrate';
|
|
3
|
+
import check from './check';
|
|
4
|
+
import makeMigration from './makeMigration';
|
|
5
|
+
|
|
6
|
+
export { migrate, check, makeMigration };
|
|
7
|
+
|
|
8
|
+
/** Explicit service command index; action files remain directly importable programmatic operations. */
|
|
9
|
+
export const databaseCommands = [
|
|
10
|
+
defineCommand({ name: 'db:migrate', description: 'Apply committed pending database migrations.', handle: migrate }),
|
|
11
|
+
defineCommand({ name: 'db:check', description: 'Check model, snapshot and live database consistency.', handle: check, exitCode: result => result.matches ? 0 : 1 }),
|
|
12
|
+
defineCommand({
|
|
13
|
+
name: 'db:make-migration', description: 'Generate a migration and snapshot from model changes.',
|
|
14
|
+
parameters: [{ name: 'name' }],
|
|
15
|
+
/** Maps the CLI name to the action's normal options object. */
|
|
16
|
+
handle: parameters => makeMigration({ name: parameters.name }),
|
|
17
|
+
exitCode: result => result.blocked ? 1 : 0,
|
|
18
|
+
}),
|
|
19
|
+
];
|