flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[TS] Add reflection library for typescript

Open jkuszmaul opened this issue 3 years ago • 8 comments

This is a potential upstreaming of https://github.com/frc971/971-Robot-Code/blob/master/aos/network/www/reflection.ts -- I'm not sure if it's exactly something we want to incorporate into the flatbuffers repo itself, but I wanted to at least get this code visible for anyone who might want it.

This does a few things:

  • Adds a reflection.ts that depends on the --ts-flat-file codegen for reflection.fbs, presuming that the generated code is available in the flatbuffers_reflection package.
  • Make bazel rules for the aforementioned reflection.ts, also making it available in the flatbuffers_reflection package.
  • Add a rudimentary test (using bazel's nodejs_test rule) for the reflection code.

This only really works great within the Bazel ecosystem (I haven't worked out the imports for more typical setups), but I wanted to get this code cleaned up and figured I'd get at least some visibility to upstream in case we do want to pull it into the main repo.

Note that this also includes #7300, because I've no clue how you're supposed to handle dependent PR's in github these days.

Alternative approach for making this accessible to people (without the weird flatbuffers_reflection package that only even exists if using the bazel rules) is to check in a codegen'd reflection_generated.ts (like we do with C++) and then put it and the new reflection.ts in the main flatbuffers library. That does somewhat offend my sensibilities since it checks in generated code, but would probably be more helpful to people. It's easy to change either way.

jkuszmaul avatar May 10 '22 23:05 jkuszmaul

@dbaileychess not sure who to ask for review on this, but the code itself is in a state where it can be reviewed. I don't really thing it's current form is exactly what we want in terms of package management for how to provide the reflection library to users, but since I'm not a heavy typescript user myself, I'm looking for feedback on what would make sense before committing to something.

It seems like the current options are to either: (a) Slightly tweak what I have now so that things work for non-bazel users, and keep a separate flatbuffers_reflection (or similarly named) package that is separate from the regular flatbuffers package, and contains the reflection_generated.ts and reflection.ts. This simplifies some of the code (e.g., don't have to worry about circular dependencies in the codegen), but requires creating a second npm package. (b) Put reflection_generated.ts and reflection.ts into the flatbuffers package itself. This may require changes to reflection_generated.ts since currently it attempts to import flatbuffers. I could make those changes manually (obnoxious to maintain in the future) or do something more complex in the codegen (also obnoxious to write and maintain).

jkuszmaul avatar Jun 22 '22 17:06 jkuszmaul

@jkuszmaul Sorry for the delay, can you fix the merge and I can take a look.

dbaileychess avatar Aug 06 '22 05:08 dbaileychess

@dbaileychess conflicts resolved. My questions from https://github.com/google/flatbuffers/pull/7301#issuecomment-1163419068 stand, although that doesn't really affect the code itself.

jkuszmaul avatar Aug 06 '22 21:08 jkuszmaul

@jkuszmaul Do you mind if I wait on this until I get v2.0.7 out? Hopefully in the next week or so.

dbaileychess avatar Aug 14 '22 19:08 dbaileychess

@dbaileychess no problem

jkuszmaul avatar Aug 15 '22 00:08 jkuszmaul

@jkuszmaul Feel free to update and let me know when its ready.

dbaileychess avatar Aug 30 '22 06:08 dbaileychess

@dbaileychess merged latest master (I've been a bit distracted lately--sorry for the slow response). My early comments/questions about package management still apply.

jkuszmaul avatar Sep 10 '22 20:09 jkuszmaul

@bjornharrtell Can you respond to the package manage questions above? Basically, how would we package the reflection library of TS.

dbaileychess avatar Sep 13 '22 07:09 dbaileychess

Converting to draft so I don't keep opening this up to look at the progress :) @bjornharrtell and @jkuszmaul Feel free to reopen/close as you see fit

dbaileychess avatar Jan 07 '23 18:01 dbaileychess

Converting to draft so I don't keep opening this up to look at the progress :) @bjornharrtell and @jkuszmaul Feel free to reopen/close as you see fit

This seems to be rather bazel specific so I cannot at this point give much feedback. However, it seems it also relies on pre https://github.com/google/flatbuffers/pull/7510 behaviour so should probably revisited after we can get that in.

bjornharrtell avatar Jan 07 '23 19:01 bjornharrtell

I haven't had the time to come back to this in a bit. I'll revive it when I next find myself irritated by the fact that I'm maintaining a local diff because of this.

jkuszmaul avatar Jan 09 '23 19:01 jkuszmaul

@jkuszmaul I'm just closing it so its not on the list of PRs, feel free to reopen later.

dbaileychess avatar Mar 03 '23 06:03 dbaileychess