Skip to content

refactor(utils): structural improvements — decomposition, naming, cohesion#5124

Open
Wolfvin wants to merge 1 commit into
rjsf-team:mainfrom
Wolfvin:refactor/utils-structural-improvements
Open

refactor(utils): structural improvements — decomposition, naming, cohesion#5124
Wolfvin wants to merge 1 commit into
rjsf-team:mainfrom
Wolfvin:refactor/utils-structural-improvements

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jun 14, 2026

Copy link
Copy Markdown

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.ts

  • Extracted hashString into its own file (hashString.ts) — Java-style string hash
  • Extracted sortedJSONStringify into its own file (sortedJSONStringify.ts) — Deterministic JSON serialization
  • 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 with barrel index.ts
  • Original files now re-export as @deprecated stubs

5. REDUCE COUPLING: Group date utilities into dateUtils/

  • Moved 6 date-related files into dateUtils/ subdirectory with barrel index.ts
  • Original files now re-export as @deprecated stubs

Verification

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):

Cluster Fingerprint Status
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

4 chain hashes — all match (multi-step flows verified):

Chain Hash Status
schema-type-inference 4vxu99p
schema-merge-and-hash 2eeryes
error-handling-pipeline 5kfikk3
ref-resolution-chain 4hs6g8l

Dual-Truth Verification:

  • KEBENARAN 1 (raw output) matches post-refactor output exactly
  • KEBENARAN 2 (fingerprints + chain hashes) matches post-refactor fingerprints exactly

Breaking Changes

None. All previously exported names remain accessible from @rjsf/utils. The @deprecated stubs and re-exports ensure full backward compatibility.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant