851: Move leetcode enum to pretty name lookup to backend type generator#869
851: Move leetcode enum to pretty name lookup to backend type generator#869angelayu0530 wants to merge 3 commits intomainfrom
Conversation
Available PR Commands
See: https://github.com/tahminator/codebloom/wiki/CI-Commands |
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement, Refactoring Description
Diagram Walkthroughflowchart LR
A[TopicMetadataObject.java]
B[TopicMetadataList.java]
C[ComplexJSTypesGenerator.java]
D[js/src/lib/api/types/complex.ts (Generated)]
E[js/src/lib/api/utils/index.ts]
F[js/src/lib/api/utils/types.ts]
G[js/src/lib/api/utils/metadata/topic/index.ts (Removed)]
A & B -- "Define topic metadata" --> C
C -- "Generates TypeScript" --> D
D -- "Imports generated types" --> E
D -- "Imports generated types" --> F
G -- "Replaced by generated types" --> D
|
| Relevant files | |||
|---|---|---|---|
| New feature | |||
| Code generation | 1 files
| ||
| Configuration | |||
| Refactoring | 1 files
| ||
| Code removal | 1 files
| ||
| Type definition | 1 files
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
...in/java/org/patinanetwork/codebloom/utilities/generator/complex/ComplexJSTypesGenerator.java
Show resolved
Hide resolved
6ef5873 to
26da6ab
Compare
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement, Refactoring Description
Diagram Walkthroughflowchart LR
JavaBackend[Backend Java Classes] --> Generator[ComplexJSTypesGenerator];
Generator -- Generates --> TSFile[js/src/lib/api/types/complex.ts];
OldFrontendFile[js/src/lib/api/utils/metadata/topic/index.ts] -- Removed --> X;
Frontend[Frontend Code] --> TSFile;
|
| Relevant files | |||
|---|---|---|---|
| New feature | |||
| Code generation | 1 files
| ||
| Configuration changes | |||
| Refactoring | 1 files
| ||
| Code removal | 1 files
| ||
| Type definition | 1 files
|
|
/deploy |
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A[TopicMetadataObject.java] --> B[TopicMetadataList.java]
B --> C[ComplexJSTypesGenerator.java]
C -- "Generates TS Type & Constant" --> D[js/src/lib/api/types/complex.ts (generated)]
E[js/src/lib/api/utils/metadata/topic/index.ts] -- "Removed" --> F[Frontend Cleanup]
D --> G[js/src/lib/api/utils/index.ts]
D --> H[js/src/lib/api/utils/types.ts]
|
| Relevant files | |||||||
|---|---|---|---|---|---|---|---|
| New feature | |||||||
| Enhancement | 3 files
| ||||||
| Configuration changes | 1 files
| ||||||
| Code removal | 1 files
| ||||||
| Type definition | 1 files
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
|
/deploy |
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement, Refactoring Description
Diagram Walkthroughflowchart LR
JavaBackend["Java Backend (TopicMetadataList)"] --> TSGenerator["TypeScript Generator (ComplexJSTypesGenerator)"];
TSGenerator -- "Generates TS types" --> Frontend["Frontend (js/src/lib/api/utils)"];
OldFrontend["Old Frontend Topic Metadata"] -- "Replaced by" --> JavaBackend;
|
| Relevant files | |||
|---|---|---|---|
| New feature | |||
| Enhancement | |||
| Refactoring | |||
| Code removal | 1 files
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
...main/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataList.java
Show resolved
Hide resolved
|
/deploy |
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A[Backend Java Code] -- "Defines Topic Metadata" --> B[TopicMetadataList.java]
B -- "Used by" --> C[ComplexJSTypesGenerator.java]
C -- "Generates TypeScript" --> D[js/src/lib/api/types/complex.ts]
D -- "Consumed by Frontend" --> E[js/src/lib/api/utils/index.ts]
F[Old Frontend Topic Metadata] -- "Removed" --> G[No longer exists]
|
| Relevant files | |||||||
|---|---|---|---|---|---|---|---|
| New feature | |||||||
| Enhancement | 3 files
| ||||||
| Configuration changes | 1 files
| ||||||
| Code removal | 1 files
| ||||||
| Type definition | 1 files
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A[Backend TopicMetadataList] --> B{ComplexJSTypesGenerator};
B -- "Generates TS" --> C[Frontend Topic Metadata];
|
| Relevant files | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 5 files
| ||||||||||
| Configuration changes | 1 files
| ||||||||||
| Refactoring | 1 files
| ||||||||||
| Typesafety | 1 files
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/utilities/generator/complex/ComplexJSTypesGenerator.java
Show resolved
Hide resolved
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
|
/deploy |
fed5882 to
67e4383
Compare
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A[LeetcodeTopicEnum] --> B{TopicMetadataList.java};
B -- "defines metadata for" --> C[TopicMetadataObject.java];
B -- "provides data to" --> D[ComplexJSTypesGenerator.java];
D -- "generates TypeScript types" --> E[js/src/lib/api/types/complex.ts];
E -- "consumed by" --> F[js/src/lib/api/utils/index.ts];
E -- "consumed by" --> G[js/src/lib/api/utils/types.ts];
H[js/src/lib/api/utils/metadata/topic/index.ts] -- "removed" --> I[Frontend Cleanup];
|
| Relevant files | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 5 files
| ||||||||||
| Tests | 1 files
| ||||||||||
| Configuration changes | 1 files
| ||||||||||
| Cleanup | 1 files
| ||||||||||
| Typesafety | 1 files
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/utilities/generator/complex/ComplexJSTypesGenerator.java
Show resolved
Hide resolved
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
changes slight changes
tests
Title851: Move leetcode enum to pretty name lookup to backend type generator PR TypeEnhancement, Refactoring, Tests Description
Diagram Walkthroughflowchart LR
JavaTopicMetadata["Java Topic Metadata (TopicMetadataList, TopicMetadataObject)"] --> ComplexJSTypesGenerator["ComplexJSTypesGenerator"]
ComplexJSTypesGenerator -- "Generates TS types" --> GeneratedTSComplexTypes["Generated TS Complex Types (complex.ts)"]
GeneratedTSComplexTypes -- "Used by" --> FrontendUtils["Frontend Utilities (index.ts, types.ts)"]
|
| Relevant files | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 6 files
| ||||||||||||
| Tests | 1 files
| ||||||||||||
| Refactoring |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
...in/java/org/patinanetwork/codebloom/common/db/models/question/topic/TopicMetadataObject.java
Show resolved
Hide resolved
...in/java/org/patinanetwork/codebloom/utilities/generator/complex/ComplexJSTypesGenerator.java
Show resolved
Hide resolved
|
/deploy |
There was a problem hiding this comment.
Move this to the org.patinanetwork.codebloom.shared package
| public static final String TS_TYPE = "export type TagMetadataObject = {\n" | ||
| + " shortName: string;\n" | ||
| + " name: string;\n" | ||
| + " apiKey: string;\n" | ||
| + " alt: string;\n" | ||
| + "};\n\n"; |
There was a problem hiding this comment.
make this a multi line string so it's easier to edit & parse (with .stripIdent() to normalize the zero-point pad size)
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class TopicMetadataObject { | ||
| public static final String TS_TYPE = | ||
| "export type TopicMetadataObject = {\n" + " name: string;\n" + " aliases?: string[];\n" + "};\n\n"; |
There was a problem hiding this comment.
make this a multi line string so it's easier to edit & parse (with
.stripIdent()to normalize the zero-point pad size)
| private static final String EXPORT_TYPE_PREFIX = "export type "; | ||
| private static final String TYPE_BODY_OPEN = " = {\n"; | ||
| private static final String CLOSE_BLOCK = "};\n\n"; | ||
| private static final String RECORD_BODY_OPEN = "> = {\n"; |
| @Getter | ||
| @Builder | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class TopicMetadataObject { |
There was a problem hiding this comment.
it might be good to create an interface called TypableObject that exports a getTsType method so we can inforce a shared way to get the type out (as well as some useful documentation about how it should work)
| } else if (generator.getDataShape() == DataShape.ENUM_TO_STRING_VALUE_MAP) { | ||
| generateEnumToStringValueMap(generator); | ||
| } else if (generator.getDataShape() == DataShape.ENUM_TO_TAG_METADATA) { | ||
| generateEnumToTagMetadata(generator); |
| /** | ||
| * Converts Jackson pretty-printed JSON to TypeScript object literal style (unquoted keys, no space before colon). | ||
| */ | ||
| private String jsonToTypeScript(String json) { | ||
| return json.replaceAll("\"(\\w+)\" : ", "$1: "); | ||
| } |
There was a problem hiding this comment.
i think you can just make a call to prettier on that specific file after writing to it and it will handle the rest / keep more complexity out of the type generator
851
Description of changes
Checklist before review
Screenshots
Dev
https://github.com/user-attachments/assets/e4f9cd77-b09d-4dfa-8554-06e18d3ec2ea


Staging
Screen.Recording.2026-03-19.at.1.45.50.PM.mov