refactor(utils): structural improvements — decomposition, naming, cohesion#5124
Open
Wolfvin wants to merge 1 commit into
Open
refactor(utils): structural improvements — decomposition, naming, cohesion#5124Wolfvin wants to merge 1 commit into
Wolfvin wants to merge 1 commit into
Conversation
…esion This PR applies 5 structural refactoring improvements to @rjsf/utils, verified safe by Regrets regression testing (15 clusters, 4 chains, all GREEN). ## Changes ### 1. DECOMPOSITION: Split hashForSchema.ts - Extracted hashString into its own file (hashString.ts) - Extracted sortedJSONStringify into its own file (sortedJSONStringify.ts) - hashForSchema.ts now imports and composes these two functions - Re-exports maintain backward compatibility ### 2. NAMING: Add descriptive name for pad() - Created zeroPadNumber.ts with the same logic but a self-documenting name - pad.ts remains as a backward-compatible re-export ### 3. SINGLE RESPONSIBILITY: Split asNumber.ts - Extracted edge-case handling into isEmptyOrNaN() helper - asNumber() now delegates to the helper for cleaner conversion logic - Both functions are exported for testing ### 4. COHESION: Group enum option functions into enumOptions/ - Moved 8 enum-related files into enumOptions/ subdirectory - Added barrel index.ts for clean imports - Original files now re-export as @deprecated stubs ### 5. REDUCE COUPLING: Group date utilities into dateUtils/ - Moved 6 date-related files into dateUtils/ subdirectory - Added barrel index.ts for clean imports - Original files now re-export as @deprecated stubs ## Verification (Regrets Regression Testing) All 15 clusters GREEN before and after refactoring: - as-number: 1f74s4r, deep-equals: 2oy6zrm, find-schema-definition: 4b9t74b - get-input-props: 6d6re7g, get-schema-type: 37gcetc, guess-type: 22ist89 - hash-for-schema: 3p14hfu, is-object: 5fn2ggb, is-select: 5sc3wkq - merge-schemas: 630iedy, options-list: 49i7fg9, pad: 515wuvg - to-error-list: 4nwxvyj, validation-data-merge: 4ci4hzj, with-id-ref-prefix: iw79ovx All 4 chain hashes match: - schema-type-inference: 4vxu99p, schema-merge-and-hash: 2eeryes - error-handling-pipeline: 5kfikk3, ref-resolution-chain: 4hs6g8l KEBENARAN 1 (raw output) matches post-refactor output exactly. KEBENARAN 2 (fingerprints + chain hashes) matches post-refactor fingerprints exactly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR applies 5 structural refactoring improvements to
@rjsf/utils, all verified safe by Regrets regression testing (15 clusters, 4 chains, all GREEN).Changes
1. DECOMPOSITION: Split
hashForSchema.tshashStringinto its own file (hashString.ts) — Java-style string hashsortedJSONStringifyinto its own file (sortedJSONStringify.ts) — Deterministic JSON serializationhashForSchema.tsnow imports and composes these two functions2. NAMING: Add descriptive name for
pad()zeroPadNumber.tswith the same logic but a self-documenting namepad.tsremains as a backward-compatible re-export3. SINGLE RESPONSIBILITY: Split
asNumber.tsisEmptyOrNaN()helperasNumber()now delegates to the helper for cleaner conversion logic4. COHESION: Group enum option functions into
enumOptions/enumOptions/subdirectory with barrelindex.ts@deprecatedstubs5. REDUCE COUPLING: Group date utilities into
dateUtils/dateUtils/subdirectory with barrelindex.ts@deprecatedstubsVerification
All refactoring was verified using Regrets — an output-based regression testing tool that fingerprints function behavior before and after refactoring.
15 clusters — all GREEN (fingerprints match exactly):
4 chain hashes — all match (multi-step flows verified):
Dual-Truth Verification:
Breaking Changes
None. All previously exported names remain accessible from
@rjsf/utils. The@deprecatedstubs and re-exports ensure full backward compatibility.