-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] feat: prisma enum from JS enum #48
base: main
Are you sure you want to change the base?
Conversation
I like this! Will have a closer look once I land, currently on flight. c: |
@Daidalos117 What do you think of the changes I've made? First, I ran the linter quickly and created some tests. The real changes were that now you can pass in raw it("Should allow importing JS/TS enums through `fromJSEnum`", async () => {
enum AvengersEnum {
THOR,
IRON_MAN,
CAPTAIN_AMERICA,
BLACK_WIDOW,
HULK,
}
const avengersEnum = new PrismaEnum("Avengers").fromJSEnum(AvengersEnum);
const asString = await avengersEnum.toString();
expect(asString).toMatchSnapshot();
}); This test produces the following output. enum Avengers {
THOR
IRON_MAN
CAPTAIN_AMERICA
BLACK_WIDOW
HULK
} while the following produces what follows. it("Should allow mapping values through `fromJSEnum`", async () => {
enum AvengersNameAcronymEnum {
THOR = "TO",
IRON_MAN = "TS",
CAPTAIN_AMERICA = "SR",
BLACK_WIDOW = "NR",
HULK = "BB",
}
const avengersNameAcronymEnum = new PrismaEnum("Avengers").fromJSEnum(
AvengersNameAcronymEnum
);
const asString = await avengersNameAcronymEnum.toString();
expect(asString).toMatchSnapshot();
}); enum Avengers {
THOR @map("TO")
IRON_MAN @map("TS")
CAPTAIN_AMERICA @map("SR")
BLACK_WIDOW @map("NR")
HULK @map("BB")
} Let me know if you're okay with these changes, and if you see foresee any issues. |
@ridafkih looks very good to me! Good idea with the mapping, I didn't think of that :) |
@Daidalos117 Awesome, this shouldn't affect any other implementations so it should be good to go! Think we're ready to get this in? |
Actually, going to write some quick tests for setting default values. |
Current status, looking into making enums on Schemix type-safe. |
@ridafkih, this sounds like something I would love to have. Which part is not currently type-safe? |
This is proposed functionality for importing TS/JS enums into the schemix/prisma. We can do this manually now, but it would be nice if the library could support this way out of the box.
IMHO it should be preferred way to import JS enums, because it has numerous advantages.
Maybe better safety could be implemented because of this, not really sure for now. What do you think?