@schemashift/core 0.7.0 → 0.9.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
@@ -143,6 +143,120 @@ declare function transformMethodChain(chain: CallChainInfo, newBase: string, fac
143
143
  args: string[];
144
144
  }[] | null | undefined): string;
145
145
 
146
+ interface AuditEntry {
147
+ timestamp: string;
148
+ migrationId: string;
149
+ filePath: string;
150
+ action: 'transform' | 'rollback' | 'skip';
151
+ from: string;
152
+ to: string;
153
+ success: boolean;
154
+ beforeHash: string;
155
+ afterHash?: string;
156
+ warningCount: number;
157
+ errorCount: number;
158
+ riskScore?: number;
159
+ user?: string;
160
+ duration?: number;
161
+ }
162
+ interface AuditLog {
163
+ version: number;
164
+ entries: AuditEntry[];
165
+ }
166
+ declare class MigrationAuditLog {
167
+ private logDir;
168
+ private logPath;
169
+ constructor(projectPath: string);
170
+ /**
171
+ * Append a new entry to the audit log.
172
+ */
173
+ append(entry: AuditEntry): void;
174
+ /**
175
+ * Create an audit entry for a file transformation.
176
+ */
177
+ createEntry(params: {
178
+ migrationId: string;
179
+ filePath: string;
180
+ from: string;
181
+ to: string;
182
+ originalCode: string;
183
+ transformedCode?: string;
184
+ success: boolean;
185
+ warningCount: number;
186
+ errorCount: number;
187
+ riskScore?: number;
188
+ duration?: number;
189
+ }): AuditEntry;
190
+ /**
191
+ * Read the current audit log.
192
+ */
193
+ read(): AuditLog;
194
+ /**
195
+ * Get entries for a specific migration.
196
+ */
197
+ getByMigration(migrationId: string): AuditEntry[];
198
+ /**
199
+ * Get summary statistics for the audit log.
200
+ */
201
+ getSummary(): {
202
+ totalMigrations: number;
203
+ totalFiles: number;
204
+ successCount: number;
205
+ failureCount: number;
206
+ migrationPaths: string[];
207
+ };
208
+ /**
209
+ * Clear the audit log.
210
+ */
211
+ clear(): void;
212
+ private write;
213
+ private hashContent;
214
+ private getCurrentUser;
215
+ }
216
+
217
+ interface BehavioralWarning {
218
+ category: BehavioralCategory;
219
+ message: string;
220
+ detail: string;
221
+ filePath: string;
222
+ lineNumber?: number;
223
+ severity: 'info' | 'warning' | 'error';
224
+ migration: string;
225
+ }
226
+ type BehavioralCategory = 'type-coercion' | 'error-handling' | 'default-values' | 'error-format' | 'form-input' | 'validation-behavior' | 'null-handling';
227
+ interface BehavioralAnalysisResult {
228
+ warnings: BehavioralWarning[];
229
+ migrationPath: string;
230
+ summary: string;
231
+ }
232
+ declare class BehavioralWarningAnalyzer {
233
+ analyze(sourceFiles: SourceFile[], from: SchemaLibrary, to: SchemaLibrary): BehavioralAnalysisResult;
234
+ private fileUsesLibrary;
235
+ private generateSummary;
236
+ }
237
+
238
+ interface BundleSizeEstimate {
239
+ from: LibraryBundleInfo;
240
+ to: LibraryBundleInfo;
241
+ estimatedDelta: number;
242
+ deltaPercent: number;
243
+ summary: string;
244
+ caveats: string[];
245
+ }
246
+ interface LibraryBundleInfo {
247
+ library: string;
248
+ minifiedGzipKb: number;
249
+ treeShakable: boolean;
250
+ estimatedUsedKb: number;
251
+ }
252
+ declare class BundleEstimator {
253
+ estimate(sourceFiles: SourceFile[], from: SchemaLibrary, to: SchemaLibrary): BundleSizeEstimate;
254
+ private countUsedValidators;
255
+ private getLibraryInfo;
256
+ private generateCaveats;
257
+ private generateSummary;
258
+ }
259
+
146
260
  interface TransformHandler {
147
261
  transform(sourceFile: SourceFile, options: TransformOptions): TransformResult;
148
262
  }
@@ -191,6 +305,7 @@ interface EcosystemIssue {
191
305
  suggestion: string;
192
306
  severity: 'info' | 'warning' | 'error';
193
307
  category: 'orm' | 'form' | 'api' | 'validation-util' | 'openapi' | 'ui';
308
+ upgradeCommand?: string;
194
309
  }
195
310
  interface EcosystemReport {
196
311
  dependencies: EcosystemIssue[];
@@ -199,6 +314,10 @@ interface EcosystemReport {
199
314
  }
200
315
  declare class EcosystemAnalyzer {
201
316
  analyze(projectPath: string, from: string, to: string): EcosystemReport;
317
+ /**
318
+ * Returns a list of npm install commands needed to resolve ecosystem issues.
319
+ */
320
+ getUpgradeCommands(report: EcosystemReport): string[];
202
321
  }
203
322
 
204
323
  interface VersionIssue {
@@ -226,6 +345,34 @@ declare class CompatibilityAnalyzer {
226
345
  checkCompatibility(projectPath: string, from?: string, to?: string): CompatibilityResult;
227
346
  }
228
347
 
348
+ type EffortLevel = 'trivial' | 'low' | 'moderate' | 'high' | 'extreme';
349
+ interface ComplexityWarning {
350
+ file: string;
351
+ line?: number;
352
+ message: string;
353
+ severity: 'info' | 'warning' | 'error';
354
+ }
355
+ interface FileComplexity {
356
+ filePath: string;
357
+ schemaCount: number;
358
+ advancedPatterns: string[];
359
+ chainDepth: number;
360
+ lineCount: number;
361
+ }
362
+ interface ComplexityEstimate {
363
+ effort: EffortLevel;
364
+ totalSchemas: number;
365
+ totalFiles: number;
366
+ advancedPatternCount: number;
367
+ files: FileComplexity[];
368
+ warnings: ComplexityWarning[];
369
+ riskAreas: string[];
370
+ }
371
+ declare class ComplexityEstimator {
372
+ estimate(files: SourceFile[]): ComplexityEstimate;
373
+ private calculateEffort;
374
+ }
375
+
229
376
  interface SchemaShiftConfig {
230
377
  include: string[];
231
378
  exclude: string[];
@@ -300,6 +447,60 @@ declare class SchemaDependencyResolver {
300
447
  private topologicalSort;
301
448
  private shortenPath;
302
449
  }
450
+ interface MonorepoPackage {
451
+ name: string;
452
+ path: string;
453
+ schemaLibrary?: string;
454
+ dependencies: string[];
455
+ }
456
+ interface MonorepoInfo {
457
+ isMonorepo: boolean;
458
+ packages: MonorepoPackage[];
459
+ suggestedOrder: string[];
460
+ }
461
+ /**
462
+ * Groups monorepo packages into parallelizable batches.
463
+ * Packages within the same batch have no dependencies on each other.
464
+ * Batches must be executed in order (batch 0 first, then batch 1, etc.).
465
+ */
466
+ interface ParallelBatch {
467
+ /** Batch index (0-based, execute in order) */
468
+ index: number;
469
+ /** Package names that can be processed in parallel */
470
+ packages: string[];
471
+ }
472
+ /**
473
+ * Computes parallel execution batches from a topological ordering.
474
+ * Packages are grouped by their "depth" in the dependency graph — packages
475
+ * at the same depth have no mutual dependencies and can run concurrently.
476
+ */
477
+ declare function computeParallelBatches(packages: MonorepoPackage[], suggestedOrder: string[]): ParallelBatch[];
478
+ type WorkspaceManager = 'npm' | 'pnpm' | 'yarn';
479
+ declare class MonorepoResolver {
480
+ detect(projectPath: string): boolean;
481
+ /**
482
+ * Detect which workspace manager is being used.
483
+ */
484
+ detectManager(projectPath: string): WorkspaceManager;
485
+ analyze(projectPath: string): MonorepoInfo;
486
+ private suggestOrder;
487
+ /**
488
+ * Resolve workspace glob patterns from any supported format.
489
+ * Supports: npm/yarn workspaces (package.json), pnpm-workspace.yaml
490
+ */
491
+ private resolveWorkspaceGlobs;
492
+ /**
493
+ * Parse pnpm-workspace.yaml to extract workspace package globs.
494
+ * Simple YAML parsing for the common format:
495
+ * ```
496
+ * packages:
497
+ * - 'packages/*'
498
+ * - 'apps/*'
499
+ * ```
500
+ */
501
+ private parsePnpmWorkspace;
502
+ private resolveWorkspaceDirs;
503
+ }
303
504
 
304
505
  interface SchemaComplexity {
305
506
  schemaName: string;
@@ -357,6 +558,16 @@ interface FormLibraryDetection {
357
558
  }
358
559
  declare function detectFormLibraries(sourceFile: SourceFile): FormLibraryDetection[];
359
560
 
561
+ interface FormResolverResult {
562
+ success: boolean;
563
+ transformedCode: string;
564
+ changes: string[];
565
+ warnings: string[];
566
+ }
567
+ declare class FormResolverMigrator {
568
+ migrate(sourceFile: SourceFile, from: string, to: string): FormResolverResult;
569
+ }
570
+
360
571
  interface GovernanceViolation {
361
572
  rule: string;
362
573
  message: string;
@@ -372,11 +583,26 @@ interface GovernanceResult {
372
583
  schemasChecked: number;
373
584
  passed: boolean;
374
585
  }
586
+ /**
587
+ * Custom governance rule function interface.
588
+ * Plugins can define rules as functions that receive a source file and config,
589
+ * and return violations found.
590
+ */
591
+ type GovernanceRuleFunction = (sourceFile: SourceFile, config: GovernanceRuleConfig) => GovernanceViolation[];
375
592
  declare class GovernanceEngine {
376
593
  private rules;
594
+ private customRuleFunctions;
377
595
  configure(rules: Record<string, GovernanceRuleConfig>): void;
596
+ /**
597
+ * Register a custom governance rule function.
598
+ * Custom rules are executed per-file alongside built-in rules.
599
+ */
600
+ registerRule(name: string, fn: GovernanceRuleFunction): void;
378
601
  analyze(project: Project): GovernanceResult;
379
602
  private detectFileLibrary;
603
+ private measureNestingDepth;
604
+ private detectDynamicSchemas;
605
+ private getSchemaPrefix;
380
606
  private isSchemaExpression;
381
607
  }
382
608
 
@@ -420,6 +646,39 @@ declare class PackageUpdater {
420
646
  apply(projectPath: string, plan: PackageUpdatePlan): void;
421
647
  }
422
648
 
649
+ interface PerformanceWarning {
650
+ category: PerformanceCategory;
651
+ message: string;
652
+ detail: string;
653
+ filePath: string;
654
+ lineNumber?: number;
655
+ severity: 'info' | 'warning' | 'error';
656
+ }
657
+ type PerformanceCategory = 'jit-overhead' | 'cold-start' | 'repeated-parsing' | 'schema-creation' | 'dynamic-schemas';
658
+ interface PerformanceAnalysisResult {
659
+ warnings: PerformanceWarning[];
660
+ parseCallSites: number;
661
+ dynamicSchemaCount: number;
662
+ recommendation: string;
663
+ summary: string;
664
+ }
665
+ /**
666
+ * Analyzes performance implications of schema library migration.
667
+ *
668
+ * Key considerations:
669
+ * - Zod v4 uses JIT compilation: 17x slower schema creation, 8x faster repeated parsing
670
+ * - Valibot is ~2x faster than Zod v3, similar to v4 for runtime
671
+ * - Serverless/edge: Zod v4 JIT penalizes cold starts
672
+ * - Long-lived servers: Zod v4 JIT amortizes well over repeated parses
673
+ */
674
+ declare class PerformanceAnalyzer {
675
+ analyze(sourceFiles: SourceFile[], from: SchemaLibrary, to: SchemaLibrary): PerformanceAnalysisResult;
676
+ private detectDynamicSchemas;
677
+ private addMigrationWarnings;
678
+ private getRecommendation;
679
+ private generateSummary;
680
+ }
681
+
423
682
  interface SchemaShiftPlugin {
424
683
  name: string;
425
684
  version: string;
@@ -429,6 +688,10 @@ interface SchemaShiftPlugin {
429
688
  handler: TransformHandler;
430
689
  }>;
431
690
  rules?: CustomRule[];
691
+ governanceRules?: Array<{
692
+ name: string;
693
+ fn: GovernanceRuleFunction;
694
+ }>;
432
695
  }
433
696
  interface PluginLoadResult {
434
697
  loaded: SchemaShiftPlugin[];
@@ -446,7 +709,69 @@ interface StandardSchemaInfo {
446
709
  version: string;
447
710
  }>;
448
711
  recommendation: string;
712
+ adoptionPath?: string;
713
+ interopTools: string[];
449
714
  }
450
715
  declare function detectStandardSchema(projectPath: string): StandardSchemaInfo;
451
716
 
452
- export { type AnalysisResult, type CallChainInfo, type ChainResult, type ChainStep, type ChainStepResult, type ChainValidation, CompatibilityAnalyzer, type CompatibilityResult, type CustomRule, type DependencyGraphResult, type DetailedAnalysisResult, DetailedAnalyzer, EcosystemAnalyzer, type EcosystemIssue, type EcosystemReport, type FormLibraryDetection, GovernanceEngine, type GovernanceResult, type GovernanceRuleConfig, type GovernanceViolation, type IncrementalState, IncrementalTracker, type LibraryVersionInfo, type MethodCallInfo, MigrationChain, type MigrationReadiness, type PackageUpdatePlan, PackageUpdater, type PluginLoadResult, PluginLoader, SchemaAnalyzer, type SchemaComplexity, SchemaDependencyResolver, type SchemaInfo, type SchemaLibrary, type SchemaShiftConfig, type SchemaShiftPlugin, type StandardSchemaInfo, TransformEngine, type TransformError, type TransformHandler, type TransformOptions, type TransformResult, type VersionIssue, type WarningSuppressionRule, buildCallChain, detectFormLibraries, detectSchemaLibrary, detectStandardSchema, isInsideComment, isInsideStringLiteral, loadConfig, parseCallChain, shouldSuppressWarning, startsWithBase, transformMethodChain, validateConfig };
717
+ interface ScaffoldedTest {
718
+ filePath: string;
719
+ testCode: string;
720
+ schemaCount: number;
721
+ }
722
+ interface TestScaffoldResult {
723
+ tests: ScaffoldedTest[];
724
+ totalSchemas: number;
725
+ summary: string;
726
+ }
727
+ /**
728
+ * Generates test files that validate pre/post migration behavior equivalence.
729
+ *
730
+ * For each schema file, generates a test that:
731
+ * 1. Imports the schema
732
+ * 2. Tests validation of sample data (valid + invalid)
733
+ * 3. Verifies error behavior is consistent
734
+ */
735
+ declare class TestScaffolder {
736
+ scaffold(sourceFiles: SourceFile[], from: SchemaLibrary, to: SchemaLibrary): TestScaffoldResult;
737
+ private extractSchemaNames;
738
+ private getLibraryPrefixes;
739
+ private generateTestFile;
740
+ private getParseMethod;
741
+ private getErrorClass;
742
+ private generateSchemaTests;
743
+ }
744
+
745
+ interface DuplicateTypeCandidate {
746
+ typeName: string;
747
+ typeFilePath: string;
748
+ typeLineNumber: number;
749
+ schemaName: string;
750
+ schemaFilePath: string;
751
+ schemaLineNumber: number;
752
+ matchedFields: string[];
753
+ confidence: 'high' | 'medium' | 'low';
754
+ suggestion: string;
755
+ }
756
+ interface TypeDedupResult {
757
+ candidates: DuplicateTypeCandidate[];
758
+ summary: string;
759
+ }
760
+ /**
761
+ * Detects TypeScript interfaces/types that mirror schema shapes.
762
+ *
763
+ * In Joi and Yup codebases, developers often maintain duplicate type definitions
764
+ * alongside schemas because those libraries don't infer TypeScript types.
765
+ * After migrating to Zod, these duplicates can be replaced with z.infer<typeof schema>.
766
+ */
767
+ declare class TypeDedupDetector {
768
+ detect(sourceFiles: SourceFile[]): TypeDedupResult;
769
+ private collectTypeDefinitions;
770
+ private collectSchemaDefinitions;
771
+ private extractSchemaFields;
772
+ private findMatches;
773
+ private getMatchedFields;
774
+ private namesRelated;
775
+ }
776
+
777
+ export { type AnalysisResult, type AuditEntry, 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, type DuplicateTypeCandidate, EcosystemAnalyzer, type EcosystemIssue, type EcosystemReport, type EffortLevel, type FileComplexity, type FormLibraryDetection, FormResolverMigrator, type FormResolverResult, GovernanceEngine, type GovernanceResult, type GovernanceRuleConfig, type GovernanceRuleFunction, 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 SchemaInfo, type SchemaLibrary, type SchemaShiftConfig, type SchemaShiftPlugin, 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, isInsideComment, isInsideStringLiteral, loadConfig, parseCallChain, shouldSuppressWarning, startsWithBase, transformMethodChain, validateConfig };