editia-core
Version:
Core services and utilities for Editia applications - Authentication, Monetization, Video Generation Types, and Database Management
107 lines • 3.94 kB
JavaScript
/**
* Type Mapping Configuration for Editia Core
*
* This file provides the connection between raw Supabase types and our abstractions.
* It should be updated when the Database type is imported from generated Supabase types.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAndTransform = exports.transformFeatureFlag = exports.transformSubscriptionPlan = exports.transformUserUsage = exports.transformUser = void 0;
// ============================================================================
// TYPE TRANSFORMATION UTILITIES
// ============================================================================
/**
* Transform raw user data to our abstraction
*/
const transformUser = (raw) => ({
id: raw.id,
email: raw.email,
full_name: raw.full_name,
avatar_url: raw.avatar_url,
role: raw.role,
clerk_user_id: raw.clerk_user_id,
stripe_customer_id: raw.stripe_customer_id,
created_at: raw.created_at,
updated_at: raw.updated_at,
});
exports.transformUser = transformUser;
/**
* Transform raw user usage data to our abstraction
*/
const transformUserUsage = (raw) => ({
user_id: raw.user_id,
current_plan_id: raw.current_plan_id, // Will be validated
videos_generated: raw.videos_generated,
videos_generated_limit: raw.videos_generated_limit,
source_videos_used: raw.source_videos_used,
source_videos_limit: raw.source_videos_limit,
voice_clones_used: raw.voice_clones_used,
voice_clones_limit: raw.voice_clones_limit,
account_analysis_used: raw.account_analysis_used,
account_analysis_limit: raw.account_analysis_limit,
next_reset_date: raw.next_reset_date,
created_at: raw.created_at,
updated_at: raw.updated_at,
});
exports.transformUserUsage = transformUserUsage;
/**
* Transform raw subscription plan data to our abstraction
*/
const transformSubscriptionPlan = (raw) => ({
id: raw.id, // Will be validated
name: raw.name,
description: raw.description,
videos_generated_limit: raw.videos_generated_limit,
source_videos_limit: raw.source_videos_limit,
voice_clones_limit: raw.voice_clones_limit,
account_analysis_limit: raw.account_analysis_limit,
is_unlimited: raw.is_unlimited,
is_active: raw.is_active,
created_at: raw.created_at,
});
exports.transformSubscriptionPlan = transformSubscriptionPlan;
/**
* Transform raw feature flag data to our abstraction
*/
const transformFeatureFlag = (raw) => ({
id: raw.id,
name: raw.name,
description: raw.description,
required_plan: raw.required_plan, // Will be validated
is_active: raw.is_active,
created_at: raw.created_at,
});
exports.transformFeatureFlag = transformFeatureFlag;
// ============================================================================
// VALIDATION UTILITIES
// ============================================================================
/**
* Validate and transform raw data with type safety
*/
exports.validateAndTransform = {
user: (raw) => {
if (!raw.id || !raw.clerk_user_id) {
throw new Error('Invalid user data: missing required fields');
}
return (0, exports.transformUser)(raw);
},
userUsage: (raw) => {
if (!raw.user_id || !raw.current_plan_id) {
throw new Error('Invalid user usage data: missing required fields');
}
return (0, exports.transformUserUsage)(raw);
},
subscriptionPlan: (raw) => {
if (!raw.id || !raw.name) {
throw new Error('Invalid subscription plan data: missing required fields');
}
return (0, exports.transformSubscriptionPlan)(raw);
},
featureFlag: (raw) => {
if (!raw.id || !raw.name) {
throw new Error('Invalid feature flag data: missing required fields');
}
return (0, exports.transformFeatureFlag)(raw);
},
};
//# sourceMappingURL=mapping.js.map
;