Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
bketelsen authored and rawkode committed Sep 7, 2021
1 parent a9322ab commit 8f2f3dd
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 135 deletions.
3 changes: 1 addition & 2 deletions cmd/images/images_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (g *ImageScanner) Process(bloxConfig string) error {
}

func (g *ImageScanner) processImages(staticDir string) error {

g.logger.Debug("processing images", "dir", staticDir)
fi, err := os.Stat(staticDir)
if errors.Is(err, os.ErrNotExist) {
Expand Down Expand Up @@ -187,7 +186,7 @@ func main() {
logger: logger,
}
// pluginMap is the map of plugins we can dispense.
var pluginMap = map[string]plugin.Plugin{
pluginMap := map[string]plugin.Plugin{
"images": &plugins.PrebuildPlugin{Impl: imageScanner},
}

Expand Down
101 changes: 0 additions & 101 deletions cmd/remotes/remotes_impl.go

This file was deleted.

3 changes: 1 addition & 2 deletions content/postplugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func (s *Service) runPostPlugins() error {

post, err := s.Cfg.GetList("postbuild")
if err != nil {
return err
Expand Down Expand Up @@ -54,8 +53,8 @@ func (s *Service) runPostPlugins() error {

}
return nil

}

func (s *Service) callPostPlugin(name, executable string) error {
pterm.Info.Println("calling the plugin")
// Create an hclog.Logger
Expand Down
3 changes: 1 addition & 2 deletions content/preplugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func (s *Service) runPrePlugins() error {

pre, err := s.Cfg.GetList("prebuild")
if err != nil {
return err
Expand Down Expand Up @@ -53,8 +52,8 @@ func (s *Service) runPrePlugins() error {

}
return nil

}

func (s *Service) callPrePlugin(name, executable string) error {
// Create an hclog.Logger
logger := hclog.New(&hclog.LoggerOptions{
Expand Down
6 changes: 4 additions & 2 deletions content/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ type Service struct {
built bool
}

var prePluginMap map[string]plugin.Plugin
var postPluginMap map[string]plugin.Plugin
var (
prePluginMap map[string]plugin.Plugin
postPluginMap map[string]plugin.Plugin
)

func NewService(bloxConfig string, referentialIntegrity bool) (*Service, error) {
cfg, err := blox.NewConfig(BaseConfig)
Expand Down
4 changes: 0 additions & 4 deletions dogfood/blox.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
schemata_dir: "schemata"
template_dir: "data/tpl"
static_dir: "static"
prebuild: [ {
name: "images"
executable: "images_impl"
}]
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
github.com/graphql-go/graphql v0.7.9
github.com/graphql-go/handler v0.2.3
github.com/h2non/filetype v1.1.1
github.com/hashicorp/go-hclog v0.16.2 // indirect
github.com/hashicorp/go-hclog v0.16.2
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-plugin v1.4.2 // indirect
github.com/hashicorp/go-plugin v1.4.2
github.com/heimdalr/dag v1.0.1
github.com/otiai10/copy v1.5.0
github.com/pterm/pterm v0.12.13
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs=
github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
Expand Down Expand Up @@ -309,6 +308,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
97 changes: 78 additions & 19 deletions internal/cuedb/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (r *Engine) GetDataSet(name string) (DataSet, error) {

// GetDataSetByID returns a DataSet by its plural name.
func (r *Engine) GetDataSetByPlural(plural string) (DataSet, error) {

for _, dataSet := range r.dataSets {
if dataSet.metadata.Plural == strings.ToLower(plural) {
return dataSet, nil
Expand All @@ -201,6 +200,10 @@ func (d *DataSet) GetDefinitionPath() cue.Path {
return cue.ParsePath(d.cuePath.String() + "." + d.name)
}

func (d *DataSet) GetDefinitionPath2() cue.Path {
return cue.ParsePath(d.cuePath.String() + ".#" + d.name)
}

// GetInlinePath returns an inline cue.Path that can be used within a Cue document
// like "some: key: #Here"
func (d *DataSet) GetInlinePath() string {
Expand All @@ -225,7 +228,7 @@ func (r *Engine) RegisterSchema(cueString string) error {
if err != nil {
return err
}
schemaPath := cue.ParsePath(fmt.Sprintf(`%s."%s"."%s"`, schemataPathRoot, schemaMetadata.Namespace, schemaMetadata.Name))
schemaPath := cue.ParsePath(fmt.Sprintf(`%s."%s"."#%s"`, schemataPathRoot, schemaMetadata.Namespace, schemaMetadata.Name))

// First, Unify whatever schemas the users want. We'll
// do our best to extract whatever information from
Expand Down Expand Up @@ -431,33 +434,90 @@ func (r *Engine) GetOutput() (cue.Value, error) {
r.Database = r.Database.FillPath(cue.Path{}, inst.Value())

// begin flattening
/* if true { // TODO: flag later
err := r.flatten(dataSet)
if err != nil {
fmt.Println(err)
}
/*
err = r.flatten(dataSet)
if err != nil {
fmt.Println(err)
}
// end flattening
*/
// end flattening

}
return r.Database.LookupPath(cue.ParsePath("output")), nil
}

/*
func (r *Engine) flatten(d DataSet) error {
for _, rel := range d.relationships {
val := r.Database.LookupPath(d.GetDefinitionPath())

foreignTable, err := r.GetDataSet(strings.ToLower(rel))
if err != nil {
return err
fields, err := val.Fields(cue.All())
if err != nil {
return err
}

for fields.Next() {
relationship := fields.Value().Attribute("relationship")

if err = relationship.Err(); err == nil {
foreignTable, err := r.GetDataSet(strings.ToLower(relationship.Contents()))
if err != nil {
return err
}

foreignDataPath := foreignTable.CueDataPath()

fmt.Println(foreignDataPath)

// RI version
// newDefinition := d.GetSchemaCue()
fmt.Println(r.Database)
// schemata."namespace".Type
fmt.Printf("{data: _\n%s: flattened: data.%s[%s] }\n", d.GetInlinePath(), foreignTable.GetDataDirectory(), fields.Label())
inst, err := r.CueRuntime.Compile("", fmt.Sprintf("{data: _\n%s: { %s: _, flattened: data.%s[%s] } }\n", d.GetInlinePath(), fields.Label(), foreignTable.GetDataDirectory(), fields.Label()))
if err != nil {
fmt.Println("HELP: Broken:", err)
return err
}

fmt.Println(inst.Value())
r.Database = r.Database.FillPath(d.GetDefinitionPath2(), inst.Value())
fmt.Println(r.Database)

// profile?: string @relationship(Profile)

// inst, err := r.CueRuntime.Compile("", fmt.Sprintf("{data: _\nflattened: data.%s[%s] }", foreignTable.name, rel))
// newDefinition = newDefinition.Unify(??)

// fmt.Println("CUE")
// fmt.Println(newDefinition)
// fmt.Println(fmt.Sprintf("{data: _\n%s: %s}", d.GetDefinitionPath(), newDefinition))
}
// Step 3. Get foreign key dataset data path
foreignDataPath := foreignTable.CueDataPath()
fmt.Println(foreignDataPath)
// RI version
inst, err := r.CueRuntime.Compile("", fmt.Sprintf("{data: _\n%s: %s: %s%s: or([ for k, _ in data.%s {k}])}", dataSet.GetInlinePath(), dataSet.name, fields.Label(), optional, foreignTable.GetDataDirectory()))

/**
data:
people:
rawkode:
name: David
bketelsen:
name: Brian
new_content:
type:
people: rawkode
people: data.people[rawkode]
people: Unify()
**/

// if err != nil {
// fmt.Println(err)
// return err
// }

// r.Database = r.Database.FillPath(cue.Path{}, inst.Value())

// output version
inst, err := r.CueRuntime.Compile("", fmt.Sprintf("{%s: %s: _\noutput: %s: [ for key, val in %s.%s {val}]}", dataPathRoot, dataSet.metadata.Plural, dataSet.metadata.Plural, dataPathRoot, dataSet.metadata.Plural))
// inst, err := r.CueRuntime.Compile("", fmt.Sprintf("{%s: %s: _\noutput: %s: [ for key, val in %s.%s {val}]}", dataPathRoot, dataSet.metadata.Plural, dataSet.metadata.Plural, dataPathRoot, dataSet.metadata.Plural))

// need data source from RI version
// output from output version
Expand All @@ -470,4 +530,3 @@ func (r *Engine) flatten(d DataSet) error {
}
return nil
}
*/

0 comments on commit 8f2f3dd

Please sign in to comment.