supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
124 lines • 3.58 kB
TypeScript
/**
* Schema-Driven Workflow Builder
* Builds dynamic workflows based on actual database schema instead of hardcoded assumptions
* Replaces framework-specific business logic with configurable execution patterns
*/
import { SchemaIntrospector } from '../../schema/schema-introspector';
export interface WorkflowStep {
id: string;
type: 'create_auth_user' | 'insert_record' | 'validate_constraint' | 'execute_trigger' | 'conditional_action';
table?: string;
description: string;
dependencies: string[];
fields: WorkflowField[];
conditions?: WorkflowCondition[];
onError: 'fail' | 'skip' | 'retry' | 'continue';
retryCount?: number;
timeout?: number;
}
export interface WorkflowField {
name: string;
source: 'input' | 'generated' | 'reference' | 'computed';
sourceField?: string;
generator?: 'uuid' | 'faker' | 'timestamp' | 'sequence';
fakerType?: string;
required: boolean;
validation?: WorkflowValidation[];
}
export interface WorkflowCondition {
type: 'field_exists' | 'constraint_check' | 'relationship_exists' | 'custom_sql';
field?: string;
value?: any;
sqlCondition?: string;
description: string;
}
export interface WorkflowValidation {
type: 'not_null' | 'unique' | 'foreign_key' | 'check_constraint' | 'custom';
errorMessage: string;
sqlCheck?: string;
}
export interface UserCreationWorkflow {
id: string;
name: string;
description: string;
steps: WorkflowStep[];
rollbackSteps: WorkflowStep[];
metadata: {
framework: string;
version: string;
createdAt: string;
schemaHash: string;
};
}
export interface WorkflowBuilderConfig {
primaryUserTable: string;
enableConstraintValidation: boolean;
enableRollback: boolean;
generateOptionalFields: boolean;
respectExistingData: boolean;
customFieldMappings?: Record<string, string>;
constraintOverrides?: Record<string, boolean>;
}
export declare class WorkflowBuilder {
private introspector;
private schemaResult;
constructor(introspector: SchemaIntrospector);
/**
* Build a complete user creation workflow based on actual schema
*/
buildUserCreationWorkflow(config: WorkflowBuilderConfig): Promise<UserCreationWorkflow>;
/**
* Find the appropriate user table pattern
*/
private findUserTable;
/**
* Build the complete workflow steps
*/
private buildWorkflowSteps;
/**
* Build auth user creation step
*/
private buildAuthUserStep;
/**
* Build constraint validation steps
*/
private buildConstraintValidationSteps;
/**
* Build the main user record creation step
*/
private buildUserRecordStep;
/**
* Build a workflow field from a database column
*/
private buildFieldFromColumn;
/**
* Build steps for related tables
*/
private buildRelatedTableSteps;
/**
* Build a step for a related table
*/
private buildRelatedTableStep;
/**
* Build post-creation steps
*/
private buildPostCreationSteps;
/**
* Build rollback steps
*/
private buildRollbackSteps;
/**
* Utility methods
*/
private generateBasicColumnMappings;
private generateSchemaHash;
/**
* Validate a workflow against the current schema
*/
validateWorkflow(workflow: UserCreationWorkflow): Promise<{
isValid: boolean;
errors: string[];
warnings: string[];
}>;
}
//# sourceMappingURL=workflow-builder.d.ts.map