mirror of
https://github.com/MontFerret/ferret.git
synced 2025-12-25 23:37:06 +02:00
* Updated ANTLR and other dependencies. Upgraded Go version * Updated unit tests * Updated CodeQL * Fixed linting errors * Updated build pipeline * Reverted refactoring of build pipeline * Removed outdated examples from E2E tests
44 lines
877 B
Go
44 lines
877 B
Go
package objects
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
|
)
|
|
|
|
// VALUES return the attribute values of the object as an array.
|
|
// @param {Object} object - Target object.
|
|
// @return {Any[]} - Values of document returned in any order.
|
|
func Values(_ context.Context, args ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(args, 1, 1)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
err = core.ValidateType(args[0], types.Object)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
obj := args[0].(*values.Object)
|
|
vals := values.NewArray(0)
|
|
|
|
obj.ForEach(func(val core.Value, _ string) bool {
|
|
cloneable, ok := val.(core.Cloneable)
|
|
|
|
if ok {
|
|
val = cloneable.Clone()
|
|
}
|
|
|
|
vals.Push(val)
|
|
|
|
return true
|
|
})
|
|
|
|
return vals, nil
|
|
}
|