refactor(configurator): type codec.ts and its call sites (SL-016/017/024/026) - #478
Conversation
…ared limit constants SL-017/024: replace `any` at codec.ts's 7 registry/options parameters and its two consumers (App.svelte, CheatsheetPanel.svelte) with new TokenRegistry, ApiIndex, SlashedClass and DecodeOptions interfaces in types.ts, so malformed JSON or option shapes are caught at compile time instead of silently no-op'ing at runtime. SL-026: document why MAX_VALUE_BYTES and MAX_ID share the same numeric value (65535) despite being independent limits, so a future edit doesn't assume they're the same constant in disguise.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoRefactor configurator codec typing and document shared 65535 limits
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
6 rules 1.
|
…re-link readers readShareFromHash()/readShareFromHashIfPresent() were typed to accept DecodeOptions.sanitize but always forced sanitizeValue internally (a CSS-injection safeguard that must not be caller-overridable) and silently discarded any options.sanitize passed in. Narrow their accepted options to a new ShareOptions type (isKnown only) so the signature matches actual behavior instead of advertising a knob that does nothing.
|
Good catch — fixed in 2af608f. Generated by Claude Code |
a5975d3
into
claude/pr-469-audit-rebase-ggp0e4
Summary
Fourth themed PR from the SLASHED technical-debt audit (PR #469), covering the codec.ts readability/type-safety group. Targets the long-lived integration branch
claude/pr-469-audit-rebase-ggp0e4per the agreed one-branch/multiple-PRs workflow (PR1–PR3 are still open on the same base and unmerged).configurator/src/lib/codec.ts.anyat codec.ts's 7 registry/options call sites (buildNameToIdMap,buildIdToNameMap,encode,decode×2 params,readShareFromHash×2 sites,readShareFromHashIfPresent) and its two consumers (App.svelte,CheatsheetPanel.svelte) with newTokenRegistry,ApiIndex,ApiIndexToken,SlashedClass,ClassIndex,TokenRegistryEntryandDecodeOptionsinterfaces added toconfigurator/src/types.ts. Malformed JSON/options shapes are now caught at compile time instead of silently no-op'ing at runtime.CheatsheetPanel.svelte's.filter()predicates over the raw JSON imports) are left with inferred types rather than an explicitApiIndexToken/SlashedClassannotation —svelte-checkrejected the explicit annotation there because the generated JSON'stier/kindfields are widened to plainstringby TS's JSON-module inference, which isn't assignable to the interfaces' literal-union fields. Inference gives the same safety without the mismatch.catch (err: any)indecode()is left as-is — SL-017/024 is about parameter/data typing, not catch-clause error typing.MAX_VALUE_BYTESandMAX_IDhappen to share the same value (65535) despite being independent limits, so a future edit doesn't conflate them.Test plan
npx tsc --noEmit— cleannpx svelte-check --tsconfig ./tsconfig.json— 0 errors, 0 warningsnpm run test:unit(vitest) — 72/72 passed, includingcodec.test.js,css.test.js,share.test.jsunchangedGenerated by Claude Code