Skip to content

Commit

Permalink
rename pathexpr package to jsonpath
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Dec 24, 2023
1 parent 3aee197 commit 8ea5fda
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 17 deletions.
6 changes: 3 additions & 3 deletions pkg/builtin/core/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pathexpr/delete.go → pkg/jsonpath/delete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Christoph Mewes
// SPDX-License-Identifier: MIT

package pathexpr
package jsonpath

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Christoph Mewes
// SPDX-License-Identifier: MIT

package pathexpr
package jsonpath

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pathexpr/get.go → pkg/jsonpath/get.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Christoph Mewes
// SPDX-License-Identifier: MIT

package pathexpr
package jsonpath

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pathexpr/get_test.go → pkg/jsonpath/get_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Christoph Mewes
// SPDX-License-Identifier: MIT

package pathexpr
package jsonpath

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pathexpr/path.go → pkg/jsonpath/path.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion pkg/pathexpr/set.go → pkg/jsonpath/set.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Christoph Mewes
// SPDX-License-Identifier: MIT

package pathexpr
package jsonpath

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pathexpr/set_test.go → pkg/jsonpath/set_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Christoph Mewes
// SPDX-License-Identifier: MIT

package pathexpr
package jsonpath

import (
"fmt"
Expand Down
15 changes: 15 additions & 0 deletions pkg/pathexpr/deprecated.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 2 additions & 2 deletions pkg/runtime/interpreter/eval_tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/runtime/interpreter/test/symbol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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" {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/pathexpr/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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) {
Expand Down

0 comments on commit 8ea5fda

Please sign in to comment.