@schemashift/core 0.10.0 → 0.11.0

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/dist/index.d.cts CHANGED
@@ -46,6 +46,71 @@ declare class SchemaAnalyzer {
46
46
  getProject(): Project;
47
47
  }
48
48
 
49
+ /**
50
+ * Approval Workflow for SchemaShift
51
+ *
52
+ * Provides review gates before executing migrations on shared codebases.
53
+ * Pending migrations are stored in `.schemashift/pending/`.
54
+ */
55
+ type ApprovalStatus = 'pending' | 'approved' | 'rejected';
56
+ interface MigrationRequest {
57
+ id: string;
58
+ from: string;
59
+ to: string;
60
+ files: string[];
61
+ requestedBy: string;
62
+ requestedAt: string;
63
+ status: ApprovalStatus;
64
+ reviewedBy?: string;
65
+ reviewedAt?: string;
66
+ reason?: string;
67
+ metadata?: Record<string, unknown>;
68
+ }
69
+ interface ApprovalDecision {
70
+ requestId: string;
71
+ status: 'approved' | 'rejected';
72
+ reviewedBy: string;
73
+ reason?: string;
74
+ }
75
+ interface ApprovalSummary {
76
+ pending: number;
77
+ approved: number;
78
+ rejected: number;
79
+ total: number;
80
+ }
81
+ /**
82
+ * Manages migration approval workflows with file-based persistence.
83
+ */
84
+ declare class ApprovalManager {
85
+ private pendingDir;
86
+ constructor(projectPath: string);
87
+ /**
88
+ * Create a new migration request for review.
89
+ */
90
+ createRequest(from: string, to: string, files: string[], requestedBy: string, metadata?: Record<string, unknown>): MigrationRequest;
91
+ /**
92
+ * Review (approve or reject) a pending migration request.
93
+ */
94
+ review(decision: ApprovalDecision): MigrationRequest;
95
+ /**
96
+ * Get a specific migration request by ID.
97
+ */
98
+ getRequest(id: string): MigrationRequest | null;
99
+ /**
100
+ * List all migration requests, optionally filtered by status.
101
+ */
102
+ listRequests(status?: ApprovalStatus): MigrationRequest[];
103
+ /**
104
+ * Get summary counts of all requests.
105
+ */
106
+ getSummary(): ApprovalSummary;
107
+ /**
108
+ * Check if a migration has been approved.
109
+ */
110
+ isApproved(requestId: string): boolean;
111
+ private ensureDir;
112
+ }
113
+
49
114
  /**
50
115
  * Represents a single method call in a chain.
51
116
  * e.g., `.email()` or `.min(5, 'Too short')`
@@ -454,6 +519,46 @@ declare function validateConfig(config: SchemaShiftConfig): {
454
519
  declare function shouldSuppressWarning(warning: string, filePath: string, rules: WarningSuppressionRule[]): boolean;
455
520
  declare function loadConfig(configPath?: string): Promise<SchemaShiftConfig>;
456
521
 
522
+ /**
523
+ * Cross-Field Validation Pattern Helpers
524
+ *
525
+ * Provides reusable patterns for common cross-field validation scenarios.
526
+ * Generates `.superRefine()` code snippets for use during migration.
527
+ */
528
+ interface CrossFieldPattern {
529
+ name: string;
530
+ description: string;
531
+ zodCode: string;
532
+ }
533
+ /**
534
+ * Generate a `.superRefine()` snippet for conditional required fields.
535
+ * When `conditionField` has a truthy value, `requiredField` becomes required.
536
+ */
537
+ declare function requireIf(conditionField: string, requiredField: string): CrossFieldPattern;
538
+ /**
539
+ * Generate a `.superRefine()` snippet requiring at least one of the given fields.
540
+ */
541
+ declare function requireOneOf(fields: string[]): CrossFieldPattern;
542
+ /**
543
+ * Generate a `.superRefine()` snippet for mutually exclusive fields.
544
+ * Only one of the given fields can have a value at a time.
545
+ */
546
+ declare function mutuallyExclusive(fields: string[]): CrossFieldPattern;
547
+ /**
548
+ * Generate a `.superRefine()` snippet for dependent fields.
549
+ * When `primaryField` is set, all `dependentFields` become required.
550
+ */
551
+ declare function dependentFields(primaryField: string, dependents: string[]): CrossFieldPattern;
552
+ /**
553
+ * Generate a `.superRefine()` snippet for conditional validation.
554
+ * When `conditionField` equals `conditionValue`, apply validation on `targetField`.
555
+ */
556
+ declare function conditionalValidation(conditionField: string, conditionValue: string, targetField: string, validationMessage: string): CrossFieldPattern;
557
+ /**
558
+ * Detect common cross-field patterns in Yup `.when()` calls and suggest Zod equivalents.
559
+ */
560
+ declare function suggestCrossFieldPattern(whenCode: string): CrossFieldPattern | null;
561
+
457
562
  interface DependencyGraphResult {
458
563
  /** Files sorted in dependency order (dependencies first) */
459
564
  sortedFiles: string[];
@@ -691,6 +796,50 @@ declare class GovernanceEngine {
691
796
  private isSchemaExpression;
692
797
  }
693
798
 
799
+ interface FixResult {
800
+ success: boolean;
801
+ fixedCode?: string;
802
+ explanation: string;
803
+ rule: string;
804
+ lineNumber: number;
805
+ }
806
+ interface FixSummary {
807
+ totalViolations: number;
808
+ fixed: number;
809
+ skipped: number;
810
+ results: FixResult[];
811
+ }
812
+ /**
813
+ * GovernanceFixer applies auto-fixes for governance violations.
814
+ * Supports fixing: no-any-schemas, require-descriptions, require-max-length, naming-convention.
815
+ */
816
+ declare class GovernanceFixer {
817
+ private defaultMaxLength;
818
+ /**
819
+ * Set the default max length appended by the require-max-length fix.
820
+ */
821
+ setDefaultMaxLength(length: number): void;
822
+ /**
823
+ * Check if a violation is auto-fixable.
824
+ */
825
+ canFix(violation: GovernanceViolation): boolean;
826
+ /**
827
+ * Fix a single violation in a source file.
828
+ * Returns the fixed code for the entire file.
829
+ */
830
+ fix(violation: GovernanceViolation, sourceCode: string): FixResult;
831
+ /**
832
+ * Fix all fixable violations in a source file.
833
+ * Applies fixes from bottom to top to preserve line numbers.
834
+ */
835
+ fixAll(violations: GovernanceViolation[], sourceCode: string): FixSummary;
836
+ private fixNoAny;
837
+ private fixRequireDescription;
838
+ private fixRequireMaxLength;
839
+ private fixNamingConvention;
840
+ private fixRequireSafeParse;
841
+ }
842
+
694
843
  /**
695
844
  * Governance Rule Templates
696
845
  *
@@ -726,6 +875,42 @@ declare function getGovernanceTemplatesByCategory(category: GovernanceTemplate['
726
875
  */
727
876
  declare function getGovernanceTemplateNames(): string[];
728
877
 
878
+ interface GraphNode {
879
+ filePath: string;
880
+ shortPath: string;
881
+ schemaLibrary?: string;
882
+ schemaCount: number;
883
+ }
884
+ interface GraphExportOptions {
885
+ /** Color-code nodes by schema library */
886
+ colorByLibrary?: boolean;
887
+ /** Highlight circular dependencies in red */
888
+ highlightCircular?: boolean;
889
+ /** Only show files using a specific library */
890
+ filterLibrary?: string;
891
+ /** File metadata for enriched graph display */
892
+ nodeMetadata?: Map<string, {
893
+ library?: string;
894
+ schemaCount?: number;
895
+ }>;
896
+ }
897
+ /**
898
+ * Exports dependency graphs in DOT (Graphviz) and Mermaid formats.
899
+ */
900
+ declare class GraphExporter {
901
+ /**
902
+ * Export dependency graph as DOT format for Graphviz.
903
+ */
904
+ exportDot(graph: DependencyGraphResult, options?: GraphExportOptions): string;
905
+ /**
906
+ * Export dependency graph as Mermaid diagram syntax.
907
+ */
908
+ exportMermaid(graph: DependencyGraphResult, options?: GraphExportOptions): string;
909
+ private shortenPath;
910
+ private toNodeId;
911
+ private toMermaidId;
912
+ }
913
+
729
914
  interface IncrementalState {
730
915
  migrationId: string;
731
916
  from: SchemaLibrary;
@@ -756,6 +941,123 @@ declare class IncrementalTracker {
756
941
  private saveState;
757
942
  }
758
943
 
944
+ interface MigrationTemplateStep {
945
+ from: string;
946
+ to: string;
947
+ description: string;
948
+ }
949
+ interface MigrationPreCheck {
950
+ description: string;
951
+ command?: string;
952
+ }
953
+ interface MigrationPostStep {
954
+ description: string;
955
+ command?: string;
956
+ }
957
+ interface PackageChange {
958
+ action: 'install' | 'remove' | 'upgrade';
959
+ package: string;
960
+ version?: string;
961
+ }
962
+ interface MigrationTemplate {
963
+ name: string;
964
+ description: string;
965
+ category: 'form-migration' | 'framework-upgrade' | 'library-switch' | 'monorepo';
966
+ migrationSteps: MigrationTemplateStep[];
967
+ preChecks: MigrationPreCheck[];
968
+ postSteps: MigrationPostStep[];
969
+ packageChanges: PackageChange[];
970
+ recommendedFlags: string[];
971
+ estimatedEffort: 'trivial' | 'low' | 'moderate' | 'high';
972
+ }
973
+ /**
974
+ * Get a migration template by name.
975
+ */
976
+ declare function getMigrationTemplate(name: string): MigrationTemplate | undefined;
977
+ /**
978
+ * Get all available migration template names.
979
+ */
980
+ declare function getMigrationTemplateNames(): string[];
981
+ /**
982
+ * Get all templates for a specific category.
983
+ */
984
+ declare function getMigrationTemplatesByCategory(category: MigrationTemplate['category']): MigrationTemplate[];
985
+ /**
986
+ * Get all built-in migration templates.
987
+ */
988
+ declare function getAllMigrationTemplates(): MigrationTemplate[];
989
+ /**
990
+ * Validate a custom migration template.
991
+ */
992
+ declare function validateMigrationTemplate(template: MigrationTemplate): {
993
+ valid: boolean;
994
+ errors: string[];
995
+ };
996
+
997
+ /**
998
+ * Webhook Notification System for SchemaShift
999
+ *
1000
+ * Sends migration event notifications to external services
1001
+ * (Slack, Teams, Zapier, custom webhooks, etc.)
1002
+ */
1003
+ type MigrationEventType = 'migration_started' | 'migration_completed' | 'migration_failed' | 'governance_violation' | 'drift_detected';
1004
+ interface MigrationEvent {
1005
+ type: MigrationEventType;
1006
+ timestamp: string;
1007
+ project?: string;
1008
+ details: Record<string, unknown>;
1009
+ }
1010
+ interface NotificationResult {
1011
+ success: boolean;
1012
+ statusCode?: number;
1013
+ error?: string;
1014
+ }
1015
+ interface WebhookConfig {
1016
+ url: string;
1017
+ events?: MigrationEventType[];
1018
+ headers?: Record<string, string>;
1019
+ secret?: string;
1020
+ }
1021
+ /**
1022
+ * Send migration event notifications via webhooks.
1023
+ */
1024
+ declare class WebhookNotifier {
1025
+ private webhooks;
1026
+ constructor(webhooks: WebhookConfig[]);
1027
+ /**
1028
+ * Create a migration event with current timestamp.
1029
+ */
1030
+ createEvent(type: MigrationEventType, details: Record<string, unknown>, project?: string): MigrationEvent;
1031
+ /**
1032
+ * Send an event to all matching webhooks.
1033
+ */
1034
+ send(event: MigrationEvent): Promise<NotificationResult[]>;
1035
+ /**
1036
+ * Send event to a single webhook endpoint.
1037
+ */
1038
+ private sendToWebhook;
1039
+ /**
1040
+ * Convenience: send a migration_started event.
1041
+ */
1042
+ notifyMigrationStarted(from: string, to: string, fileCount: number, project?: string): Promise<NotificationResult[]>;
1043
+ /**
1044
+ * Convenience: send a migration_completed event.
1045
+ */
1046
+ notifyMigrationCompleted(from: string, to: string, fileCount: number, warningCount: number, project?: string): Promise<NotificationResult[]>;
1047
+ /**
1048
+ * Convenience: send a migration_failed event.
1049
+ */
1050
+ notifyMigrationFailed(from: string, to: string, error: string, project?: string): Promise<NotificationResult[]>;
1051
+ /**
1052
+ * Convenience: send a governance_violation event.
1053
+ */
1054
+ notifyGovernanceViolation(violationCount: number, rules: string[], project?: string): Promise<NotificationResult[]>;
1055
+ /**
1056
+ * Convenience: send a drift_detected event.
1057
+ */
1058
+ notifyDriftDetected(modifiedFiles: number, addedFiles: number, removedFiles: number, project?: string): Promise<NotificationResult[]>;
1059
+ }
1060
+
759
1061
  interface PackageUpdatePlan {
760
1062
  add: Record<string, string>;
761
1063
  remove: string[];
@@ -834,6 +1136,38 @@ interface StandardSchemaInfo {
834
1136
  }
835
1137
  declare function detectStandardSchema(projectPath: string): StandardSchemaInfo;
836
1138
 
1139
+ interface StandardSchemaAdvisory {
1140
+ shouldConsiderAdapter: boolean;
1141
+ reason: string;
1142
+ adapterExample?: string;
1143
+ migrationAdvantages: string[];
1144
+ adapterAdvantages: string[];
1145
+ recommendation: 'migrate' | 'adapter' | 'either';
1146
+ }
1147
+ /**
1148
+ * Advises whether to do a full migration or use Standard Schema adapters.
1149
+ *
1150
+ * When both source and target libraries support Standard Schema 1.0,
1151
+ * users may not need a full migration — they can use adapters instead.
1152
+ */
1153
+ declare class StandardSchemaAdvisor {
1154
+ /**
1155
+ * Check if a schema library supports Standard Schema.
1156
+ */
1157
+ supportsStandardSchema(library: SchemaLibrary | string): boolean;
1158
+ /**
1159
+ * Generate advisory for a given migration path.
1160
+ */
1161
+ advise(from: SchemaLibrary | string, to: SchemaLibrary | string): StandardSchemaAdvisory;
1162
+ /**
1163
+ * Analyze a project and provide advisory based on detected libraries.
1164
+ */
1165
+ adviseFromProject(projectPath: string, from: SchemaLibrary | string, to: SchemaLibrary | string): StandardSchemaAdvisory & {
1166
+ projectInfo: StandardSchemaInfo;
1167
+ };
1168
+ private generateAdapterExample;
1169
+ }
1170
+
837
1171
  interface ScaffoldedTest {
838
1172
  filePath: string;
839
1173
  testCode: string;
@@ -894,4 +1228,4 @@ declare class TypeDedupDetector {
894
1228
  private namesRelated;
895
1229
  }
896
1230
 
897
- export { type AnalysisResult, type AuditEntry, type AuditEntryMetadata, type AuditLog, type BehavioralAnalysisResult, type BehavioralCategory, type BehavioralWarning, BehavioralWarningAnalyzer, BundleEstimator, type BundleSizeEstimate, type CallChainInfo, type ChainResult, type ChainStep, type ChainStepResult, type ChainValidation, CompatibilityAnalyzer, type CompatibilityResult, type ComplexityEstimate, ComplexityEstimator, type ComplexityWarning, type CustomRule, type DependencyGraphResult, type DetailedAnalysisResult, DetailedAnalyzer, DriftDetector, type DriftModification, type DriftResult, type DuplicateTypeCandidate, EcosystemAnalyzer, type EcosystemIssue, type EcosystemReport, type EffortLevel, type FileComplexity, type FormLibraryDetection, FormResolverMigrator, type FormResolverResult, GOVERNANCE_TEMPLATES, GovernanceEngine, type GovernanceResult, type GovernanceRuleConfig, type GovernanceRuleFunction, type GovernanceTemplate, type GovernanceViolation, type IncrementalState, IncrementalTracker, type LibraryBundleInfo, type LibraryVersionInfo, type MethodCallInfo, MigrationAuditLog, MigrationChain, type MigrationReadiness, type MonorepoInfo, type MonorepoPackage, MonorepoResolver, type PackageUpdatePlan, PackageUpdater, type ParallelBatch, type PerformanceAnalysisResult, PerformanceAnalyzer, type PerformanceCategory, type PerformanceWarning, type PluginLoadResult, PluginLoader, type ScaffoldedTest, SchemaAnalyzer, type SchemaComplexity, SchemaDependencyResolver, type SchemaFileSnapshot, type SchemaInfo, type SchemaLibrary, type SchemaShiftConfig, type SchemaShiftPlugin, type SchemaSnapshot, type StandardSchemaInfo, type TestScaffoldResult, TestScaffolder, TransformEngine, type TransformError, type TransformHandler, type TransformOptions, type TransformResult, TypeDedupDetector, type TypeDedupResult, type VersionIssue, type WarningSuppressionRule, type WorkspaceManager, buildCallChain, computeParallelBatches, detectFormLibraries, detectSchemaLibrary, detectStandardSchema, getGovernanceTemplate, getGovernanceTemplateNames, getGovernanceTemplatesByCategory, isInsideComment, isInsideStringLiteral, loadConfig, parseCallChain, shouldSuppressWarning, startsWithBase, transformMethodChain, validateConfig };
1231
+ export { type AnalysisResult, type ApprovalDecision, ApprovalManager, type ApprovalStatus, type ApprovalSummary, type AuditEntry, type AuditEntryMetadata, type AuditLog, type BehavioralAnalysisResult, type BehavioralCategory, type BehavioralWarning, BehavioralWarningAnalyzer, BundleEstimator, type BundleSizeEstimate, type CallChainInfo, type ChainResult, type ChainStep, type ChainStepResult, type ChainValidation, CompatibilityAnalyzer, type CompatibilityResult, type ComplexityEstimate, ComplexityEstimator, type ComplexityWarning, type CrossFieldPattern, type CustomRule, type DependencyGraphResult, type DetailedAnalysisResult, DetailedAnalyzer, DriftDetector, type DriftModification, type DriftResult, type DuplicateTypeCandidate, EcosystemAnalyzer, type EcosystemIssue, type EcosystemReport, type EffortLevel, type FileComplexity, type FixResult, type FixSummary, type FormLibraryDetection, FormResolverMigrator, type FormResolverResult, GOVERNANCE_TEMPLATES, GovernanceEngine, GovernanceFixer, type GovernanceResult, type GovernanceRuleConfig, type GovernanceRuleFunction, type GovernanceTemplate, type GovernanceViolation, type GraphExportOptions, GraphExporter, type GraphNode, type IncrementalState, IncrementalTracker, type LibraryBundleInfo, type LibraryVersionInfo, type MethodCallInfo, MigrationAuditLog, MigrationChain, type MigrationEvent, type MigrationEventType, type MigrationReadiness, type MigrationRequest, type MigrationTemplate, type MigrationTemplateStep, type MonorepoInfo, type MonorepoPackage, MonorepoResolver, type NotificationResult, type PackageChange, type PackageUpdatePlan, PackageUpdater, type ParallelBatch, type PerformanceAnalysisResult, PerformanceAnalyzer, type PerformanceCategory, type PerformanceWarning, type PluginLoadResult, PluginLoader, type ScaffoldedTest, SchemaAnalyzer, type SchemaComplexity, SchemaDependencyResolver, type SchemaFileSnapshot, type SchemaInfo, type SchemaLibrary, type SchemaShiftConfig, type SchemaShiftPlugin, type SchemaSnapshot, StandardSchemaAdvisor, type StandardSchemaAdvisory, type StandardSchemaInfo, type TestScaffoldResult, TestScaffolder, TransformEngine, type TransformError, type TransformHandler, type TransformOptions, type TransformResult, TypeDedupDetector, type TypeDedupResult, type VersionIssue, type WarningSuppressionRule, type WebhookConfig, WebhookNotifier, type WorkspaceManager, buildCallChain, computeParallelBatches, conditionalValidation, dependentFields, detectFormLibraries, detectSchemaLibrary, detectStandardSchema, getAllMigrationTemplates, getGovernanceTemplate, getGovernanceTemplateNames, getGovernanceTemplatesByCategory, getMigrationTemplate, getMigrationTemplateNames, getMigrationTemplatesByCategory, isInsideComment, isInsideStringLiteral, loadConfig, mutuallyExclusive, parseCallChain, requireIf, requireOneOf, shouldSuppressWarning, startsWithBase, suggestCrossFieldPattern, transformMethodChain, validateConfig, validateMigrationTemplate };