mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-24 23:32:19 +10:00
refactor(import): add v4section/v4url aliases, inline clamp wrappers, replace classes with fns
Finding 5: Introduce V4Url + V4Section<T> type aliases in reactive-resume-v4-json.tsx; collapse
310-line V4ResumeData type (13x 5-field section header, 11x {label,href}) into typed aliases.
Inferred shape is structurally identical.
Finding 6: Remove 9 single-caller clamp/pxToPt wrappers; replace compile-time constants
(rotation=0, sidebarWidth=35, shadowWidth=0, gapX=4, gapY=6) with literals; inline dynamic
calls (clamp(x, 32, 512) etc.) at the two body/heading typography call sites.
Finding 7: Convert three stateless single-method importer classes to plain functions.
Extract shared rethrowAsImportError() to error.ts, replacing triplicated ZodError catch blocks.
Update web import dialog + all in-package test files to use function API.
Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { ResumeData } from "@reactive-resume/schema/resume/data";
|
||||
import { flattenError, ZodError } from "zod";
|
||||
import { ZodError } from "zod";
|
||||
import { resumeDataSchema, sectionTypeSchema } from "@reactive-resume/schema/resume/data";
|
||||
import { rethrowAsImportError } from "./error";
|
||||
|
||||
const BUILT_IN_LAYOUT_SECTION_IDS = sectionTypeSchema.options.filter((section) => section !== "cover-letter");
|
||||
|
||||
@@ -62,18 +63,13 @@ function normalizeBuiltInSectionsInLayout(data: ResumeData): ResumeData {
|
||||
};
|
||||
}
|
||||
|
||||
export class ReactiveResumeJSONImporter {
|
||||
parse(json: string): ResumeData {
|
||||
try {
|
||||
const parsed = resumeDataSchema.parse(JSON.parse(json));
|
||||
return resumeDataSchema.parse(normalizeBuiltInSectionsInLayout(parsed));
|
||||
} catch (error) {
|
||||
if (error instanceof ZodError) {
|
||||
const errors = flattenError(error);
|
||||
throw new Error(JSON.stringify(errors));
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
// ponytail: stateless single-method class → plain function
|
||||
export function parseReactiveResumeJSON(json: string): ResumeData {
|
||||
try {
|
||||
const parsed = resumeDataSchema.parse(JSON.parse(json));
|
||||
return resumeDataSchema.parse(normalizeBuiltInSectionsInLayout(parsed));
|
||||
} catch (error) {
|
||||
if (error instanceof ZodError) rethrowAsImportError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user