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

feat: streaming update code generation for typescript #8988

Merged
merged 12 commits into from
Mar 20, 2024

Conversation

gt2345
Copy link
Contributor

@gt2345 gt2345 commented Mar 12, 2024

Description

Edit stream-gen to auto generate webui/react/src/services/stream/wire.ts

Test Plan

All streaming updates associated with projects should work as expected.

  • Edit/Archive a project
  • Move a project

Commentary (optional)

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

Ticket

Copy link

netlify bot commented Mar 12, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit 8711656
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/65f9c489b77c6200087b6312

@gt2345 gt2345 requested review from jgongd and removed request for kkunapuli March 12, 2024 16:22
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 38.46154% with 144 lines in your changes are missing coverage. Please review.

Project coverage is 47.72%. Comparing base (137bfcd) to head (8711656).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8988      +/-   ##
==========================================
- Coverage   47.74%   47.72%   -0.02%     
==========================================
  Files        1161     1161              
  Lines      143093   143253     +160     
  Branches     2370     2371       +1     
==========================================
+ Hits        68322    68371      +49     
- Misses      74618    74729     +111     
  Partials      153      153              
Flag Coverage Δ
backend 42.58% <0.00%> (-0.11%) ⬇️
harness 63.96% <ø> (ø)
web 40.90% <87.37%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
master/internal/stream/projects.go 77.01% <ø> (ø)
webui/react/src/services/stream/experiments.ts 75.75% <100.00%> (ø)
webui/react/src/services/stream/index.ts 100.00% <100.00%> (ø)
webui/react/src/stores/projects.tsx 96.93% <100.00%> (ø)
webui/react/src/services/stream/wire.ts 86.86% <86.86%> (ø)
master/cmd/stream-gen/main.go 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes

@gt2345 gt2345 requested a review from ashtonG March 12, 2024 18:21
"model.TaskID": {"string", ""},
"model.RequestID": {"number", "0"},
"*model.RequestID": {"number | undefined", "undefined"},
"model.State": {"string", ""},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified this part to use enum

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i wasn't clear -- shouldn't the generated typescript type be an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean we should use a enum like CommandState for model.State?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- if the field has constraints, we can communicate that through the type and make sure that we're handling all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, fixed!

@@ -27,7 +27,8 @@ export class ExperimentSpec extends StreamSpec {
return this.#id;
};

public toWire = (): Record<string, Array<number>> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public toWire = (): Record<string, any> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be Record<string, unknown>?

master/Makefile Outdated Show resolved Hide resolved

source := s.Args["source"]
entity := strings.ToLower(strings.TrimSuffix(s.Name, "SubscriptionSpec"))
caser := cases.Title(language.English)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If s.Name has more than one words, like s.Name = "StorageBackendSubscriptionSpec", I'm wondering if we should generate export class StorageBackendSpec extends StreamSpec instead of export class StoragebackendSpec extends StreamSpec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safer to just generate StorageBackendSpec because it's possible to have StorageBackendSubscriptionSpec and StorageSubscriptionSpec from backend and we don't want to risk duplicating class name when generating

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker: when s.name = "StorageBackendSubscriptionSpec", case.String(entity) = "Storagebackend".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I misunderstood your first comment, I get it now. More than one word can be tricky, thank you for pointing it out

@gt2345 gt2345 requested review from ashtonG and jgongd March 15, 2024 16:30
@@ -0,0 +1,100 @@
// Code generated by stream-gen. DO NOT EDIT.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember to mark this as ignored for eslint and prettier, and mark it as generated in .gitattributes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

Copy link
Contributor

@jgongd jgongd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gt2345 gt2345 requested a review from ashtonG March 19, 2024 19:39
@gt2345 gt2345 merged commit 0518785 into main Mar 20, 2024
68 of 81 checks passed
@gt2345 gt2345 deleted the gt/278-ts-code-generation branch March 20, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants