From 8ea5fdae58739cdb51a29e5f3e9059e3a00bee51 Mon Sep 17 00:00:00 2001 From: xrstf Date: Sun, 24 Dec 2023 16:00:40 +0100 Subject: [PATCH] rename pathexpr package to jsonpath --- pkg/builtin/core/functions.go | 6 +++--- pkg/{pathexpr => jsonpath}/delete.go | 2 +- pkg/{pathexpr => jsonpath}/delete_test.go | 2 +- pkg/{pathexpr => jsonpath}/get.go | 2 +- pkg/{pathexpr => jsonpath}/get_test.go | 2 +- pkg/{pathexpr => jsonpath}/path.go | 2 +- pkg/{pathexpr => jsonpath}/set.go | 2 +- pkg/{pathexpr => jsonpath}/set_test.go | 2 +- pkg/pathexpr/deprecated.go | 15 +++++++++++++++ pkg/runtime/interpreter/eval_tuple.go | 4 ++-- pkg/runtime/interpreter/test/symbol_test.go | 6 +++--- pkg/runtime/pathexpr/eval.go | 4 ++-- 12 files changed, 32 insertions(+), 17 deletions(-) rename pkg/{pathexpr => jsonpath}/delete.go (99%) rename pkg/{pathexpr => jsonpath}/delete_test.go (99%) rename pkg/{pathexpr => jsonpath}/get.go (99%) rename pkg/{pathexpr => jsonpath}/get_test.go (99%) rename pkg/{pathexpr => jsonpath}/path.go (97%) rename pkg/{pathexpr => jsonpath}/set.go (99%) rename pkg/{pathexpr => jsonpath}/set_test.go (99%) create mode 100644 pkg/pathexpr/deprecated.go diff --git a/pkg/builtin/core/functions.go b/pkg/builtin/core/functions.go index af9da60..12eb894 100644 --- a/pkg/builtin/core/functions.go +++ b/pkg/builtin/core/functions.go @@ -10,8 +10,8 @@ import ( "go.xrstf.de/rudi/pkg/coalescing" "go.xrstf.de/rudi/pkg/deepcopy" + "go.xrstf.de/rudi/pkg/jsonpath" "go.xrstf.de/rudi/pkg/lang/ast" - genericpathexpr "go.xrstf.de/rudi/pkg/pathexpr" "go.xrstf.de/rudi/pkg/runtime/functions" "go.xrstf.de/rudi/pkg/runtime/pathexpr" "go.xrstf.de/rudi/pkg/runtime/types" @@ -261,7 +261,7 @@ func deleteFunction(ctx types.Context, expr ast.Expression) (any, error) { } // delete the desired path in the value - updatedValue, err := genericpathexpr.Delete(currentValue, genericpathexpr.FromEvaluatedPath(*pathExpr)) + updatedValue, err := jsonpath.Delete(currentValue, jsonpath.FromEvaluatedPath(*pathExpr)) if err != nil { return nil, fmt.Errorf("cannot delete %s in %T: %w", pathExpr, currentValue, err) } @@ -303,7 +303,7 @@ func deleteBangHandler(ctx types.Context, originalArgs []ast.Expression, value a } // apply the path expression - updatedValue, err = genericpathexpr.Delete(currentValue, genericpathexpr.FromEvaluatedPath(*pathExpr)) + updatedValue, err = jsonpath.Delete(currentValue, jsonpath.FromEvaluatedPath(*pathExpr)) if err != nil { return ctx, nil, fmt.Errorf("cannot set value in %T at %s: %w", currentValue, pathExpr, err) } diff --git a/pkg/pathexpr/delete.go b/pkg/jsonpath/delete.go similarity index 99% rename from pkg/pathexpr/delete.go rename to pkg/jsonpath/delete.go index 4ee7a11..a2a9dc8 100644 --- a/pkg/pathexpr/delete.go +++ b/pkg/jsonpath/delete.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import ( "errors" diff --git a/pkg/pathexpr/delete_test.go b/pkg/jsonpath/delete_test.go similarity index 99% rename from pkg/pathexpr/delete_test.go rename to pkg/jsonpath/delete_test.go index be95718..d1e9ab3 100644 --- a/pkg/pathexpr/delete_test.go +++ b/pkg/jsonpath/delete_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import ( "fmt" diff --git a/pkg/pathexpr/get.go b/pkg/jsonpath/get.go similarity index 99% rename from pkg/pathexpr/get.go rename to pkg/jsonpath/get.go index 092708c..15c0144 100644 --- a/pkg/pathexpr/get.go +++ b/pkg/jsonpath/get.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import ( "fmt" diff --git a/pkg/pathexpr/get_test.go b/pkg/jsonpath/get_test.go similarity index 99% rename from pkg/pathexpr/get_test.go rename to pkg/jsonpath/get_test.go index 9084d43..9e322f8 100644 --- a/pkg/pathexpr/get_test.go +++ b/pkg/jsonpath/get_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import ( "fmt" diff --git a/pkg/pathexpr/path.go b/pkg/jsonpath/path.go similarity index 97% rename from pkg/pathexpr/path.go rename to pkg/jsonpath/path.go index 991c2be..ba8efe6 100644 --- a/pkg/pathexpr/path.go +++ b/pkg/jsonpath/path.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import "go.xrstf.de/rudi/pkg/lang/ast" diff --git a/pkg/pathexpr/set.go b/pkg/jsonpath/set.go similarity index 99% rename from pkg/pathexpr/set.go rename to pkg/jsonpath/set.go index 92f7cbd..b1d3597 100644 --- a/pkg/pathexpr/set.go +++ b/pkg/jsonpath/set.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import ( "errors" diff --git a/pkg/pathexpr/set_test.go b/pkg/jsonpath/set_test.go similarity index 99% rename from pkg/pathexpr/set_test.go rename to pkg/jsonpath/set_test.go index cc1dfa2..26361c8 100644 --- a/pkg/pathexpr/set_test.go +++ b/pkg/jsonpath/set_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 Christoph Mewes // SPDX-License-Identifier: MIT -package pathexpr +package jsonpath import ( "fmt" diff --git a/pkg/pathexpr/deprecated.go b/pkg/pathexpr/deprecated.go new file mode 100644 index 0000000..de0c2b4 --- /dev/null +++ b/pkg/pathexpr/deprecated.go @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Christoph Mewes +// SPDX-License-Identifier: MIT + +package pathexpr + +// These types are deprecated, use jsonpath package instead. + +type ObjectReader interface { + GetObjectKey(name string) (any, error) +} + +type ObjectWriter interface { + ObjectReader + SetObjectKey(name string, value any) (any, error) +} diff --git a/pkg/runtime/interpreter/eval_tuple.go b/pkg/runtime/interpreter/eval_tuple.go index bc2b575..c2d117a 100644 --- a/pkg/runtime/interpreter/eval_tuple.go +++ b/pkg/runtime/interpreter/eval_tuple.go @@ -8,8 +8,8 @@ import ( "fmt" "go.xrstf.de/rudi/pkg/deepcopy" + "go.xrstf.de/rudi/pkg/jsonpath" "go.xrstf.de/rudi/pkg/lang/ast" - genericpathexpr "go.xrstf.de/rudi/pkg/pathexpr" "go.xrstf.de/rudi/pkg/runtime/pathexpr" "go.xrstf.de/rudi/pkg/runtime/types" ) @@ -112,7 +112,7 @@ func (*interpreter) CallFunction(ctx types.Context, fun ast.Identifier, args []a } // apply the path expression - updatedValue, err = genericpathexpr.Set(currentValue, genericpathexpr.FromEvaluatedPath(*pathExpr), updatedValue) + updatedValue, err = jsonpath.Set(currentValue, jsonpath.FromEvaluatedPath(*pathExpr), updatedValue) if err != nil { return ctx, nil, fmt.Errorf("cannot set value in %T at %s: %w", currentValue, pathExpr, err) } diff --git a/pkg/runtime/interpreter/test/symbol_test.go b/pkg/runtime/interpreter/test/symbol_test.go index 6a861ae..8574f53 100644 --- a/pkg/runtime/interpreter/test/symbol_test.go +++ b/pkg/runtime/interpreter/test/symbol_test.go @@ -7,8 +7,8 @@ import ( "fmt" "testing" + "go.xrstf.de/rudi/pkg/jsonpath" "go.xrstf.de/rudi/pkg/lang/ast" - "go.xrstf.de/rudi/pkg/pathexpr" "go.xrstf.de/rudi/pkg/runtime/types" "go.xrstf.de/rudi/pkg/testutil" ) @@ -34,7 +34,7 @@ type customObjGetter struct { value any } -var _ pathexpr.ObjectReader = customObjGetter{} +var _ jsonpath.ObjectReader = customObjGetter{} func (g customObjGetter) GetObjectKey(name string) (any, error) { if name == "value" { @@ -49,7 +49,7 @@ type customVecGetter struct { value any } -var _ pathexpr.VectorReader = customVecGetter{} +var _ jsonpath.VectorReader = customVecGetter{} func (g customVecGetter) GetVectorItem(index int) (any, error) { if index == g.magic { diff --git a/pkg/runtime/pathexpr/eval.go b/pkg/runtime/pathexpr/eval.go index 232311f..ef7af9d 100644 --- a/pkg/runtime/pathexpr/eval.go +++ b/pkg/runtime/pathexpr/eval.go @@ -6,8 +6,8 @@ package pathexpr import ( "fmt" + "go.xrstf.de/rudi/pkg/jsonpath" "go.xrstf.de/rudi/pkg/lang/ast" - genericpathexpr "go.xrstf.de/rudi/pkg/pathexpr" "go.xrstf.de/rudi/pkg/runtime/types" ) @@ -25,7 +25,7 @@ func Apply(ctx types.Context, value any, path *ast.PathExpression) (any, error) } func Traverse(value any, path ast.EvaluatedPathExpression) (any, error) { - return genericpathexpr.Get(value, genericpathexpr.FromEvaluatedPath(path)) + return jsonpath.Get(value, jsonpath.FromEvaluatedPath(path)) } func Eval(ctx types.Context, path *ast.PathExpression) (*ast.EvaluatedPathExpression, error) {