Skip to content
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

[BUG] Enum with "DateTime" Value #1399

Open
francistogram opened this issue May 1, 2024 · 9 comments
Open

[BUG] Enum with "DateTime" Value #1399

francistogram opened this issue May 1, 2024 · 9 comments
Milestone

Comments

@francistogram
Copy link

francistogram commented May 1, 2024

I have an enum with values from Webflow's API with all of the possible types

enum WebflowFieldType {
  Image
  RichText
  Link
  Switch
  Reference
  PlainText
  VideoLink
  MultiImage
  Email
  Phone
  Number
  Option
  Color
  DateTime // Error is here
  File
  MultiReference
}

this worked in prisma.schema but with schema.zmodel I get this error

schema.zmodel:2344:3 - Expecting token of type '}' but found `DateTime`.
image

Seems like a bug cause there's no reason I shouldn't be able to have an enum named "DateTime" and it works in Prisma directly

@ymc9
Copy link
Member

ymc9 commented May 13, 2024

Fixed in 2.1.0

@ymc9 ymc9 closed this as completed May 13, 2024
@francistogram
Copy link
Author

Hey @ymc9 seems like I'm still running into the same issue on v2.1.1

image image

Looking at the test in the commit seems like it only tests for the name used as a field on a model vs an enum value that either

  1. I'm doing something wrong (very possible)
  2. The change fixed it for fields but not enum names

https://github.com/zenstackhq/zenstack/pull/1424/files#diff-7883ee0ee292eabaa7686a78d64d6af8bab02fcc845bb7352c3c4aee213c9512R19

@ymc9
Copy link
Member

ymc9 commented May 17, 2024

Oh, my apologies. You're right, the support was only added for model fields not enum fields ... Will make one more fix later today. Please also let me know if you're interested in making a PR 😄 @francistogram

@ymc9 ymc9 reopened this May 17, 2024
@francistogram
Copy link
Author

Happy to make a PR if ya don't mind pointing me on where to get started!

@ymc9
Copy link
Member

ymc9 commented May 17, 2024

Happy to make a PR if ya don't mind pointing me on where to get started!

Awesome! You can make a fork and create a PR based off the "dev" branch.

I believe the only change needed is this line here: https://github.com/zenstackhq/zenstack/blob/fea8ec71eac83e880112d64057355e8d2979bd18/packages/language/src/zmodel.langium#L212C10-L212C19

name=RegularID to name=RegularIDWithTypeName.

If you run pnpm build, a few other files (like ast.ts) will be auto-updated and should be included in the change.

If you want to test it out locally, you can pnpm build in the language package, and copy over the content of "dist" folder into your node_modules.

Let me know if you run into any hurdle.

@francistogram
Copy link
Author

I've made the change and was able to build it'

image

I am a little stuck with testing it locally

If you want to test it out locally, you can pnpm build in the language package, and copy over the content of "dist" folder into your node_modules.

Was initially thinking maybe I'd copy over the changed files e.g. ast.ts but that file doesn't seem to exist in the node_modules, closest thing I found was ast-utils.js

Any pointers here on what I might be missing?

image

@ymc9
Copy link
Member

ymc9 commented May 18, 2024

Good to know the progress @francistogram ! The npm package corresponding to the "language" pnpm package is actually "@zenstackhq/language". You should be able to find "ast.js" at "node_modules/@zenstackhq/language".

@francistogram
Copy link
Author

Ah the @ explains why I hadn't seen it in the folder 🤦‍♂️

Almost there I think, unclear to me if this is an issue related with my change or with my schema.zmodel as this is my first time setting up zenstack (this issue was preventing me from migrating easily)

image

These are some of the lines it's complaining about it you see any issues here?

image

I went ahead and put up a PR in case this helps in debugging if I did anything wrong

#1457

Thanks for the help here too!

@ymc9
Copy link
Member

ymc9 commented May 20, 2024

Ah the @ explains why I hadn't seen it in the folder 🤦‍♂️

Almost there I think, unclear to me if this is an issue related with my change or with my schema.zmodel as this is my first time setting up zenstack (this issue was preventing me from migrating easily)

image These are some of the lines it's complaining about it you see any issues here? image I went ahead and put up a PR in case this helps in debugging if I did anything wrong

#1457

Thanks for the help here too!

Hey @francistogram , the change looks cool to me. I've merged it. And then I found I overlooked that reference expressions also need to respect reserved type names, otherwise enum fields cannot be properly resolved. I've pushed an extra fix.

Will publish a patch release today. Thank you for the work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants