Skip to content

Commit

Permalink
chore: correct duration type in client sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
davenewza committed Feb 17, 2025
1 parent 442b84e commit d41fa87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions node/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func writeClientTypes(w *codegen.Writer, schema *proto.Schema, api *proto.Api) {

for _, a := range proto.GetActionNamesForApi(schema, api) {
action := schema.FindAction(a)
writeResultInfoInterface(w, schema, action)
writeResultInfoInterface(w, schema, action, true)
}

// writing embedded response types
Expand Down Expand Up @@ -278,7 +278,7 @@ func toClientActionReturnType(model *proto.Model, action *proto.Action) string {

if len(action.Facets) > 0 {
resultInfo := fmt.Sprintf("%sResultInfo", strcase.ToCamel(action.Name))
return "{ results: " + respName + "[], " + resultInfo + ": " + resultInfo + ", pageInfo: PageInfo }"
return "{ results: " + respName + "[], resultInfo: " + resultInfo + ", pageInfo: PageInfo }"
} else {
return "{ results: " + respName + "[], pageInfo: PageInfo }"
}
Expand Down
10 changes: 7 additions & 3 deletions node/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func generateSdkPackage(schema *proto.Schema, cfg *config.ProjectConfig) codegen
}
}

func writeResultInfoInterface(w *codegen.Writer, schema *proto.Schema, action *proto.Action) {
func writeResultInfoInterface(w *codegen.Writer, schema *proto.Schema, action *proto.Action, isClientPackage bool) {
facetFields := proto.FacetFields(schema, action)
if len(facetFields) == 0 {
return
Expand All @@ -185,7 +185,11 @@ func writeResultInfoInterface(w *codegen.Writer, schema *proto.Schema, action *p
case proto.Type_TYPE_TIMESTAMP, proto.Type_TYPE_DATE, proto.Type_TYPE_DATETIME:
w.Writef("%s: { min: Date, max: Date };\n", field.Name)
case proto.Type_TYPE_DURATION:
w.Writef("%s: { min: runtime.Duration, max: runtime.Duration, avg: runtime.Duration };\n", field.Name)
if isClientPackage {
w.Writef("%s: { min: DurationString, max: DurationString, avg: DurationString };\n", field.Name)
} else {
w.Writef("%s: { min: runtime.Duration, max: runtime.Duration, avg: runtime.Duration };\n", field.Name)
}
}
}

Expand Down Expand Up @@ -1770,7 +1774,7 @@ func writeTestingTypes(w *codegen.Writer, schema *proto.Schema) {
for _, model := range schema.Models {
for _, action := range model.Actions {
if action.Type == proto.ActionType_ACTION_TYPE_LIST {
writeResultInfoInterface(w, schema, action)
writeResultInfoInterface(w, schema, action, false)
}
}
}
Expand Down

0 comments on commit d41fa87

Please sign in to comment.