eggi-ai-db-schema
Version:
Type-safe database schema and ORM client for Eggi.AI with direct RDS connection
170 lines • 6.23 kB
TypeScript
/**
* =============================================================================
* MAPPING JOB OPERATIONS UTILITIES
* =============================================================================
* Utility functions for creating and managing mapping jobs and their social account relationships
*
* USAGE EXAMPLES:
*
* 1. PREPARATION HANDLER (Single Social Account):
* ```typescript
* const result = await createMappingJobWithSingleSocialAccount({
* socialAccountId: 123,
* jobMetadata: {
* service: "feed_analyzer",
* triggered_by: "preparation_handler",
* linkedin_identifier: "ACoAABCDEFG"
* },
* socialAccountMetadata: {
* status: "pending",
* mapping_type: "linkedin_profile"
* }
* });
* // Creates: 1 job + 1 social account relationship
* ```
*
* 2. BATCH PROCESSING (Multiple Social Accounts):
* ```typescript
* const result = await createMappingJobWithSocialAccounts({
* socialAccounts: [
* { socialAccountId: 123, metadata: { priority: "high" } },
* { socialAccountId: 456, metadata: { priority: "normal" } },
* { socialAccountId: 789, metadata: { priority: "low" } }
* ],
* jobMetadata: {
* service: "account_worker",
* batch_size: 3,
* triggered_by: "scheduled_job"
* }
* });
* // Creates: 1 job + 3 social account relationships
* ```
*
* 3. PROCESSING LIFECYCLE:
* ```typescript
* // When processing starts
* await startMappingJob(jobId, {
* service_version: "v2.1.0",
* model_version: "gpt-4-turbo",
* started_by: "mapping_service_lambda"
* });
*
* // Update individual social account progress
* await updateMappingJobSocialAccountByIds(jobId, socialAccountId, {
* status: "processing",
* tokens_used: 1250,
* api_calls_count: 8,
* messages_analyzed: 45
* });
*
* // When processing completes
* await completeMappingJob(jobId, {
* total_relationships_found: 12,
* total_processing_time_ms: 45000,
* success: true
* });
* ```
*/
import { type MappingJob, type MappingJobSocialAccount } from "../lib/schema";
/**
* Creates a new mapping job
*
* @param params - Mapping job creation parameters
* @returns Promise resolving to the created mapping job
*/
export declare function createMappingJob(params: {
metadata?: Record<string, any>;
}): Promise<MappingJob>;
/**
* Creates a mapping job social account relationship
* Links a social account to a mapping job with metadata
*
* @param params - Mapping job social account creation parameters
* @returns Promise resolving to the created mapping job social account record
*/
export declare function createMappingJobSocialAccount(params: {
mappingJobId: number;
socialAccountId: number;
metadata?: Record<string, any>;
}): Promise<MappingJobSocialAccount>;
/**
* Updates a mapping job social account with processing results
*
* @param mappingJobSocialAccountId - The ID of the mapping job social account record
* @param updates - Fields to update
* @returns Promise resolving to the updated record
*/
export declare function updateMappingJobSocialAccount(mappingJobSocialAccountId: number, updates: {
metadata?: Record<string, any>;
}): Promise<MappingJobSocialAccount>;
/**
* Updates a mapping job social account metadata by job ID and social account ID
* This is useful when you have the job ID and social account ID but not the junction table ID
*
* @param mappingJobId - The mapping job ID
* @param socialAccountId - The social account ID
* @param metadata - Metadata to update
* @returns Promise resolving to the updated record
*/
export declare function updateMappingJobSocialAccountByIds(mappingJobId: number, socialAccountId: number, metadata: Record<string, any>): Promise<MappingJobSocialAccount>;
/**
* Comprehensive function to create a mapping job and associate it with one or more social accounts
* This handles both single social account (preparation handler) and multiple social accounts (batch processing)
*
* @param params - Combined creation parameters
* @returns Promise resolving to the mapping job and all social account relationships
*/
export declare function createMappingJobWithSocialAccounts(params: {
socialAccounts: Array<{
socialAccountId: number;
metadata?: Record<string, any>;
}>;
jobMetadata?: Record<string, any>;
}): Promise<{
mappingJob: MappingJob;
mappingJobSocialAccounts: MappingJobSocialAccount[];
}>;
/**
* Convenience function for the common case of creating a job with a single social account
* This is specifically useful for the preparation handler Lambda
*
* @param params - Single social account creation parameters
* @returns Promise resolving to the mapping job and single social account relationship
*/
export declare function createMappingJobWithSingleSocialAccount(params: {
socialAccountId: number;
jobMetadata?: Record<string, any>;
socialAccountMetadata?: Record<string, any>;
}): Promise<{
mappingJob: MappingJob;
mappingJobSocialAccount: MappingJobSocialAccount;
}>;
/**
* Updates a mapping job with timestamps and metadata
*
* @param mappingJobId - The ID of the mapping job
* @param updates - Fields to update
* @returns Promise resolving to the updated mapping job
*/
export declare function updateMappingJob(mappingJobId: number, updates: {
startedAt?: Date;
completedAt?: Date;
metadata?: Record<string, any>;
}): Promise<MappingJob>;
/**
* Marks a mapping job as started (sets startedAt timestamp)
*
* @param mappingJobId - The ID of the mapping job
* @param metadata - Optional metadata to merge with existing metadata
* @returns Promise resolving to the updated mapping job
*/
export declare function startMappingJob(mappingJobId: number, metadata?: Record<string, any>): Promise<MappingJob>;
/**
* Marks a mapping job as completed (sets completedAt timestamp)
*
* @param mappingJobId - The ID of the mapping job
* @param metadata - Optional metadata to merge with existing metadata
* @returns Promise resolving to the updated mapping job
*/
export declare function completeMappingJob(mappingJobId: number, metadata?: Record<string, any>): Promise<MappingJob>;
//# sourceMappingURL=mapping-job-operations.d.ts.map