Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tliron committed Sep 11, 2023
1 parent a5359db commit ff2eeda
Show file tree
Hide file tree
Showing 34 changed files with 136 additions and 128 deletions.
6 changes: 3 additions & 3 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ Controlling the Output
----------------------

The default output format is YAML but other formats are supported: JSON (and
[ARD](https://github.com/tliron/kutil/tree/master/ard/)-compatible JSON), XML, CBOR,
and MessagePack. Here's ARD-compatible JSON:
[ARD](https://github.com/tliron/kutil/tree/master/ard/)-compatible extended JSON), XML,
CBOR, and MessagePack. Here's ARD-compatible XJSON:

puccini-tosca compile examples/tosca/descriptions.yaml --format=cjson
puccini-tosca compile examples/tosca/descriptions.yaml --format=xjson

By default the output is nicely indented and and colorized for human readability. You can
turn off prettification if you're interested in the most compact output:
Expand Down
24 changes: 13 additions & 11 deletions clout/clout.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ type MarshalableCloutStringMaps Clout
func (self *Clout) MarshalableStringMaps() any {
return &MarshalableCloutStringMaps{
Version: self.Version,
Metadata: ard.EnsureStringMaps(self.Metadata),
Properties: ard.EnsureStringMaps(self.Properties),
Metadata: ard.CopyMapsToStringMaps(self.Metadata).(ard.StringMap),
Properties: ard.CopyMapsToStringMaps(self.Properties).(ard.StringMap),
Vertexes: self.Vertexes,
}
}

// json.Marshaler interface
// ([json.Marshaler] interface)
func (self *Clout) MarshalJSON() ([]byte, error) {
// JavaScript requires keys to be strings, so we would lose complex keys
return json.Marshal(self.MarshalableStringMaps())
Expand All @@ -55,10 +55,10 @@ func (self *Clout) Resolve() error {
return fmt.Errorf("unsupported Clout version: %q", self.Version)
}

return self.ResolveTopology()
return self.ResolveEdges()
}

func (self *Clout) ResolveTopology() error {
func (self *Clout) ResolveEdges() error {
for id, vertex := range self.Vertexes {
vertex.Clout = self
vertex.ID = id
Expand All @@ -78,11 +78,13 @@ func (self *Clout) ResolveTopology() error {
return nil
}

// Creates a copy of the Clout in which ARD is used for all data.
func (self *Clout) Copy() (*Clout, error) {
return self.copy(true)
}

func (self *Clout) SimpleCopy() *Clout {
// Creates a copy of the Clout in which non-ARD data is left as is.
func (self *Clout) CopyAsIs() *Clout {
clout, _ := self.copy(false)
return clout
}
Expand All @@ -95,8 +97,8 @@ func (self *Clout) copy(toArd bool) (*Clout, error) {
var err error
if clout.Vertexes, err = self.Vertexes.copy(toArd); err == nil {
if toArd {
if metadata, err := ard.NormalizeStringMapsCopyToARD(self.Metadata); err == nil {
if properties, err := ard.NormalizeStringMapsCopyToARD(self.Properties); err == nil {
if metadata, err := ard.ValidCopyMapsToStringMaps(self.Metadata, nil); err == nil {
if properties, err := ard.ValidCopyMapsToStringMaps(self.Properties, nil); err == nil {
clout.Metadata = metadata.(ard.StringMap)
clout.Properties = properties.(ard.StringMap)
} else {
Expand All @@ -106,14 +108,14 @@ func (self *Clout) copy(toArd bool) (*Clout, error) {
return nil, err
}
} else {
clout.Metadata = ard.SimpleCopy(self.Metadata).(ard.StringMap)
clout.Properties = ard.SimpleCopy(self.Properties).(ard.StringMap)
clout.Metadata = ard.CopyMapsToStringMaps(self.Metadata).(ard.StringMap)
clout.Properties = ard.CopyMapsToStringMaps(self.Properties).(ard.StringMap)
}
} else {
return nil, err
}

if err := clout.ResolveTopology(); err == nil {
if err := clout.ResolveEdges(); err == nil {
return &clout, nil
} else {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions clout/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (self *Edge) Marshalable(stringMaps bool) any {

if stringMaps {
return &MarshalableEdgeStringMaps{
Metadata: ard.EnsureStringMaps(self.Metadata),
Properties: ard.EnsureStringMaps(self.Properties),
Metadata: ard.CopyMapsToStringMaps(self.Metadata).(ard.StringMap),
Properties: ard.CopyMapsToStringMaps(self.Properties).(ard.StringMap),
TargetID: targetID,
}
} else {
Expand All @@ -104,30 +104,30 @@ func (self *Edge) Unmarshal(f func(m *MarshalableEdge) error) error {
return nil
}

// json.Marshaler interface
// ([json.Marshaler] interface)
func (self *Edge) MarshalJSON() ([]byte, error) {
// JavaScript requires keys to be strings, so we would lose complex keys
return json.Marshal(self.Marshalable(true))
}

// yaml.Marshaler interface
// ([yaml.Marshaler] interface)
func (self *Edge) MarshalYAML() (any, error) {
return self.Marshalable(false), nil
}

// cbor.Marshaler interface
// ([cbor.Marshaler] interface)
func (self *Edge) MarshalCBOR() ([]byte, error) {
return cbor.Marshal(self.Marshalable(false))
}

// msgpack.Marshaler interface
// ([msgpack.Marshaler] interface)
func (self *Edge) MarshalMsgpack() ([]byte, error) {
return msgpack.Marshal(self.Marshalable(false))
}

// ard.ToARD interface
// ([ard.ToARD] interface)
func (self *Edge) ToARD(reflector *ard.Reflector) (any, error) {
return reflector.Unpack(self.Marshalable(false))
return reflector.Unpack(self.Marshalable(false), false)
}

// json.Unmarshaler interface
Expand Down Expand Up @@ -164,8 +164,8 @@ func (self *Edge) copy(toArd bool) (*Edge, error) {
}

if toArd {
if metadata, err := ard.NormalizeStringMapsCopyToARD(self.Metadata); err == nil {
if properties, err := ard.NormalizeStringMapsCopyToARD(self.Properties); err == nil {
if metadata, err := ard.ValidCopyMapsToStringMaps(self.Metadata, nil); err == nil {
if properties, err := ard.ValidCopyMapsToStringMaps(self.Properties, nil); err == nil {
edge.Metadata = metadata.(ard.StringMap)
edge.Properties = properties.(ard.StringMap)
} else {
Expand All @@ -175,8 +175,8 @@ func (self *Edge) copy(toArd bool) (*Edge, error) {
return nil, err
}
} else {
edge.Metadata = ard.SimpleCopy(self.Metadata).(ard.StringMap)
edge.Properties = ard.SimpleCopy(self.Properties).(ard.StringMap)
edge.Metadata = ard.CopyMapsToStringMaps(self.Metadata).(ard.StringMap)
edge.Properties = ard.CopyMapsToStringMaps(self.Properties).(ard.StringMap)
}

return &edge, nil
Expand Down
10 changes: 5 additions & 5 deletions clout/js/clout-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (self *CloutAPI) Load(context contextpkg.Context, data any) (*CloutAPI, err
}

case ard.Map:
if clout, err = cloutpkg.Parse(data_); err != nil {
if clout, err = cloutpkg.Unpack(data_); err != nil {
return nil, err
}

Expand Down Expand Up @@ -165,22 +165,22 @@ func (self *CloutAPI) Unwrap(value any) any {
}
}

// json.Marshaler interface
// ([json.Marshaler] interface)
func (self *CloutAPI) MarshalJSON() ([]byte, error) {
return json.Marshal(self.Clout)
}

// yaml.Marshaler interface
// ([yaml.Marshaler] interface)
func (self *CloutAPI) MarshalYAML() (any, error) {
return self.Clout, nil
}

// cbor.Marshaler interface
// ([cbor.Marshaler] interface)
func (self *CloutAPI) MarshalCBOR() ([]byte, error) {
return cbor.Marshal(self.Clout)
}

// msgpack.Marshaler interface
// ([msgpack.Marshaler] interface)
func (self *CloutAPI) MarshalMsgpack() ([]byte, error) {
return msgpack.Marshal(self.Clout)
}
4 changes: 3 additions & 1 deletion clout/js/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Context struct {
Format string
Strict bool
Pretty bool
Base64 bool
Output string
Log commonlog.Logger
Stdout io.Writer
Expand All @@ -34,7 +35,7 @@ type Context struct {
programCache sync.Map
}

func NewContext(name string, log commonlog.Logger, arguments map[string]string, quiet bool, format string, strict bool, pretty bool, output string, urlContext *exturl.Context) *Context {
func NewContext(name string, log commonlog.Logger, arguments map[string]string, quiet bool, format string, strict bool, pretty bool, base64 bool, output string, urlContext *exturl.Context) *Context {
if arguments == nil {
arguments = make(map[string]string)
}
Expand All @@ -45,6 +46,7 @@ func NewContext(name string, log commonlog.Logger, arguments map[string]string,
Format: format,
Strict: strict,
Pretty: pretty,
Base64: base64,
Output: output,
Log: commonlog.NewScopeLogger(log, name),
Stdout: os.Stdout,
Expand Down
3 changes: 2 additions & 1 deletion clout/js/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type ExecContext struct {
Format string
Strict bool
Pretty bool
Base64 bool
}

func (self *ExecContext) NewContext(scriptletName string, arguments map[string]string) *Context {
return NewContext(scriptletName, log, arguments, true, self.Format, self.Strict, self.Pretty, "", self.URLContext)
return NewContext(scriptletName, log, arguments, true, self.Format, self.Strict, self.Pretty, self.Base64, "", self.URLContext)
}

func (self *ExecContext) Exec(scriptletName string, arguments map[string]string) *goja.Object {
Expand Down
4 changes: 2 additions & 2 deletions clout/js/function-call.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/tliron/go-ard"
"github.com/tliron/kutil/transcribe"
"github.com/tliron/go-transcribe"
)

//
Expand Down Expand Up @@ -226,7 +226,7 @@ func encodeArgument(argument ard.Value) string {
argument_ = strings.ReplaceAll(argument_, "\n", "¶")
return fmt.Sprintf("%q", argument_)
default:
argument__, _ := transcribe.EncodeJSON(argument, "")
argument__, _ := transcribe.StringifyJSON(argument, "")
return argument__
}
}
6 changes: 4 additions & 2 deletions clout/js/puccini-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/tliron/commonjs-goja"
"github.com/tliron/commonlog"
"github.com/tliron/exturl"
"github.com/tliron/go-transcribe"
"github.com/tliron/kutil/terminal"
"github.com/tliron/kutil/transcribe"
"github.com/tliron/kutil/util"
)

Expand All @@ -35,6 +35,7 @@ type PucciniAPI struct {
Format string
Strict bool
Pretty bool
Base64 bool

context *Context
}
Expand All @@ -56,6 +57,7 @@ func (self *Context) NewPucciniAPI() *PucciniAPI {
Format: format,
Strict: self.Strict,
Pretty: self.Pretty,
Base64: self.Base64,
context: self,
}
}
Expand Down Expand Up @@ -105,7 +107,7 @@ func (self *PucciniAPI) Write(data any, path string, dontOverwrite bool) {
}
}

self.failOnError(transcribe.WriteOrPrint(data, self.Format, self.Stdout, self.Strict, self.Pretty, output))
self.failOnError(transcribe.WriteOrPrint(data, self.Format, self.Stdout, self.Strict, self.Pretty, self.Base64, output, nil))
}

func (self *PucciniAPI) LoadString(url string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion clout/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func Read(reader io.Reader, format string) (*Clout, error) {
if data, _, err := ard.Read(reader, format, false); err == nil {
if map_, ok := data.(ard.Map); ok {
if clout, err := Parse(map_); err == nil {
if clout, err := Unpack(map_); err == nil {
return clout, nil
} else {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions clout/parse.go → clout/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ import (
"github.com/tliron/go-ard"
)

func Parse(map_ ard.Map) (*Clout, error) {
func Unpack(map_ ard.Map) (*Clout, error) {
clout := NewClout()

if data, ok := map_["version"]; ok {
if version, ok := data.(string); ok {
clout.Version = version
} else {
return nil, fmt.Errorf("malformed clout: \"version\" not a string: %T", data)
return nil, fmt.Errorf("malformed Clout: \"version\" not a string: %T", data)
}
} else {
return nil, errors.New("malformed clout: no \"version\"")
return nil, errors.New("malformed Clout: no \"version\"")
}

if data, ok := map_["metadata"]; ok {
if metadata, ok := data.(ard.Map); ok {
clout.Metadata = ard.MapToStringMap(metadata)
clout.Metadata = ard.CopyMapsToStringMaps(metadata).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed clout: \"metadata\" not a map: %T", data)
return nil, fmt.Errorf("malformed Clout: \"metadata\" not a map: %T", data)
}
}

if data, ok := map_["properties"]; ok {
if properties, ok := data.(ard.Map); ok {
clout.Properties = ard.MapToStringMap(properties)
clout.Properties = ard.CopyMapsToStringMaps(properties).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed clout: \"properties\" not a map: %T", data)
return nil, fmt.Errorf("malformed Clout: \"properties\" not a map: %T", data)
}
}

Expand All @@ -45,15 +45,15 @@ func Parse(map_ ard.Map) (*Clout, error) {

if data, ok := map_["metadata"]; ok {
if metadata, ok := data.(ard.Map); ok {
vertex.Metadata = ard.MapToStringMap(metadata)
vertex.Metadata = ard.CopyMapsToStringMaps(metadata).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed vertex: \"metadata\" not a map: %T", data)
}
}

if data, ok := map_["properties"]; ok {
if properties, ok := data.(ard.Map); ok {
vertex.Properties = ard.MapToStringMap(properties)
vertex.Properties = ard.CopyMapsToStringMaps(properties).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed vertex: \"properties\" not a map: %T", data)
}
Expand All @@ -69,15 +69,15 @@ func Parse(map_ ard.Map) (*Clout, error) {

if data, ok := map_["metadata"]; ok {
if metadata, ok := data.(ard.Map); ok {
edge.Metadata = ard.MapToStringMap(metadata)
edge.Metadata = ard.CopyMapsToStringMaps(metadata).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed edge: \"metadata\" not a map: %T", data)
}
}

if data, ok := map_["properties"]; ok {
if properties, ok := data.(ard.Map); ok {
edge.Properties = ard.MapToStringMap(properties)
edge.Properties = ard.CopyMapsToStringMaps(properties).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed edge: \"properties\" not a map: %T", data)
}
Expand All @@ -102,7 +102,7 @@ func Parse(map_ ard.Map) (*Clout, error) {
}
}
} else {
return nil, fmt.Errorf("malformed clout: \"vertexes\" not a map: %T", data)
return nil, fmt.Errorf("malformed Clout: \"vertexes\" not a map: %T", data)
}
}

Expand Down
Loading

0 comments on commit ff2eeda

Please sign in to comment.