diff --git a/app/action/actionmap.go b/app/action/actionmap.go index 1f7af669..223d4bef 100644 --- a/app/action/actionmap.go +++ b/app/action/actionmap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (a *Action) ToMap() util.ValueMap { + return util.ValueMap{"id": a.ID, "svc": a.Svc, "modelID": a.ModelID, "userID": a.UserID, "act": a.Act, "content": a.Content, "note": a.Note, "created": a.Created} +} + //nolint:gocognit func FromMap(m util.ValueMap, setPK bool) (*Action, util.ValueMap, error) { ret := &Action{} diff --git a/app/comment/commentmap.go b/app/comment/commentmap.go index af662a54..bb65c129 100644 --- a/app/comment/commentmap.go +++ b/app/comment/commentmap.go @@ -5,6 +5,10 @@ import ( "github.com/kyleu/rituals/app/util" ) +func (c *Comment) ToMap() util.ValueMap { + return util.ValueMap{"id": c.ID, "svc": c.Svc, "modelID": c.ModelID, "userID": c.UserID, "content": c.Content, "html": c.HTML, "created": c.Created} +} + //nolint:gocognit func FromMap(m util.ValueMap, setPK bool) (*Comment, util.ValueMap, error) { ret := &Comment{} diff --git a/app/controller/clib/databasesql.go b/app/controller/clib/databasesql.go index 06ec2029..b496dad0 100644 --- a/app/controller/clib/databasesql.go +++ b/app/controller/clib/databasesql.go @@ -35,7 +35,7 @@ func DatabaseSQLRun(w http.ResponseWriter, r *http.Request) { defer func() { _ = tx.Rollback() }() var columns []string - results := [][]any{} + var results [][]any timer := util.TimerStart() result, err := svc.Query(ps.Context, sql, tx, ps.Logger) diff --git a/app/email/emailmap.go b/app/email/emailmap.go index d9e50f7d..be7b4790 100644 --- a/app/email/emailmap.go +++ b/app/email/emailmap.go @@ -2,6 +2,11 @@ package email import "github.com/kyleu/rituals/app/util" +//nolint:lll +func (e *Email) ToMap() util.ValueMap { + return util.ValueMap{"id": e.ID, "recipients": e.Recipients, "subject": e.Subject, "data": e.Data, "plain": e.Plain, "html": e.HTML, "userID": e.UserID, "status": e.Status, "created": e.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*Email, util.ValueMap, error) { ret := &Email{} extra := util.ValueMap{} diff --git a/app/enum/memberstatus.go b/app/enum/memberstatus.go index a166f3fa..fad16447 100644 --- a/app/enum/memberstatus.go +++ b/app/enum/memberstatus.go @@ -28,10 +28,14 @@ type MemberStatus struct { } func (m MemberStatus) String() string { + return m.Key +} + +func (m MemberStatus) NameSafe() string { if m.Name != "" { return m.Name } - return m.Key + return m.String() } func (m MemberStatus) Matches(xx MemberStatus) bool { diff --git a/app/enum/modelservice.go b/app/enum/modelservice.go index c7d60688..7901c0b3 100644 --- a/app/enum/modelservice.go +++ b/app/enum/modelservice.go @@ -34,10 +34,14 @@ type ModelService struct { } func (m ModelService) String() string { + return m.Key +} + +func (m ModelService) NameSafe() string { if m.Name != "" { return m.Name } - return m.Key + return m.String() } func (m ModelService) Matches(xx ModelService) bool { diff --git a/app/enum/sessionstatus.go b/app/enum/sessionstatus.go index 7178c341..d0c42d45 100644 --- a/app/enum/sessionstatus.go +++ b/app/enum/sessionstatus.go @@ -28,10 +28,14 @@ type SessionStatus struct { } func (s SessionStatus) String() string { + return s.Key +} + +func (s SessionStatus) NameSafe() string { if s.Name != "" { return s.Name } - return s.Key + return s.String() } func (s SessionStatus) Matches(xx SessionStatus) bool { diff --git a/app/estimate/ehistory/estimatehistorymap.go b/app/estimate/ehistory/estimatehistorymap.go index 9b3161a1..de737bb6 100644 --- a/app/estimate/ehistory/estimatehistorymap.go +++ b/app/estimate/ehistory/estimatehistorymap.go @@ -2,6 +2,10 @@ package ehistory import "github.com/kyleu/rituals/app/util" +func (e *EstimateHistory) ToMap() util.ValueMap { + return util.ValueMap{"slug": e.Slug, "estimateID": e.EstimateID, "estimateName": e.EstimateName, "created": e.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*EstimateHistory, util.ValueMap, error) { ret := &EstimateHistory{} extra := util.ValueMap{} diff --git a/app/estimate/emember/estimatemembermap.go b/app/estimate/emember/estimatemembermap.go index 0e46b1e1..0cee6d69 100644 --- a/app/estimate/emember/estimatemembermap.go +++ b/app/estimate/emember/estimatemembermap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (e *EstimateMember) ToMap() util.ValueMap { + return util.ValueMap{"estimateID": e.EstimateID, "userID": e.UserID, "name": e.Name, "picture": e.Picture, "role": e.Role, "created": e.Created, "updated": e.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*EstimateMember, util.ValueMap, error) { ret := &EstimateMember{} extra := util.ValueMap{} diff --git a/app/estimate/epermission/estimatepermissionmap.go b/app/estimate/epermission/estimatepermissionmap.go index 1eaa5220..76eac851 100644 --- a/app/estimate/epermission/estimatepermissionmap.go +++ b/app/estimate/epermission/estimatepermissionmap.go @@ -2,6 +2,10 @@ package epermission import "github.com/kyleu/rituals/app/util" +func (e *EstimatePermission) ToMap() util.ValueMap { + return util.ValueMap{"estimateID": e.EstimateID, "key": e.Key, "value": e.Value, "access": e.Access, "created": e.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*EstimatePermission, util.ValueMap, error) { ret := &EstimatePermission{} extra := util.ValueMap{} diff --git a/app/estimate/estimatemap.go b/app/estimate/estimatemap.go index 46f1ed20..18eb8466 100644 --- a/app/estimate/estimatemap.go +++ b/app/estimate/estimatemap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (e *Estimate) ToMap() util.ValueMap { + return util.ValueMap{"id": e.ID, "slug": e.Slug, "title": e.Title, "icon": e.Icon, "status": e.Status, "teamID": e.TeamID, "sprintID": e.SprintID, "choices": e.Choices, "created": e.Created, "updated": e.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Estimate, util.ValueMap, error) { ret := &Estimate{} extra := util.ValueMap{} diff --git a/app/estimate/story/storymap.go b/app/estimate/story/storymap.go index b33af865..4e1e800d 100644 --- a/app/estimate/story/storymap.go +++ b/app/estimate/story/storymap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (s *Story) ToMap() util.ValueMap { + return util.ValueMap{"id": s.ID, "estimateID": s.EstimateID, "idx": s.Idx, "userID": s.UserID, "title": s.Title, "status": s.Status, "finalVote": s.FinalVote, "created": s.Created, "updated": s.Updated} +} + //nolint:gocognit func FromMap(m util.ValueMap, setPK bool) (*Story, util.ValueMap, error) { ret := &Story{} diff --git a/app/estimate/story/vote/votemap.go b/app/estimate/story/vote/votemap.go index da2fa975..4e2354f9 100644 --- a/app/estimate/story/vote/votemap.go +++ b/app/estimate/story/vote/votemap.go @@ -2,6 +2,10 @@ package vote import "github.com/kyleu/rituals/app/util" +func (v *Vote) ToMap() util.ValueMap { + return util.ValueMap{"storyID": v.StoryID, "userID": v.UserID, "choice": v.Choice, "created": v.Created, "updated": v.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Vote, util.ValueMap, error) { ret := &Vote{} extra := util.ValueMap{} diff --git a/app/lib/database/debug.go b/app/lib/database/debug.go index dc700ad8..5ca4ab0c 100644 --- a/app/lib/database/debug.go +++ b/app/lib/database/debug.go @@ -70,11 +70,12 @@ func (s *DebugStatement) Complete(count int, msg string, err error, output ...an type DebugStatements []*DebugStatement func (d DebugStatements) Add(st *DebugStatement) DebugStatements { - if len(d) > MaxTracedStatements { - d = d[1:] + x := d[:] + if len(x) > MaxTracedStatements { + x = x[1:] } - d = append(d, st) - return d + x = append(x, st) + return x } func GetDebugStatements(key string) DebugStatements { diff --git a/app/lib/database/migrate/db.go b/app/lib/database/migrate/db.go index fa43e504..cf154a89 100644 --- a/app/lib/database/migrate/db.go +++ b/app/lib/database/migrate/db.go @@ -77,10 +77,10 @@ func newMigration(ctx context.Context, s *database.Service, e *Migration, tx *sq func maxMigrationIdx(ctx context.Context, s *database.Service, tx *sqlx.Tx, logger util.Logger) int { q := database.SQLSelectSimple("max(idx) as x", "migration", s.Type) - max, err := s.SingleInt(ctx, q, tx, logger) + mx, err := s.SingleInt(ctx, q, tx, logger) if err != nil { logger.Errorf("error getting migrations: %+v", err) return -1 } - return int(max) + return int(mx) } diff --git a/app/retro/feedback/feedbackmap.go b/app/retro/feedback/feedbackmap.go index 4c6e6c9d..765aced1 100644 --- a/app/retro/feedback/feedbackmap.go +++ b/app/retro/feedback/feedbackmap.go @@ -2,6 +2,11 @@ package feedback import "github.com/kyleu/rituals/app/util" +//nolint:lll +func (f *Feedback) ToMap() util.ValueMap { + return util.ValueMap{"id": f.ID, "retroID": f.RetroID, "idx": f.Idx, "userID": f.UserID, "category": f.Category, "content": f.Content, "html": f.HTML, "created": f.Created, "updated": f.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Feedback, util.ValueMap, error) { ret := &Feedback{} extra := util.ValueMap{} diff --git a/app/retro/retromap.go b/app/retro/retromap.go index 48c456fc..485b78b7 100644 --- a/app/retro/retromap.go +++ b/app/retro/retromap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (r *Retro) ToMap() util.ValueMap { + return util.ValueMap{"id": r.ID, "slug": r.Slug, "title": r.Title, "icon": r.Icon, "status": r.Status, "teamID": r.TeamID, "sprintID": r.SprintID, "categories": r.Categories, "created": r.Created, "updated": r.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Retro, util.ValueMap, error) { ret := &Retro{} extra := util.ValueMap{} diff --git a/app/retro/rhistory/retrohistorymap.go b/app/retro/rhistory/retrohistorymap.go index c1fefff3..a072d1e8 100644 --- a/app/retro/rhistory/retrohistorymap.go +++ b/app/retro/rhistory/retrohistorymap.go @@ -2,6 +2,10 @@ package rhistory import "github.com/kyleu/rituals/app/util" +func (r *RetroHistory) ToMap() util.ValueMap { + return util.ValueMap{"slug": r.Slug, "retroID": r.RetroID, "retroName": r.RetroName, "created": r.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*RetroHistory, util.ValueMap, error) { ret := &RetroHistory{} extra := util.ValueMap{} diff --git a/app/retro/rmember/retromembermap.go b/app/retro/rmember/retromembermap.go index 8c82ca80..8c645e27 100644 --- a/app/retro/rmember/retromembermap.go +++ b/app/retro/rmember/retromembermap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (r *RetroMember) ToMap() util.ValueMap { + return util.ValueMap{"retroID": r.RetroID, "userID": r.UserID, "name": r.Name, "picture": r.Picture, "role": r.Role, "created": r.Created, "updated": r.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*RetroMember, util.ValueMap, error) { ret := &RetroMember{} extra := util.ValueMap{} diff --git a/app/retro/rpermission/retropermissionmap.go b/app/retro/rpermission/retropermissionmap.go index db74dacc..329c8489 100644 --- a/app/retro/rpermission/retropermissionmap.go +++ b/app/retro/rpermission/retropermissionmap.go @@ -2,6 +2,10 @@ package rpermission import "github.com/kyleu/rituals/app/util" +func (r *RetroPermission) ToMap() util.ValueMap { + return util.ValueMap{"retroID": r.RetroID, "key": r.Key, "value": r.Value, "access": r.Access, "created": r.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*RetroPermission, util.ValueMap, error) { ret := &RetroPermission{} extra := util.ValueMap{} diff --git a/app/sprint/shistory/sprinthistorymap.go b/app/sprint/shistory/sprinthistorymap.go index ace6eb42..f84c0fcb 100644 --- a/app/sprint/shistory/sprinthistorymap.go +++ b/app/sprint/shistory/sprinthistorymap.go @@ -2,6 +2,10 @@ package shistory import "github.com/kyleu/rituals/app/util" +func (s *SprintHistory) ToMap() util.ValueMap { + return util.ValueMap{"slug": s.Slug, "sprintID": s.SprintID, "sprintName": s.SprintName, "created": s.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*SprintHistory, util.ValueMap, error) { ret := &SprintHistory{} extra := util.ValueMap{} diff --git a/app/sprint/smember/sprintmembermap.go b/app/sprint/smember/sprintmembermap.go index 4bc739c0..981418f7 100644 --- a/app/sprint/smember/sprintmembermap.go +++ b/app/sprint/smember/sprintmembermap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (s *SprintMember) ToMap() util.ValueMap { + return util.ValueMap{"sprintID": s.SprintID, "userID": s.UserID, "name": s.Name, "picture": s.Picture, "role": s.Role, "created": s.Created, "updated": s.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*SprintMember, util.ValueMap, error) { ret := &SprintMember{} extra := util.ValueMap{} diff --git a/app/sprint/spermission/sprintpermissionmap.go b/app/sprint/spermission/sprintpermissionmap.go index cc58b16d..a6c50a1f 100644 --- a/app/sprint/spermission/sprintpermissionmap.go +++ b/app/sprint/spermission/sprintpermissionmap.go @@ -2,6 +2,10 @@ package spermission import "github.com/kyleu/rituals/app/util" +func (s *SprintPermission) ToMap() util.ValueMap { + return util.ValueMap{"sprintID": s.SprintID, "key": s.Key, "value": s.Value, "access": s.Access, "created": s.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*SprintPermission, util.ValueMap, error) { ret := &SprintPermission{} extra := util.ValueMap{} diff --git a/app/sprint/sprintmap.go b/app/sprint/sprintmap.go index 41b821a7..07e6a729 100644 --- a/app/sprint/sprintmap.go +++ b/app/sprint/sprintmap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (s *Sprint) ToMap() util.ValueMap { + return util.ValueMap{"id": s.ID, "slug": s.Slug, "title": s.Title, "icon": s.Icon, "status": s.Status, "teamID": s.TeamID, "startDate": s.StartDate, "endDate": s.EndDate, "created": s.Created, "updated": s.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Sprint, util.ValueMap, error) { ret := &Sprint{} extra := util.ValueMap{} diff --git a/app/standup/report/reportmap.go b/app/standup/report/reportmap.go index a7f6f79c..bb7bb3e0 100644 --- a/app/standup/report/reportmap.go +++ b/app/standup/report/reportmap.go @@ -2,6 +2,11 @@ package report import "github.com/kyleu/rituals/app/util" +//nolint:lll +func (r *Report) ToMap() util.ValueMap { + return util.ValueMap{"id": r.ID, "standupID": r.StandupID, "day": r.Day, "userID": r.UserID, "content": r.Content, "html": r.HTML, "created": r.Created, "updated": r.Updated} +} + //nolint:gocognit func FromMap(m util.ValueMap, setPK bool) (*Report, util.ValueMap, error) { ret := &Report{} diff --git a/app/standup/standupmap.go b/app/standup/standupmap.go index 17cc7ceb..c77148a8 100644 --- a/app/standup/standupmap.go +++ b/app/standup/standupmap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (s *Standup) ToMap() util.ValueMap { + return util.ValueMap{"id": s.ID, "slug": s.Slug, "title": s.Title, "icon": s.Icon, "status": s.Status, "teamID": s.TeamID, "sprintID": s.SprintID, "created": s.Created, "updated": s.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Standup, util.ValueMap, error) { ret := &Standup{} extra := util.ValueMap{} diff --git a/app/standup/uhistory/standuphistorymap.go b/app/standup/uhistory/standuphistorymap.go index 2eb4e72e..377c862c 100644 --- a/app/standup/uhistory/standuphistorymap.go +++ b/app/standup/uhistory/standuphistorymap.go @@ -2,6 +2,10 @@ package uhistory import "github.com/kyleu/rituals/app/util" +func (s *StandupHistory) ToMap() util.ValueMap { + return util.ValueMap{"slug": s.Slug, "standupID": s.StandupID, "standupName": s.StandupName, "created": s.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*StandupHistory, util.ValueMap, error) { ret := &StandupHistory{} extra := util.ValueMap{} diff --git a/app/standup/umember/standupmembermap.go b/app/standup/umember/standupmembermap.go index 8864b6ea..aacce2b5 100644 --- a/app/standup/umember/standupmembermap.go +++ b/app/standup/umember/standupmembermap.go @@ -5,6 +5,11 @@ import ( "github.com/kyleu/rituals/app/util" ) +//nolint:lll +func (s *StandupMember) ToMap() util.ValueMap { + return util.ValueMap{"standupID": s.StandupID, "userID": s.UserID, "name": s.Name, "picture": s.Picture, "role": s.Role, "created": s.Created, "updated": s.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*StandupMember, util.ValueMap, error) { ret := &StandupMember{} extra := util.ValueMap{} diff --git a/app/standup/upermission/standuppermissionmap.go b/app/standup/upermission/standuppermissionmap.go index 3ec7f67e..7c5038a3 100644 --- a/app/standup/upermission/standuppermissionmap.go +++ b/app/standup/upermission/standuppermissionmap.go @@ -2,6 +2,10 @@ package upermission import "github.com/kyleu/rituals/app/util" +func (s *StandupPermission) ToMap() util.ValueMap { + return util.ValueMap{"standupID": s.StandupID, "key": s.Key, "value": s.Value, "access": s.Access, "created": s.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*StandupPermission, util.ValueMap, error) { ret := &StandupPermission{} extra := util.ValueMap{} diff --git a/app/team/teammap.go b/app/team/teammap.go index 8957bb39..8538a314 100644 --- a/app/team/teammap.go +++ b/app/team/teammap.go @@ -5,6 +5,10 @@ import ( "github.com/kyleu/rituals/app/util" ) +func (t *Team) ToMap() util.ValueMap { + return util.ValueMap{"id": t.ID, "slug": t.Slug, "title": t.Title, "icon": t.Icon, "status": t.Status, "created": t.Created, "updated": t.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*Team, util.ValueMap, error) { ret := &Team{} extra := util.ValueMap{} diff --git a/app/team/thistory/teamhistorymap.go b/app/team/thistory/teamhistorymap.go index a6ec02ed..46b36734 100644 --- a/app/team/thistory/teamhistorymap.go +++ b/app/team/thistory/teamhistorymap.go @@ -2,6 +2,10 @@ package thistory import "github.com/kyleu/rituals/app/util" +func (t *TeamHistory) ToMap() util.ValueMap { + return util.ValueMap{"slug": t.Slug, "teamID": t.TeamID, "teamName": t.TeamName, "created": t.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*TeamHistory, util.ValueMap, error) { ret := &TeamHistory{} extra := util.ValueMap{} diff --git a/app/team/tmember/teammembermap.go b/app/team/tmember/teammembermap.go index efa223cb..372ec6b1 100644 --- a/app/team/tmember/teammembermap.go +++ b/app/team/tmember/teammembermap.go @@ -5,6 +5,10 @@ import ( "github.com/kyleu/rituals/app/util" ) +func (t *TeamMember) ToMap() util.ValueMap { + return util.ValueMap{"teamID": t.TeamID, "userID": t.UserID, "name": t.Name, "picture": t.Picture, "role": t.Role, "created": t.Created, "updated": t.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*TeamMember, util.ValueMap, error) { ret := &TeamMember{} extra := util.ValueMap{} diff --git a/app/team/tpermission/teampermissionmap.go b/app/team/tpermission/teampermissionmap.go index 81d0406d..b1b66370 100644 --- a/app/team/tpermission/teampermissionmap.go +++ b/app/team/tpermission/teampermissionmap.go @@ -2,6 +2,10 @@ package tpermission import "github.com/kyleu/rituals/app/util" +func (t *TeamPermission) ToMap() util.ValueMap { + return util.ValueMap{"teamID": t.TeamID, "key": t.Key, "value": t.Value, "access": t.Access, "created": t.Created} +} + func FromMap(m util.ValueMap, setPK bool) (*TeamPermission, util.ValueMap, error) { ret := &TeamPermission{} extra := util.ValueMap{} diff --git a/app/user/usermap.go b/app/user/usermap.go index 1356645d..24023377 100644 --- a/app/user/usermap.go +++ b/app/user/usermap.go @@ -2,6 +2,10 @@ package user import "github.com/kyleu/rituals/app/util" +func (u *User) ToMap() util.ValueMap { + return util.ValueMap{"id": u.ID, "name": u.Name, "picture": u.Picture, "created": u.Created, "updated": u.Updated} +} + func FromMap(m util.ValueMap, setPK bool) (*User, util.ValueMap, error) { ret := &User{} extra := util.ValueMap{} diff --git a/app/util/http.go b/app/util/http.go index 8511fbf4..474ff6e6 100644 --- a/app/util/http.go +++ b/app/util/http.go @@ -27,6 +27,14 @@ func NewHTTPRequest(ctx context.Context, method string, url string, bodies ...io return &HTTPRequest{Request: ret} } +func NewHTTPGet(ctx context.Context, url string) *HTTPRequest { + return NewHTTPRequest(ctx, http.MethodGet, url, http.NoBody) +} + +func NewHTTPPost(ctx context.Context, url string, body io.Reader) *HTTPRequest { + return NewHTTPRequest(ctx, http.MethodPost, url, body) +} + func (r *HTTPRequest) WithHeader(k string, v string) *HTTPRequest { r.Header.Set(k, v) return r diff --git a/app/util/map.go b/app/util/map.go index 220b736c..45dda2f2 100644 --- a/app/util/map.go +++ b/app/util/map.go @@ -29,11 +29,9 @@ func (m ValueMap) Add(kvs ...any) { } func (m ValueMap) With(k string, v any) ValueMap { - if m == nil { - m = ValueMap{} - } - m[k] = v - return m + x := m.Clone() + x[k] = v + return x } func (m ValueMap) Merge(args ...ValueMap) ValueMap { @@ -97,8 +95,15 @@ func (m ValueMap) WithoutKeys(keys ...string) ValueMap { return ret } -func (m ValueMap) AsMap() map[string]any { - return m +func (m ValueMap) AsMap(simplify bool) map[string]any { + if !simplify { + return m + } + ret := make(map[string]any, len(m)) + for k, v := range m { + ret[k] = simplifyValue(k, v) + } + return ret } func (m ValueMap) String() string { diff --git a/app/util/mapparse.go b/app/util/mapparse.go index 0fd96543..7077ad02 100644 --- a/app/util/mapparse.go +++ b/app/util/mapparse.go @@ -1,10 +1,12 @@ package util import ( + "fmt" "time" "github.com/google/uuid" "github.com/pkg/errors" + "github.com/samber/lo" ) func (m ValueMap) ParseBool(path string, allowMissing bool, allowEmpty bool) (bool, error) { @@ -93,3 +95,50 @@ func parseMapField[T any](m ValueMap, path string, allowMissing bool, fn func(re } return fn(result) } + +func simplifyValue(k string, v any) any { + if v != nil { + switch t := v.(type) { + case []string: + v = ArrayFromAny[any](t) + case []int: + v = ArrayFromAny[any](t) + case []int64: + v = ArrayFromAny[any](t) + case []float32: + v = ArrayFromAny[any](t) + case []float64: + v = ArrayFromAny[any](t) + case uuid.UUID: + v = t.String() + case *uuid.UUID: + v = t.String() + case time.Time: + v = TimeToJS(&t) + case *time.Time: + v = TimeToJS(t) + case ValueMap: + v = t.AsMap(true) + case []ValueMap: + v = lo.Map(t, func(x ValueMap, _ int) any { + return x.AsMap(true) + }) + case []any: + v = lo.Map(t, func(x any, idx int) any { + return simplifyValue(fmt.Sprintf("%s[%d]", k, idx), x) + }) + case map[string]any: + case string: + case int: + case bool: + case float64: + default: + if s, ok := v.(fmt.Stringer); ok { + v = s.String() + } else { + println(fmt.Sprintf("encountered [%s] value of type [%T]", k, v)) + } + } + } + return v +} diff --git a/app/util/process.go b/app/util/process.go index eed0f806..300b9fa4 100644 --- a/app/util/process.go +++ b/app/util/process.go @@ -53,8 +53,8 @@ func RunProcess(cmd string, path string, in io.Reader, out io.Writer, er io.Writ } err = c.Wait() if err != nil { - ec, ok := err.(*exec.ExitError) //nolint:errorlint - if ok { + var ec *exec.ExitError + if ok := errors.As(err, &ec); ok { return ec.ExitCode(), nil } return -1, errors.Wrapf(err, "unable to run [%s] (%T)", cmd, err) diff --git a/app/util/timefmt.go b/app/util/timefmt.go index 5a475e47..ce14ccab 100644 --- a/app/util/timefmt.go +++ b/app/util/timefmt.go @@ -123,7 +123,7 @@ func FormatSecondsFull(x float64) string { } f("second", seconds) if fractionalPart > 0 { - result = append(result, fmt.Sprintf("%d milliseconds", int(math.Round((fractionalPart*1000))))) + result = append(result, fmt.Sprintf("%d milliseconds", int(math.Round(fractionalPart*1000)))) } return strings.Join(result, ", ") } diff --git a/client/package.json b/client/package.json index 07f0a96c..74da4cf5 100644 --- a/client/package.json +++ b/client/package.json @@ -1,7 +1,7 @@ { "name": "client", "version": "1.0.0", - "type":"module", + "type": "module", "dependencies": { "esbuild": "^0.17.15" }, diff --git a/tools/release/.goreleaser.yml b/tools/release/.goreleaser.yml index 88e7e2c9..2cd55509 100644 --- a/tools/release/.goreleaser.yml +++ b/tools/release/.goreleaser.yml @@ -73,6 +73,8 @@ release: # $PF_SECTION_START(releasefiles)$ # $PF_SECTION_END(releasefiles)$ +report_sizes: true + snapcrafts: - publish: false