supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
224 lines • 7.8 kB
JavaScript
;
/**
* Storage Configuration Management
* Handles configuration for storage integration across different frameworks
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageConfigUtils = exports.FRAMEWORK_STORAGE_CONFIGS = void 0;
exports.getFrameworkStorageConfig = getFrameworkStorageConfig;
exports.getMergedStorageConfig = getMergedStorageConfig;
exports.validateStorageConfig = validateStorageConfig;
exports.generateStorageRecommendations = generateStorageRecommendations;
exports.getEnvironmentStorageConfig = getEnvironmentStorageConfig;
const storage_types_1 = require("../../features/generation/storage/storage-types");
/**
* Framework-specific storage configurations
*/
exports.FRAMEWORK_STORAGE_CONFIGS = {
makerkit: {
framework: 'makerkit',
config: {
bucketName: 'media',
domain: 'outdoor-adventure',
respectRLS: true,
enableRealImages: true,
imagesPerSetup: 8,
categories: ['outdoor', 'adventure', 'nature', 'travel'],
storageRootPath: 'accounts'
},
bucketStrategy: 'tenant-scoped',
defaultPermissions: {
respectRLS: true,
enablePublicUrls: false,
requireAuth: true
},
mediaAttachmentStrategy: 'database'
},
'makerkit-profiles': {
framework: 'makerkit-profiles',
config: {
bucketName: 'media',
domain: 'outdoor-adventure',
respectRLS: true,
enableRealImages: true,
imagesPerSetup: 6,
categories: ['outdoor', 'adventure', 'profile', 'nature'],
storageRootPath: 'profiles'
},
bucketStrategy: 'single',
defaultPermissions: {
respectRLS: true,
enablePublicUrls: false,
requireAuth: true
},
mediaAttachmentStrategy: 'database'
},
simple: {
framework: 'simple',
config: {
bucketName: 'uploads',
domain: 'general',
respectRLS: false,
enableRealImages: false,
imagesPerSetup: 3,
categories: ['general', 'placeholder'],
storageRootPath: 'files'
},
bucketStrategy: 'single',
defaultPermissions: {
respectRLS: false,
enablePublicUrls: true,
requireAuth: false
},
mediaAttachmentStrategy: 'metadata-only'
},
custom: {
framework: 'custom',
config: {
bucketName: 'files',
domain: 'general',
respectRLS: false,
enableRealImages: false,
imagesPerSetup: 4,
categories: ['general', 'user-content'],
storageRootPath: 'uploads'
},
bucketStrategy: 'single',
defaultPermissions: {
respectRLS: false,
enablePublicUrls: true,
requireAuth: false
},
mediaAttachmentStrategy: 'hybrid'
},
generic: {
framework: 'generic',
config: {
bucketName: 'media',
domain: 'general',
respectRLS: true,
enableRealImages: false,
imagesPerSetup: 3,
categories: ['general', 'placeholder', 'mock'],
storageRootPath: 'uploads'
},
bucketStrategy: 'single',
defaultPermissions: {
respectRLS: true,
enablePublicUrls: false,
requireAuth: true
},
mediaAttachmentStrategy: 'database'
}
};
/**
* Get storage configuration for a specific framework
*/
function getFrameworkStorageConfig(framework) {
return exports.FRAMEWORK_STORAGE_CONFIGS[framework] || exports.FRAMEWORK_STORAGE_CONFIGS.generic;
}
/**
* Get merged storage configuration with custom overrides
*/
function getMergedStorageConfig(framework, customConfig) {
const frameworkConfig = getFrameworkStorageConfig(framework);
const domainConfig = storage_types_1.DOMAIN_CONFIGURATIONS[frameworkConfig.config.domain || 'general'] || {};
return {
...storage_types_1.DEFAULT_STORAGE_CONFIG,
...domainConfig,
...frameworkConfig.config,
...customConfig
};
}
/**
* Validate storage configuration
*/
function validateStorageConfig(config) {
const errors = [];
const warnings = [];
// Required fields validation
if (!config.bucketName) {
errors.push('bucketName is required');
}
if (!config.domain) {
warnings.push('domain not specified, using default');
}
// Logical validation
if (config.enableRealImages && (!process.env.UNSPLASH_ACCESS_KEY && !process.env.PIXABAY_API_KEY)) {
warnings.push('enableRealImages is true but no API keys found - will fallback to mock images');
}
// Note: Permission validation is handled at the framework level
if (config.imagesPerSetup && config.imagesPerSetup > 20) {
warnings.push('imagesPerSetup is high - may impact performance and API rate limits');
}
// Category validation
if (config.categories && config.categories.length === 0) {
warnings.push('Empty categories array - will use default categories');
}
return {
isValid: errors.length === 0,
errors,
warnings
};
}
/**
* Generate storage recommendations based on configuration
*/
function generateStorageRecommendations(framework, config) {
const recommendations = [];
const frameworkConfig = getFrameworkStorageConfig(framework);
// Framework-specific recommendations
if (framework === 'generic') {
recommendations.push('Consider using a framework-specific strategy for better storage integration');
recommendations.push('Generic storage uses conservative settings for compatibility');
}
if (frameworkConfig.bucketStrategy === 'tenant-scoped') {
recommendations.push('Tenant-scoped storage requires proper RLS policies');
recommendations.push('Ensure tenant isolation is properly configured');
}
// Configuration-based recommendations
if (config.enableRealImages) {
recommendations.push('Real image generation requires API keys and rate limit consideration');
recommendations.push('Monitor external API usage to prevent rate limiting');
}
if (config.respectRLS === false) {
recommendations.push('RLS bypass enabled - ensure security implications are understood');
recommendations.push('Consider enabling RLS for production environments');
}
// Note: Permission validation recommendations are handled by the framework strategy
return recommendations;
}
/**
* Get environment-specific storage configuration
*/
function getEnvironmentStorageConfig() {
const environment = process.env.NODE_ENV || 'development';
const baseConfig = {};
switch (environment) {
case 'production':
baseConfig.enableRealImages = true;
baseConfig.respectRLS = true;
break;
case 'staging':
baseConfig.enableRealImages = false; // Use mock images in staging
baseConfig.respectRLS = true;
break;
case 'development':
default:
baseConfig.enableRealImages = false;
baseConfig.respectRLS = false;
break;
}
return baseConfig;
}
/**
* Storage configuration utilities
*/
exports.StorageConfigUtils = {
getFrameworkConfig: getFrameworkStorageConfig,
getMergedConfig: getMergedStorageConfig,
validate: validateStorageConfig,
getRecommendations: generateStorageRecommendations,
getEnvironmentConfig: getEnvironmentStorageConfig
};
//# sourceMappingURL=storage-config.js.map