@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
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
|
|
3
|
+
import { mimeTypeFromPath } from '../storage/mime';
|
|
4
|
+
import { normalizeStoragePath } from '../storage/path';
|
|
5
|
+
import type { Storage, StorageContents, StorageDisk, StorageVisibility } from '../storage';
|
|
6
|
+
import { MEDIA_FILE_VISIBILITY, MEDIA_ITEM_TYPE, MEDIA_LIBRARY_DEFAULT_KEY } from './constants';
|
|
7
|
+
import type { MediaOptions } from './contracts';
|
|
8
|
+
import { ImageReconstructionError, ImageVariantRenderer, SharpImageProcessor, type ImageProcessor, type ImageVariant, type ImageVariantOptions } from './image';
|
|
9
|
+
import { MediaFile } from './MediaFile';
|
|
10
|
+
import { MediaItem } from './MediaItem';
|
|
11
|
+
import { MediaLibrary } from './MediaLibrary';
|
|
12
|
+
import type { MediaAttachFileInput, MediaFolderInput, MediaLibraryInput, MediaLibraryScope, MediaStoreFileInput, MediaStoreFileStreamInput, MediaStoreReconstructedVisibleImageStreamInput, MediaStoredVisibleFile, MediaStoreVisibleFileInput, MediaStoreVisibleFileStreamInput } from './types';
|
|
13
|
+
|
|
14
|
+
type MediaFileWriter = (
|
|
15
|
+
disk: StorageDisk,
|
|
16
|
+
path: string,
|
|
17
|
+
mimeType: string,
|
|
18
|
+
visibility: StorageVisibility,
|
|
19
|
+
) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
const MEDIA_ITEM_NAME_CONFLICT_RETRIES = 10;
|
|
22
|
+
const RECONSTRUCTIBLE_IMAGE_MIME_TYPES = new Set([
|
|
23
|
+
'image/avif',
|
|
24
|
+
'image/gif',
|
|
25
|
+
'image/jpeg',
|
|
26
|
+
'image/png',
|
|
27
|
+
'image/webp',
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Framework service for managed media libraries, files, and browser items.
|
|
32
|
+
*
|
|
33
|
+
* Storage remains responsible for bytes. This manager records file metadata,
|
|
34
|
+
* scopes files through media libraries, and creates optional folder-tree rows
|
|
35
|
+
* for media browser UIs.
|
|
36
|
+
*/
|
|
37
|
+
export class MediaManager {
|
|
38
|
+
readonly #imageProcessor: ImageProcessor;
|
|
39
|
+
readonly #imageVariants: ImageVariantRenderer;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a media manager backed by the application storage service.
|
|
43
|
+
*
|
|
44
|
+
* @param storage - Storage manager used to write and read file bytes.
|
|
45
|
+
* @param options - Media rendering and derived-file cache configuration.
|
|
46
|
+
* @param imageProcessor - Concrete image processing engine.
|
|
47
|
+
*/
|
|
48
|
+
constructor(
|
|
49
|
+
private readonly storage: Storage,
|
|
50
|
+
options: MediaOptions = {},
|
|
51
|
+
imageProcessor: ImageProcessor = new SharpImageProcessor(),
|
|
52
|
+
) {
|
|
53
|
+
this.#imageProcessor = imageProcessor;
|
|
54
|
+
this.#imageVariants = new ImageVariantRenderer(storage, options.images, imageProcessor);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Finds or creates the media library for an application-owned scope.
|
|
59
|
+
*
|
|
60
|
+
* @param input - Scope identity and defaults for a new library.
|
|
61
|
+
* @returns Existing or newly-created media library.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const library = await app.media.libraryFor({
|
|
65
|
+
* scopeType: 'app.website',
|
|
66
|
+
* scopeId: website.id,
|
|
67
|
+
* key: 'default',
|
|
68
|
+
* name: 'Website media',
|
|
69
|
+
* });
|
|
70
|
+
*/
|
|
71
|
+
async libraryFor(input: MediaLibraryScope): Promise<MediaLibrary> {
|
|
72
|
+
const scopeType = requiredString(input.scopeType, 'Media library scopeType is required.');
|
|
73
|
+
const scopeId = requiredString(input.scopeId, 'Media library scopeId is required.');
|
|
74
|
+
const key = normalizeLibraryKey(input.key);
|
|
75
|
+
const existing = await MediaLibrary
|
|
76
|
+
.where({
|
|
77
|
+
scopeType,
|
|
78
|
+
scopeId,
|
|
79
|
+
key,
|
|
80
|
+
})
|
|
81
|
+
.first();
|
|
82
|
+
|
|
83
|
+
if (existing) return existing;
|
|
84
|
+
|
|
85
|
+
const library = MediaLibrary.create({
|
|
86
|
+
scopeType,
|
|
87
|
+
scopeId,
|
|
88
|
+
key,
|
|
89
|
+
name: input.name || defaultLibraryName(scopeType, key),
|
|
90
|
+
defaultDisk: input.defaultDisk ?? null,
|
|
91
|
+
pathPrefix: input.pathPrefix ?? null,
|
|
92
|
+
meta: input.meta ?? null,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
await library.save();
|
|
96
|
+
|
|
97
|
+
return library;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Loads one media library by id.
|
|
102
|
+
*
|
|
103
|
+
* @param id - Media library ULID.
|
|
104
|
+
* @returns Media library row or null.
|
|
105
|
+
*/
|
|
106
|
+
library(id: string): Promise<MediaLibrary | null> {
|
|
107
|
+
return MediaLibrary.find(id);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Loads one managed file by id.
|
|
112
|
+
*
|
|
113
|
+
* @param id - Managed file ULID.
|
|
114
|
+
* @returns Managed file row or null.
|
|
115
|
+
*/
|
|
116
|
+
file(id: string): Promise<MediaFile | null> {
|
|
117
|
+
return MediaFile.find(id);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Writes bytes to storage and records a managed file row.
|
|
122
|
+
*
|
|
123
|
+
* The file is not visible in the media browser until `attachFile()` creates a
|
|
124
|
+
* `MediaItem` that points to it.
|
|
125
|
+
*
|
|
126
|
+
* @param input - File contents, library, storage options, and metadata.
|
|
127
|
+
* @returns Managed file row.
|
|
128
|
+
*/
|
|
129
|
+
async storeFile(input: MediaStoreFileInput): Promise<MediaFile> {
|
|
130
|
+
return this.#storeFile(
|
|
131
|
+
input,
|
|
132
|
+
input.size ?? storageContentsByteLength(input.contents),
|
|
133
|
+
(disk, path, mimeType, visibility) => disk.put(path, input.contents, {
|
|
134
|
+
mimeType,
|
|
135
|
+
visibility,
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Streams bytes to storage and records a managed file row.
|
|
142
|
+
*
|
|
143
|
+
* This is the preferred media finalization path for resumable uploads because
|
|
144
|
+
* completed temporary files do not need to be buffered in application memory.
|
|
145
|
+
*
|
|
146
|
+
* @param input - File stream, library, storage options, and metadata.
|
|
147
|
+
* @returns Managed file row.
|
|
148
|
+
*/
|
|
149
|
+
async storeFileStream(input: MediaStoreFileStreamInput): Promise<MediaFile> {
|
|
150
|
+
return this.#storeFile(
|
|
151
|
+
input,
|
|
152
|
+
input.size ?? null,
|
|
153
|
+
(disk, path, mimeType, visibility) => disk.writeStream(path, input.stream, {
|
|
154
|
+
mimeType,
|
|
155
|
+
visibility,
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Reads managed file bytes from the storage disk recorded on the file row.
|
|
162
|
+
*
|
|
163
|
+
* @param fileOrId - Managed file row or id.
|
|
164
|
+
* @returns Stored file bytes.
|
|
165
|
+
*/
|
|
166
|
+
async readFile(fileOrId: MediaFile | string): Promise<Buffer> {
|
|
167
|
+
const file = await this.#resolveFile(fileOrId);
|
|
168
|
+
const diskName = requiredString(file.disk, 'Managed file disk is required.');
|
|
169
|
+
const path = requiredString(file.path, 'Managed file path is required.');
|
|
170
|
+
|
|
171
|
+
return this.storage.disk(diskName).get(path);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Opens a managed file as a storage-backed readable stream.
|
|
176
|
+
*
|
|
177
|
+
* @param fileOrId - Managed file row or ULID.
|
|
178
|
+
* @returns Stream containing the stored file bytes.
|
|
179
|
+
*/
|
|
180
|
+
async readFileStream(fileOrId: MediaFile | string): Promise<Readable> {
|
|
181
|
+
const file = await this.#resolveFile(fileOrId);
|
|
182
|
+
const diskName = requiredString(file.disk, 'Managed file disk is required.');
|
|
183
|
+
const path = requiredString(file.path, 'Managed file path is required.');
|
|
184
|
+
|
|
185
|
+
return this.storage.disk(diskName).readStream(path);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Renders a responsive managed image into the configured disposable cache.
|
|
190
|
+
*
|
|
191
|
+
* @param fileOrId - Managed image row or ULID.
|
|
192
|
+
* @param options - Requested responsive image dimensions.
|
|
193
|
+
* @returns Rendered image stream and cache metadata.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* const image = await app.media.renderImage(imageId, {
|
|
197
|
+
* width: 640,
|
|
198
|
+
* });
|
|
199
|
+
*/
|
|
200
|
+
async renderImage(fileOrId: MediaFile | string, options: ImageVariantOptions): Promise<ImageVariant> {
|
|
201
|
+
const file = await this.#resolveFile(fileOrId);
|
|
202
|
+
|
|
203
|
+
return this.#imageVariants.render(file, options);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Permanently deletes a managed file, its browser placements, and stored bytes.
|
|
208
|
+
*
|
|
209
|
+
* Browser item rows are removed through their database foreign key to the
|
|
210
|
+
* managed file. Disposable responsive-image variants are cleared before the
|
|
211
|
+
* durable source bytes and database record are removed.
|
|
212
|
+
*
|
|
213
|
+
* @param fileOrId - Managed file row or ULID to permanently delete.
|
|
214
|
+
*/
|
|
215
|
+
async deleteFile(fileOrId: MediaFile | string): Promise<void> {
|
|
216
|
+
const file = await this.#resolveFile(fileOrId);
|
|
217
|
+
const diskName = requiredString(file.disk, 'Managed file disk is required.');
|
|
218
|
+
const path = requiredString(file.path, 'Managed file path is required.');
|
|
219
|
+
|
|
220
|
+
await this.#imageVariants.deleteCachedVariants(file);
|
|
221
|
+
await this.storage.disk(diskName).delete(path);
|
|
222
|
+
await file.delete();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Finds or creates the root browser item for a library.
|
|
227
|
+
*
|
|
228
|
+
* @param libraryOrId - Media library row or id.
|
|
229
|
+
* @returns Root browser item for the library.
|
|
230
|
+
*/
|
|
231
|
+
async rootFor(libraryOrId: MediaLibraryInput): Promise<MediaItem> {
|
|
232
|
+
const library = await this.#resolveLibrary(libraryOrId);
|
|
233
|
+
const existing = await MediaItem
|
|
234
|
+
.where('library', library)
|
|
235
|
+
.where('type', MEDIA_ITEM_TYPE.root)
|
|
236
|
+
.first();
|
|
237
|
+
|
|
238
|
+
if (existing) return existing;
|
|
239
|
+
|
|
240
|
+
const root = MediaItem.create({
|
|
241
|
+
library,
|
|
242
|
+
type: MEDIA_ITEM_TYPE.root,
|
|
243
|
+
root: null,
|
|
244
|
+
parent: null,
|
|
245
|
+
file: null,
|
|
246
|
+
name: 'Root',
|
|
247
|
+
path: '/',
|
|
248
|
+
meta: null,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
await root.save();
|
|
252
|
+
|
|
253
|
+
return root;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Finds or creates a slash-prefixed browser folder path.
|
|
258
|
+
*
|
|
259
|
+
* @param input - Library and folder path to ensure.
|
|
260
|
+
* @returns Folder item for the requested path, or the root for `/`.
|
|
261
|
+
*/
|
|
262
|
+
async ensureFolder(input: MediaFolderInput): Promise<MediaItem> {
|
|
263
|
+
const library = await this.#resolveLibrary(input.library);
|
|
264
|
+
const path = normalizeMediaPath(input.path);
|
|
265
|
+
|
|
266
|
+
if (path === '/') return this.rootFor(library);
|
|
267
|
+
|
|
268
|
+
const existing = await MediaItem
|
|
269
|
+
.where({
|
|
270
|
+
library,
|
|
271
|
+
path,
|
|
272
|
+
})
|
|
273
|
+
.first();
|
|
274
|
+
|
|
275
|
+
if (existing) return existing;
|
|
276
|
+
|
|
277
|
+
const root = await this.rootFor(library);
|
|
278
|
+
const segments = pathSegments(path);
|
|
279
|
+
let parent = root;
|
|
280
|
+
let currentPath = '';
|
|
281
|
+
|
|
282
|
+
for (const segment of segments) {
|
|
283
|
+
currentPath = joinMediaPath(currentPath || '/', segment);
|
|
284
|
+
|
|
285
|
+
let folder = await MediaItem
|
|
286
|
+
.where({
|
|
287
|
+
library,
|
|
288
|
+
path: currentPath,
|
|
289
|
+
})
|
|
290
|
+
.first();
|
|
291
|
+
|
|
292
|
+
if (!folder) {
|
|
293
|
+
folder = MediaItem.create({
|
|
294
|
+
library,
|
|
295
|
+
type: MEDIA_ITEM_TYPE.directory,
|
|
296
|
+
root,
|
|
297
|
+
parent,
|
|
298
|
+
file: null,
|
|
299
|
+
name: segment,
|
|
300
|
+
path: currentPath,
|
|
301
|
+
meta: currentPath === path ? input.meta ?? null : null,
|
|
302
|
+
});
|
|
303
|
+
await folder.save();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
parent = folder;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return parent;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Places an existing managed file into the browser tree.
|
|
314
|
+
*
|
|
315
|
+
* @param input - File, target library, folder path, and optional item metadata.
|
|
316
|
+
* @returns Browser item pointing at the managed file.
|
|
317
|
+
*/
|
|
318
|
+
async attachFile(input: MediaAttachFileInput): Promise<MediaItem> {
|
|
319
|
+
const library = await this.#resolveLibrary(input.library);
|
|
320
|
+
const file = await this.#resolveFile(input.file);
|
|
321
|
+
const root = await this.rootFor(library);
|
|
322
|
+
const parent = await this.ensureFolder({
|
|
323
|
+
library,
|
|
324
|
+
path: input.folderPath || '/',
|
|
325
|
+
});
|
|
326
|
+
const requestedName = normalizeFileName(input.name || file.name, file.mimeType);
|
|
327
|
+
const existingItems = await MediaItem
|
|
328
|
+
.where({
|
|
329
|
+
library,
|
|
330
|
+
parent,
|
|
331
|
+
})
|
|
332
|
+
.all();
|
|
333
|
+
const existingPaths = new Set(existingItems.flatMap(item => item.path ? [item.path] : []));
|
|
334
|
+
let sequence = 1;
|
|
335
|
+
let conflictRetries = 0;
|
|
336
|
+
|
|
337
|
+
while (conflictRetries <= MEDIA_ITEM_NAME_CONFLICT_RETRIES) {
|
|
338
|
+
const name = numberedMediaItemName(requestedName, sequence);
|
|
339
|
+
const path = joinMediaPath(parent.path || '/', name);
|
|
340
|
+
|
|
341
|
+
sequence += 1;
|
|
342
|
+
|
|
343
|
+
if (existingPaths.has(path)) continue;
|
|
344
|
+
|
|
345
|
+
const item = MediaItem.create({
|
|
346
|
+
library,
|
|
347
|
+
type: MEDIA_ITEM_TYPE.file,
|
|
348
|
+
root,
|
|
349
|
+
parent,
|
|
350
|
+
file,
|
|
351
|
+
name,
|
|
352
|
+
path,
|
|
353
|
+
meta: input.meta ?? null,
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
await item.save();
|
|
358
|
+
return item;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
const uniqueConflict = isUniqueConstraintError(error);
|
|
361
|
+
|
|
362
|
+
if (!uniqueConflict && !isRetriableTransactionConflict(error)) throw error;
|
|
363
|
+
|
|
364
|
+
const conflictingItem = await MediaItem
|
|
365
|
+
.where({
|
|
366
|
+
library,
|
|
367
|
+
path,
|
|
368
|
+
})
|
|
369
|
+
.first();
|
|
370
|
+
|
|
371
|
+
if (uniqueConflict && !conflictingItem) throw error;
|
|
372
|
+
|
|
373
|
+
existingPaths.add(path);
|
|
374
|
+
conflictRetries += 1;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
throw new Error(`Unable to allocate a unique media item name for "${requestedName}".`);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Writes bytes to storage and creates a browser item for the file.
|
|
383
|
+
*
|
|
384
|
+
* @param input - File storage input plus optional browser placement.
|
|
385
|
+
* @returns Stored file and browser item rows.
|
|
386
|
+
*/
|
|
387
|
+
async storeVisibleFile(input: MediaStoreVisibleFileInput): Promise<MediaStoredVisibleFile> {
|
|
388
|
+
const library = await this.#resolveLibrary(input.library);
|
|
389
|
+
const file = await this.storeFile({
|
|
390
|
+
...input,
|
|
391
|
+
library,
|
|
392
|
+
});
|
|
393
|
+
const item = await this.attachFile({
|
|
394
|
+
library,
|
|
395
|
+
file,
|
|
396
|
+
folderPath: input.folderPath || '/',
|
|
397
|
+
name: input.itemName || file.name,
|
|
398
|
+
meta: input.itemMeta ?? null,
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
return {
|
|
402
|
+
library,
|
|
403
|
+
file,
|
|
404
|
+
item,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Streams bytes to storage and creates a browser item for the file.
|
|
410
|
+
*
|
|
411
|
+
* @param input - File stream and storage input plus optional browser placement.
|
|
412
|
+
* @returns Stored file and browser item rows.
|
|
413
|
+
*/
|
|
414
|
+
async storeVisibleFileStream(input: MediaStoreVisibleFileStreamInput): Promise<MediaStoredVisibleFile> {
|
|
415
|
+
const library = await this.#resolveLibrary(input.library);
|
|
416
|
+
const file = await this.storeFileStream({
|
|
417
|
+
...input,
|
|
418
|
+
library,
|
|
419
|
+
});
|
|
420
|
+
const item = await this.attachFile({
|
|
421
|
+
library,
|
|
422
|
+
file,
|
|
423
|
+
folderPath: input.folderPath || '/',
|
|
424
|
+
name: input.itemName || file.name,
|
|
425
|
+
meta: input.itemMeta ?? null,
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
library,
|
|
430
|
+
file,
|
|
431
|
+
item,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Fully decodes and reconstructs an untrusted image before durable storage.
|
|
437
|
+
*
|
|
438
|
+
* The processor emits new canonical bytes without source metadata or trailing
|
|
439
|
+
* payloads. No media row becomes visible unless the complete processor stream
|
|
440
|
+
* is successfully written.
|
|
441
|
+
*
|
|
442
|
+
* @param input - Untrusted image stream and browser placement metadata.
|
|
443
|
+
* @returns Stored reconstructed file and browser item rows.
|
|
444
|
+
*/
|
|
445
|
+
async storeReconstructedVisibleImageStream(
|
|
446
|
+
input: MediaStoreReconstructedVisibleImageStreamInput,
|
|
447
|
+
): Promise<MediaStoredVisibleFile> {
|
|
448
|
+
const mimeType = reconstructibleImageMimeType(input.mimeType);
|
|
449
|
+
const source = input.stream;
|
|
450
|
+
const reconstructed = this.#imageProcessor.reconstruct({
|
|
451
|
+
sourceMimeType: mimeType,
|
|
452
|
+
outputMimeType: mimeType,
|
|
453
|
+
});
|
|
454
|
+
let processorError: Error | null = null;
|
|
455
|
+
let sourceError: Error | null = null;
|
|
456
|
+
|
|
457
|
+
source.once('error', error => {
|
|
458
|
+
sourceError = asError(error);
|
|
459
|
+
reconstructed.destroy(sourceError);
|
|
460
|
+
});
|
|
461
|
+
reconstructed.once('error', error => {
|
|
462
|
+
processorError = asError(error);
|
|
463
|
+
});
|
|
464
|
+
source.pipe(reconstructed);
|
|
465
|
+
|
|
466
|
+
try {
|
|
467
|
+
return await this.storeVisibleFileStream({
|
|
468
|
+
...input,
|
|
469
|
+
mimeType,
|
|
470
|
+
size: null,
|
|
471
|
+
stream: reconstructed,
|
|
472
|
+
});
|
|
473
|
+
} catch (error) {
|
|
474
|
+
if (sourceError) throw sourceError;
|
|
475
|
+
|
|
476
|
+
if (processorError) {
|
|
477
|
+
throw new ImageReconstructionError(
|
|
478
|
+
'The image could not be completely decoded and reconstructed.',
|
|
479
|
+
{
|
|
480
|
+
cause: processorError,
|
|
481
|
+
},
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
throw error;
|
|
486
|
+
} finally {
|
|
487
|
+
source.unpipe(reconstructed);
|
|
488
|
+
source.destroy();
|
|
489
|
+
reconstructed.destroy();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Writes one managed file through the supplied storage operation.
|
|
495
|
+
*
|
|
496
|
+
* @param input - Shared managed-file metadata and storage options.
|
|
497
|
+
* @param size - Known byte size, or null when storage should measure it.
|
|
498
|
+
* @param write - Concrete buffered or streamed storage write.
|
|
499
|
+
* @returns Managed file row.
|
|
500
|
+
*/
|
|
501
|
+
async #storeFile(
|
|
502
|
+
input: Omit<MediaStoreFileInput, 'contents'>,
|
|
503
|
+
size: number | null,
|
|
504
|
+
write: MediaFileWriter,
|
|
505
|
+
): Promise<MediaFile> {
|
|
506
|
+
const library = await this.#resolveLibrary(input.library);
|
|
507
|
+
const mimeType = normalizeMimeType(input.mimeType, input.name);
|
|
508
|
+
const requestedName = normalizeOptionalFileName(input.name);
|
|
509
|
+
const diskName = input.disk || library.defaultDisk || this.storage.defaultDiskName;
|
|
510
|
+
const disk = this.storage.disk(diskName);
|
|
511
|
+
const file = MediaFile.create({
|
|
512
|
+
library,
|
|
513
|
+
disk: diskName,
|
|
514
|
+
path: 'pending',
|
|
515
|
+
name: 'pending',
|
|
516
|
+
mimeType,
|
|
517
|
+
size,
|
|
518
|
+
visibility: input.visibility ?? MEDIA_FILE_VISIBILITY.private,
|
|
519
|
+
source: input.source ?? null,
|
|
520
|
+
meta: input.meta ?? null,
|
|
521
|
+
});
|
|
522
|
+
const fileId = requiredString(file.id, 'Generated media file id is required.');
|
|
523
|
+
const name = requestedName || `${fileId}${extensionForMimeType(mimeType)}`;
|
|
524
|
+
const path = input.path
|
|
525
|
+
? normalizeStoragePath(input.path)
|
|
526
|
+
: defaultFilePath(library, fileId, name);
|
|
527
|
+
let wroteGeneratedPath = false;
|
|
528
|
+
|
|
529
|
+
file.name = name;
|
|
530
|
+
file.path = path;
|
|
531
|
+
|
|
532
|
+
try {
|
|
533
|
+
wroteGeneratedPath = !input.path;
|
|
534
|
+
await write(
|
|
535
|
+
disk,
|
|
536
|
+
path,
|
|
537
|
+
mimeType,
|
|
538
|
+
file.visibility as StorageVisibility,
|
|
539
|
+
);
|
|
540
|
+
|
|
541
|
+
if (file.size === null || file.size === undefined) {
|
|
542
|
+
file.size = await disk.size(path);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
await file.save();
|
|
546
|
+
} catch (error) {
|
|
547
|
+
if (wroteGeneratedPath) {
|
|
548
|
+
await deleteStoredFileQuietly(disk, path);
|
|
549
|
+
}
|
|
550
|
+
throw error;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
return file;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Resolves a library row from a row or id.
|
|
558
|
+
*
|
|
559
|
+
* @param libraryOrId - Media library row or id.
|
|
560
|
+
* @returns Resolved media library.
|
|
561
|
+
*/
|
|
562
|
+
async #resolveLibrary(libraryOrId: MediaLibraryInput): Promise<MediaLibrary> {
|
|
563
|
+
if (libraryOrId instanceof MediaLibrary) return libraryOrId;
|
|
564
|
+
|
|
565
|
+
const library = await MediaLibrary.find(libraryOrId);
|
|
566
|
+
|
|
567
|
+
if (!library) {
|
|
568
|
+
throw new Error(`Media library "${libraryOrId}" was not found.`);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return library;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Resolves a managed file row from a row or id.
|
|
576
|
+
*
|
|
577
|
+
* @param fileOrId - Managed file row or id.
|
|
578
|
+
* @returns Resolved managed file.
|
|
579
|
+
*/
|
|
580
|
+
async #resolveFile(fileOrId: MediaFile | string): Promise<MediaFile> {
|
|
581
|
+
if (fileOrId instanceof MediaFile) return fileOrId;
|
|
582
|
+
|
|
583
|
+
const file = await MediaFile.find(fileOrId);
|
|
584
|
+
|
|
585
|
+
if (!file) {
|
|
586
|
+
throw new Error(`Media file "${fileOrId}" was not found.`);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return file;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Creates the default display name for a new scoped library.
|
|
595
|
+
*
|
|
596
|
+
* @param scopeType - App-owned scope type.
|
|
597
|
+
* @param key - Scope-local library key.
|
|
598
|
+
* @returns Human-readable library name.
|
|
599
|
+
*/
|
|
600
|
+
function defaultLibraryName(scopeType: string, key: string): string {
|
|
601
|
+
return key === MEDIA_LIBRARY_DEFAULT_KEY
|
|
602
|
+
? `${scopeType} media`
|
|
603
|
+
: `${scopeType} ${key}`;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Normalizes a library key.
|
|
608
|
+
*
|
|
609
|
+
* @param key - Optional library key.
|
|
610
|
+
* @returns Non-empty library key.
|
|
611
|
+
*/
|
|
612
|
+
function normalizeLibraryKey(key: string | null | undefined): string {
|
|
613
|
+
return String(key || MEDIA_LIBRARY_DEFAULT_KEY).trim() || MEDIA_LIBRARY_DEFAULT_KEY;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Normalizes a MIME type, falling back to the filename extension.
|
|
618
|
+
*
|
|
619
|
+
* @param mimeType - Optional MIME type.
|
|
620
|
+
* @param name - Optional filename.
|
|
621
|
+
* @returns MIME type for storage and metadata.
|
|
622
|
+
*/
|
|
623
|
+
function normalizeMimeType(mimeType: string | null | undefined, name: string | null | undefined): string {
|
|
624
|
+
const value = String(mimeType || '').trim().toLowerCase();
|
|
625
|
+
|
|
626
|
+
if (value) return value;
|
|
627
|
+
if (name) return mimeTypeFromPath(name);
|
|
628
|
+
|
|
629
|
+
return 'application/octet-stream';
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Normalizes and validates a MIME type supported by canonical reconstruction.
|
|
634
|
+
*
|
|
635
|
+
* @param value - Source image MIME type supplied by the upload adapter.
|
|
636
|
+
* @returns Normalized reconstructible image MIME type.
|
|
637
|
+
*/
|
|
638
|
+
function reconstructibleImageMimeType(value: string): string {
|
|
639
|
+
const mimeType = String(value || '').trim().toLowerCase();
|
|
640
|
+
|
|
641
|
+
if (!RECONSTRUCTIBLE_IMAGE_MIME_TYPES.has(mimeType)) {
|
|
642
|
+
throw new ImageReconstructionError(
|
|
643
|
+
`Image MIME type "${mimeType || 'unknown'}" cannot be reconstructed.`,
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return mimeType;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Converts an unknown stream failure into a standard Error instance.
|
|
652
|
+
*
|
|
653
|
+
* @param value - Error-like value emitted by a Node stream.
|
|
654
|
+
* @returns Standard error preserving the available message.
|
|
655
|
+
*/
|
|
656
|
+
function asError(value: unknown): Error {
|
|
657
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Normalizes a filename and removes path separators.
|
|
662
|
+
*
|
|
663
|
+
* @param name - Optional requested filename.
|
|
664
|
+
* @param mimeType - MIME type used to choose a fallback extension.
|
|
665
|
+
* @returns Safe display filename.
|
|
666
|
+
*/
|
|
667
|
+
function normalizeFileName(name: string | null | undefined, mimeType: string | null | undefined): string {
|
|
668
|
+
const value = normalizeOptionalFileName(name);
|
|
669
|
+
|
|
670
|
+
if (value) return value;
|
|
671
|
+
|
|
672
|
+
return `file${extensionForMimeType(mimeType)}`;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Normalizes an optional filename and returns null when it is empty.
|
|
677
|
+
*
|
|
678
|
+
* @param name - Optional requested filename.
|
|
679
|
+
* @returns Safe display filename or null.
|
|
680
|
+
*/
|
|
681
|
+
function normalizeOptionalFileName(name: string | null | undefined): string | null {
|
|
682
|
+
const value = String(name || '').trim().replace(/[\\/]+/g, '-').replace(/\s+/g, ' ');
|
|
683
|
+
|
|
684
|
+
return value || null;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Adds a sequence number before a filename extension when required.
|
|
689
|
+
*
|
|
690
|
+
* @param requestedName - Normalized browser item name requested by the caller.
|
|
691
|
+
* @param sequence - One-based allocation sequence.
|
|
692
|
+
* @returns Original name for sequence one, otherwise a numbered variant.
|
|
693
|
+
*/
|
|
694
|
+
function numberedMediaItemName(requestedName: string, sequence: number): string {
|
|
695
|
+
if (sequence <= 1) return requestedName;
|
|
696
|
+
|
|
697
|
+
const extensionIndex = requestedName.lastIndexOf('.');
|
|
698
|
+
const hasExtension = extensionIndex > 0;
|
|
699
|
+
const stem = hasExtension ? requestedName.slice(0, extensionIndex) : requestedName;
|
|
700
|
+
const extension = hasExtension ? requestedName.slice(extensionIndex) : '';
|
|
701
|
+
const suffix = `-${sequence}`;
|
|
702
|
+
const maximumStemLength = Math.max(1, 255 - extension.length - suffix.length);
|
|
703
|
+
|
|
704
|
+
return `${stem.slice(0, maximumStemLength)}${suffix}${extension}`;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Builds a generated storage path for a managed file.
|
|
709
|
+
*
|
|
710
|
+
* @param library - Media library that owns the file.
|
|
711
|
+
* @param fileId - Generated managed file id.
|
|
712
|
+
* @param name - Safe file name.
|
|
713
|
+
* @returns Storage path relative to the chosen disk.
|
|
714
|
+
*/
|
|
715
|
+
function defaultFilePath(library: MediaLibrary, fileId: string, name: string): string {
|
|
716
|
+
const prefix = trimSlashes(library.pathPrefix || `media/${requiredString(library.id, 'Media library id is required.')}`);
|
|
717
|
+
|
|
718
|
+
return normalizeStoragePath(`${prefix}/${fileId}/${name}`);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Converts framework storage contents into a byte length.
|
|
723
|
+
*
|
|
724
|
+
* @param contents - Storage contents accepted by the storage service.
|
|
725
|
+
* @returns Byte length for the supplied contents.
|
|
726
|
+
*/
|
|
727
|
+
function storageContentsByteLength(contents: StorageContents): number {
|
|
728
|
+
if (typeof contents === 'string') return Buffer.byteLength(contents);
|
|
729
|
+
if (Buffer.isBuffer(contents)) return contents.length;
|
|
730
|
+
if (contents instanceof ArrayBuffer) return contents.byteLength;
|
|
731
|
+
|
|
732
|
+
return contents.byteLength;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Removes leading and trailing slashes from a storage path prefix.
|
|
737
|
+
*
|
|
738
|
+
* @param input - Path prefix.
|
|
739
|
+
* @returns Trimmed path prefix.
|
|
740
|
+
*/
|
|
741
|
+
function trimSlashes(input: string): string {
|
|
742
|
+
return input.replace(/^\/+|\/+$/g, '');
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Returns a conventional extension for common MIME types.
|
|
747
|
+
*
|
|
748
|
+
* @param mimeType - MIME type.
|
|
749
|
+
* @returns File extension including the dot.
|
|
750
|
+
*/
|
|
751
|
+
function extensionForMimeType(mimeType: string | null | undefined): string {
|
|
752
|
+
switch (mimeType) {
|
|
753
|
+
case 'image/png':
|
|
754
|
+
return '.png';
|
|
755
|
+
case 'image/jpeg':
|
|
756
|
+
return '.jpg';
|
|
757
|
+
case 'image/webp':
|
|
758
|
+
return '.webp';
|
|
759
|
+
case 'application/pdf':
|
|
760
|
+
return '.pdf';
|
|
761
|
+
case 'text/plain':
|
|
762
|
+
return '.txt';
|
|
763
|
+
default:
|
|
764
|
+
return '.bin';
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Normalizes a browser path into a slash-prefixed path.
|
|
770
|
+
*
|
|
771
|
+
* @param value - Browser path-like value.
|
|
772
|
+
* @returns Slash-prefixed browser path.
|
|
773
|
+
*/
|
|
774
|
+
function normalizeMediaPath(value: string): string {
|
|
775
|
+
const path = String(value || '/').trim();
|
|
776
|
+
const normalized = (path.startsWith('/') ? path : `/${path}`)
|
|
777
|
+
.replace(/\/+/g, '/')
|
|
778
|
+
.replace(/\/$/, '');
|
|
779
|
+
|
|
780
|
+
return normalized || '/';
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Joins a media parent path and child name.
|
|
785
|
+
*
|
|
786
|
+
* @param parentPath - Slash-prefixed parent path.
|
|
787
|
+
* @param name - Child display name.
|
|
788
|
+
* @returns Slash-prefixed child path.
|
|
789
|
+
*/
|
|
790
|
+
function joinMediaPath(parentPath: string, name: string): string {
|
|
791
|
+
const parent = normalizeMediaPath(parentPath);
|
|
792
|
+
const child = String(name || '').trim().replace(/^\/+|\/+$/g, '') || 'Untitled';
|
|
793
|
+
|
|
794
|
+
return parent === '/' ? `/${child}` : `${parent}/${child}`;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Splits a media path into display segments.
|
|
799
|
+
*
|
|
800
|
+
* @param path - Slash-prefixed media path.
|
|
801
|
+
* @returns Path segments without empty entries.
|
|
802
|
+
*/
|
|
803
|
+
function pathSegments(path: string): string[] {
|
|
804
|
+
return normalizeMediaPath(path).split('/').filter(Boolean);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Returns a required string value or throws a clear error.
|
|
809
|
+
*
|
|
810
|
+
* @param value - Value to inspect.
|
|
811
|
+
* @param message - Error message when the value is empty.
|
|
812
|
+
* @returns Non-empty string.
|
|
813
|
+
*/
|
|
814
|
+
function requiredString(value: unknown, message: string): string {
|
|
815
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
816
|
+
throw new Error(message);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
return value;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Best-effort cleanup for a storage write that failed after bytes were written.
|
|
824
|
+
*
|
|
825
|
+
* @param disk - Storage disk that may contain the file.
|
|
826
|
+
* @param path - Storage path to remove.
|
|
827
|
+
*/
|
|
828
|
+
async function deleteStoredFileQuietly(disk: StorageDisk, path: string): Promise<void> {
|
|
829
|
+
try {
|
|
830
|
+
await disk.delete(path);
|
|
831
|
+
} catch {
|
|
832
|
+
// Failed writes should preserve the original error.
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Returns whether a database failure represents a unique-constraint conflict.
|
|
838
|
+
*
|
|
839
|
+
* @param error - Unknown database failure.
|
|
840
|
+
* @returns True for MariaDB, PostgreSQL, or SQLite unique conflicts.
|
|
841
|
+
*/
|
|
842
|
+
function isUniqueConstraintError(error: unknown): boolean {
|
|
843
|
+
if (!error || typeof error !== 'object') return false;
|
|
844
|
+
|
|
845
|
+
const code = String((error as { code?: unknown }).code ?? '');
|
|
846
|
+
|
|
847
|
+
return code === 'ER_DUP_ENTRY'
|
|
848
|
+
|| code === '23505'
|
|
849
|
+
|| code === 'SQLITE_CONSTRAINT'
|
|
850
|
+
|| code === 'SQLITE_CONSTRAINT_UNIQUE';
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* Returns whether a transaction can be retried after concurrent name allocation.
|
|
855
|
+
*
|
|
856
|
+
* MariaDB/MySQL may select one of two simultaneous inserts as a deadlock victim
|
|
857
|
+
* before its unique constraint reports the competing path. PostgreSQL exposes
|
|
858
|
+
* the equivalent deadlock and serialization failures through SQLSTATE codes.
|
|
859
|
+
*
|
|
860
|
+
* @param error - Unknown database failure.
|
|
861
|
+
* @returns True when the current allocation attempt may safely choose another name.
|
|
862
|
+
*/
|
|
863
|
+
function isRetriableTransactionConflict(error: unknown): boolean {
|
|
864
|
+
if (!error || typeof error !== 'object') return false;
|
|
865
|
+
|
|
866
|
+
const code = String((error as { code?: unknown }).code ?? '');
|
|
867
|
+
const sqlState = String((error as { sqlState?: unknown }).sqlState ?? '');
|
|
868
|
+
|
|
869
|
+
return code === 'ER_LOCK_DEADLOCK'
|
|
870
|
+
|| code === '40P01'
|
|
871
|
+
|| code === '40001'
|
|
872
|
+
|| sqlState === '40P01'
|
|
873
|
+
|| sqlState === '40001';
|
|
874
|
+
}
|