Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tliron committed Nov 12, 2023
1 parent ff2eeda commit f7305d3
Show file tree
Hide file tree
Showing 217 changed files with 908 additions and 916 deletions.
22 changes: 11 additions & 11 deletions assets/tosca/profiles/common/1.0/js/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.addHistory = function(description) {
else
history = history.slice(0);
history.push({
timestamp: puccini.nowString(),
timestamp: util.nowString(),
description: description
});
metadata.history = history;
Expand All @@ -108,7 +108,7 @@ exports.getNestedValue = function(singular, plural, args) {
let count = 0;
if (arg in nodeTemplate.capabilities) {
value = nodeTemplate.capabilities[arg][plural];
singular = puccini.sprintf('capability %q %s', arg, singular);
singular = util.sprintf('capability %q %s', arg, singular);
arg = args[++a];
} else for (let e = 0, l = vertex.edgesOut.size(); e < l; e++) {
let edge = vertex.edgesOut[e];
Expand All @@ -118,7 +118,7 @@ exports.getNestedValue = function(singular, plural, args) {
if (relationship.name === arg)
if (count++ === nextArg) {
value = relationship[plural];
singular = puccini.sprintf('relationship %q %s', arg, singular);
singular = util.sprintf('relationship %q %s', arg, singular);
a += 2;
arg = args[a];
break;
Expand All @@ -127,14 +127,14 @@ exports.getNestedValue = function(singular, plural, args) {
if ((typeof value === 'object') && (value !== null) && (arg in value))
value = value[arg];
else
throw puccini.sprintf('%s %q not found in %q', singular, arg, nodeTemplate.name);
throw util.sprintf('%s %q not found in %q', singular, arg, nodeTemplate.name);
value = clout.coerce(value);
for (let i = a + 1; i < length; i++) {
arg = args[i];
if ((typeof value === 'object') && (value !== null) && (arg in value))
value = value[arg];
else
throw puccini.sprintf('nested %s %q not found in %q', singular, args.slice(a, i+1).join('.'), nodeTemplate.name);
throw util.sprintf('nested %s %q not found in %q', singular, args.slice(a, i+1).join('.'), nodeTemplate.name);
}
return value;
};
Expand All @@ -144,22 +144,22 @@ exports.getModelableEntity = function(entity) {
switch (entity) {
case 'SELF':
if (!this || !this.site)
throw puccini.sprintf('%q cannot be used in this context', entity);
throw util.sprintf('%q cannot be used in this context', entity);
vertex = this.site;
break;
case 'SOURCE':
if (!this || !this.source)
throw puccini.sprintf('%q cannot be used in this context', entity);
throw util.sprintf('%q cannot be used in this context', entity);
vertex = this.source;
break;
case 'TARGET':
if (!this || !this.target)
throw puccini.sprintf('%q cannot be used in this context', entity);
throw util.sprintf('%q cannot be used in this context', entity);
vertex = this.target;
break;
case 'HOST':
if (!this || !this.site)
throw puccini.sprintf('%q cannot be used in this context', entity);
throw util.sprintf('%q cannot be used in this context', entity);
vertex = exports.getHost(this.site);
break;
default:
Expand All @@ -173,7 +173,7 @@ exports.getModelableEntity = function(entity) {
if (exports.isNodeTemplate(vertex))
return vertex;
else
throw puccini.sprintf('%q node template not found', entity);
throw util.sprintf('%q node template not found', entity);
};

exports.getHost = function(vertex) {
Expand All @@ -188,7 +188,7 @@ exports.getHost = function(vertex) {
}
}
if (exports.isNodeTemplate(vertex))
throw puccini.sprintf('"HOST" not found for node template %q', vertex.properties.name);
throw util.sprintf('"HOST" not found for node template %q', vertex.properties.name);
else
throw '"HOST" not found';
};
Expand Down
8 changes: 4 additions & 4 deletions assets/tosca/profiles/common/1.0/js/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ function isMaxCountGreater(a, b) {

function unsatisfied(location, name, message) {
if (typeof problems === 'undefined')
throw puccini.sprintf('%s: could not satisfy %q because %s', location.path, name, message);
throw util.sprintf('%s: could not satisfy %q because %s', location.path, name, message);
else
problems.reportFull(11, 'Resolution', location.path, puccini.sprintf('could not satisfy %q because %s', name, message), location.row, location.column);
problems.reportFull(11, 'Resolution', location.path, util.sprintf('could not satisfy %q because %s', name, message), location.row, location.column);
}

function notEnoughRelationships(location, relationshipCount, minRelationshipCount) {
if (typeof problems === 'undefined')
throw puccini.sprintf('%s: not enough relationships: %d < %d', location.path, relationshipCount, minRelationshipCount);
throw util.sprintf('%s: not enough relationships: %d < %d', location.path, relationshipCount, minRelationshipCount);
else
problems.reportFull(11, 'Resolution', location.path, puccini.sprintf('not enough relationships: %d < %d', relationshipCount, minRelationshipCount), location.row, location.column);
problems.reportFull(11, 'Resolution', location.path, util.sprintf('not enough relationships: %d < %d', relationshipCount, minRelationshipCount), location.row, location.column);
}
2 changes: 1 addition & 1 deletion assets/tosca/profiles/common/1.0/js/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ $(document).ready(function () {\n\
</body>\n\
</html>';

let html = puccini.sprintf(
let html = util.sprintf(
template,
jQueryVersion,
jQueryUiVersion, jQueryUiVersion,
Expand Down
2 changes: 1 addition & 1 deletion assets/tosca/profiles/hot/1.0/js/functions/get_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.evaluate = function(input) {
throw 'Clout is not TOSCA';
let inputs = clout.properties.tosca.inputs;
if (!(input in inputs))
throw puccini.sprintf('parameter %q not found', input);
throw util.sprintf('parameter %q not found', input);
let r = inputs[input];
r = clout.coerce(r);
return r;
Expand Down
4 changes: 2 additions & 2 deletions assets/tosca/profiles/implicit/2.0/js/constraints/$format.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
exports.validate = function(v, format) {
if (arguments.length !== 2)
throw 'must have 1 argument';
if (!puccini.isType(v, 'ard.string'))
if (!util.isType(v, 'ard.string'))
return 'not a string';
try {
puccini.validateFormat(v, format);
ard.validateFormat(v, format);
} catch (x) {
if (x.value && x.value.error)
// Unwrap Go error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.evaluate = function(entity, artifactName, location, remove) {
throw 'must have at least 2 arguments';
let nodeTemplate = tosca.getModelableEntity.call(this, entity).properties;
if (!nodeTemplate.artifacts || !(artifactName in nodeTemplate.artifacts))
throw puccini.sprintf('artifact %q not found in %q', artifactName, nodeTemplate.name);
throw util.sprintf('artifact %q not found in %q', artifactName, nodeTemplate.name);
let artifact = nodeTemplate.artifacts[artifactName];
if (artifact.$artifact === undefined)
return artifact.sourcePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.evaluate = function(input) {
throw 'Clout is not TOSCA';
let inputs = clout.properties.tosca.inputs;
if (!(input in inputs))
throw puccini.sprintf('input %q not found', input);
throw util.sprintf('input %q not found', input);
let r = inputs[input];
r = clout.coerce(r);
return r;
Expand Down
7 changes: 7 additions & 0 deletions clout/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package clout

import (
"github.com/tliron/commonlog"
)

var log = commonlog.GetLogger("puccini.clout")
5 changes: 2 additions & 3 deletions clout/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/fxamacker/cbor/v2"
"github.com/tliron/go-ard"
"github.com/tliron/kutil/util"
"github.com/vmihailenco/msgpack/v5"
)

Expand Down Expand Up @@ -127,7 +126,7 @@ func (self *Edge) MarshalMsgpack() ([]byte, error) {

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

// json.Unmarshaler interface
Expand All @@ -154,7 +153,7 @@ func (self *Edge) UnmarshalCBOR(data []byte) error {
// msgpack.Unmarshaler interface
func (self *Edge) UnmarshalMsgpack(data []byte) error {
return self.Unmarshal(func(m *MarshalableEdge) error {
return util.UnmarshalMessagePack(data, m)
return ard.UnmarshalMessagePack(data, m)
})
}

Expand Down
10 changes: 8 additions & 2 deletions clout/js/clout-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
"github.com/vmihailenco/msgpack/v5"
)

func (self *Environment) CreateCloutExtension(clout *cloutpkg.Clout) commonjs.CreateExtensionFunc {
return func(jsContext *commonjs.Context) any {
return self.NewCloutAPI(clout, jsContext)
}
}

//
// CloutAPI
//
Expand All @@ -25,7 +31,7 @@ type CloutAPI struct {
cloutContext *CloutContext
}

func (self *Context) NewCloutAPI(clout *cloutpkg.Clout, jsContext *commonjs.Context) *CloutAPI {
func (self *Environment) NewCloutAPI(clout *cloutpkg.Clout, jsContext *commonjs.Context) *CloutAPI {
return &CloutAPI{
clout,
self.NewCloutContext(clout, jsContext),
Expand Down Expand Up @@ -66,7 +72,7 @@ func (self *CloutAPI) NewKey() string {

func (self *CloutAPI) Call(scriptletName string, functionName string, arguments []any) (any, error) {
executionContext := self.cloutContext.NewExecutionContext(nil, nil, nil)
return executionContext.Call(scriptletName, functionName, arguments)
return executionContext.Call(scriptletName, functionName, arguments...)
}

// TODO: unused?
Expand Down
4 changes: 2 additions & 2 deletions clout/js/clout-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
//

type CloutContext struct {
Context *Context
Context *Environment
Clout *cloutpkg.Clout
JSContext *commonjs.Context
}

func (self *Context) NewCloutContext(clout *cloutpkg.Clout, jsContext *commonjs.Context) *CloutContext {
func (self *Environment) NewCloutContext(clout *cloutpkg.Clout, jsContext *commonjs.Context) *CloutContext {
return &CloutContext{
Context: self,
Clout: clout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (self *FunctionCall) Signature(arguments []ard.Value) string {
return fmt.Sprintf("%s(%s)", self.Name, strings.Join(s, ","))
}

// Coercible interface
// ([Coercible] interface)
func (self *FunctionCall) Coerce() (ard.Value, error) {
arguments, err := self.CoerceArguments()
if err != nil {
Expand All @@ -127,7 +127,7 @@ func (self *FunctionCall) Coerce() (ard.Value, error) {

logEvaluate.Debugf("%s %s", self.Path, self.Signature(arguments))

data, err := self.ExecutionContext.Call(self.Name, "evaluate", arguments)
data, err := self.ExecutionContext.Call(self.Name, "evaluate", arguments...)
if err != nil {
return nil, self.WrapError(arguments, err)
}
Expand All @@ -145,12 +145,12 @@ func (self *FunctionCall) Coerce() (ard.Value, error) {
}
}

// Coercible interface
// ([Coercible] interface)
func (self *FunctionCall) AddValidators(validators Validators) {
self.Validators = append(self.Validators, validators...)
}

// Coercible interface
// ([Coercible] interface)
func (self *FunctionCall) Unwrap() ard.Value {
return self.Notation
}
Expand All @@ -177,7 +177,7 @@ func (self *FunctionCall) Validate(value ard.Value, errorWhenInvalid bool) (bool

logValidate.Debugf("%s %s", self.Path, self.Signature(arguments))

r, err := self.ExecutionContext.Call(self.Name, "validate", arguments)
r, err := self.ExecutionContext.Call(self.Name, "validate", arguments...)
if err != nil {
return false, self.WrapError(arguments, err)
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (self *FunctionCall) Convert(value ard.Value) (ard.Value, error) {

logConvert.Debugf("%s %s", self.Path, self.Signature(arguments))

if r, err := self.ExecutionContext.Call(self.Name, "convert", arguments); err == nil {
if r, err := self.ExecutionContext.Call(self.Name, "convert", arguments...); err == nil {
return r, nil
} else {
return false, self.WrapError(arguments, err)
Expand All @@ -226,7 +226,7 @@ func encodeArgument(argument ard.Value) string {
argument_ = strings.ReplaceAll(argument_, "\n", "¶")
return fmt.Sprintf("%q", argument_)
default:
argument__, _ := transcribe.StringifyJSON(argument, "")
argument__, _ := transcribe.NewTranscriber().StringifyJSON(argument)
return argument__
}
}
72 changes: 72 additions & 0 deletions clout/js/coercible-value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package js

import (
"github.com/tliron/go-ard"
)

//
// Value
//

type Value struct {
Data any `json:"data" yaml:"data"` // List, Map, or ard.Value
Validators Validators `json:"validators,omitempty" yaml:"validators,omitempty"`
Converter *FunctionCall `json:"converter,omitempty" yaml:"converter,omitempty"`

Notation ard.StringMap `json:"-" yaml:"-"`
}

func (self *ExecutionContext) NewValue(data ard.Value, notation ard.StringMap, meta ard.StringMap) (*Value, error) {
value := Value{
Data: data,
Notation: notation,
}

var err error
if value.Validators, err = self.NewValidatorsFromMeta(meta); err != nil {
return nil, err
}
if value.Converter, err = self.NewConverter(meta); err != nil {
return nil, err
}

return &value, nil
}

// ([Coercible] interface)
func (self *Value) Coerce() (ard.Value, error) {
data := self.Data

var err error
switch data_ := data.(type) {
case List:
if data, err = data_.Coerce(); err != nil {
return nil, err
}

case Map:
if data, err = data_.Coerce(); err != nil {
return nil, err
}
}

if err := self.Validators.Apply(data); err == nil {
if self.Converter != nil {
return self.Converter.Convert(data)
} else {
return data, nil
}
} else {
return nil, err
}
}

// ([Coercible] interface)
func (self *Value) AddValidators(validators Validators) {
self.Validators = append(self.Validators, validators...)
}

// ([Coercible] interface)
func (self *Value) Unwrap() ard.Value {
return self.Notation
}
Loading

0 comments on commit f7305d3

Please sign in to comment.