Skip to content

Commit

Permalink
Remove native CUE schema sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
sam boyer committed Jun 8, 2023
1 parent 423667a commit fd8b835
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type maybeLineage struct {
}

func (ml *maybeLineage) checkGoValidity(cfg *bindConfig) error {
schiter, err := ml.uni.LookupPath(cue.MakePath(cue.Hid("_sortedSchemas", "github.com/grafana/thema"))).List()
// schiter, err := ml.uni.LookupPath(cue.MakePath(cue.Hid("_sortedSchemas", "github.com/grafana/thema"))).List()
schiter, err := ml.uni.LookupPath(cue.MakePath(cue.Str("schemas"))).List()
if err != nil {
panic(fmt.Sprintf("unreachable - should have already verified schemas field exists and is list: %+v", cerrors.Details(err, nil)))
}
Expand Down
13 changes: 7 additions & 6 deletions lineage.cue
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,20 @@ import (

_atLeastOneSchema: len(schemas) > 0

_schemas: [...]
SS=_schemas: [...]
if _atLeastOneSchema == true {
_schemas: schemas
}

if _atLeastOneSchema == false {
_schemas: [#SchemaDef & {version: [0, 0]}]
}

SS=_sortedSchemas: list.Sort(_schemas, {
x: #SchemaDef
y: #SchemaDef
less: (_cmpSV & {l: x.version, r: y.version}).out == -1
}) & list.MinItems(1)
// SS=_sortedSchemas: list.Sort(_schemas, {
// x: #SchemaDef
// y: #SchemaDef
// less: (_cmpSV & {l: x.version, r: y.version}).out == -1
// }) & list.MinItems(1)

// TODO add informative validation that exactly the expected set of explicit lenses exist
_sortedLenses: list.Sort(lenses, {
Expand Down
5 changes: 3 additions & 2 deletions lineage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func TestBindLineage(t *testing.T) {
if err != nil {
tc.Fatalf("error binding lineage: %+v", err)
}

sspath := cue.MakePath(cue.Hid("_sortedSchemas", "github.com/grafana/thema"))
// schemaselem := cue.Hid("_sortedSchemas", "github.com/grafana/thema")
schemaselem := cue.Str("schemas")
sspath := cue.MakePath(schemaselem)
slen, err := lin.Underlying().LookupPath(sspath).Len().Int64()
if err != nil {
tc.Fatal("error getting schemas len", err)
Expand Down

0 comments on commit fd8b835

Please sign in to comment.