capabilitycontract

package
v0.70.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package capabilitycontract centralizes the helper utilities shared by the carved vibes/capability/* subpackages. The helpers operate on vibes/value.Value so they stay free of runtime-AST imports and can be reused by every capability adapter without forcing each one to take a hard dependency on the vibes package.

Index

Constants

View Source
const MaxDataOnlyTraversalDepth = capabilitydata.MaxDepth

MaxDataOnlyTraversalDepth bounds recursive capability payload validation and cloning so deeply nested acyclic values cannot exhaust the host stack.

Variables

This section is empty.

Functions

func CloneDataOnlyValue added in v0.60.0

func CloneDataOnlyValue(label string, val value.Value) (value.Value, error)

CloneDataOnlyValue validates and deep-copies val in one graph walk.

func CloneHash

func CloneHash(src map[string]value.Value) map[string]value.Value

CloneHash returns a deep copy of the provided string-keyed map. An empty input returns an empty (non-nil) map to preserve historical behavior of the in-package helper this replaced.

func CloneHashValue added in v0.60.0

func CloneHashValue(label string, val value.Value) (map[string]value.Value, error)

CloneHashValue checks that val is a hash or object, validates that it contains only data values, and returns an isolated copy of its entries.

func CloneKwargs

func CloneKwargs(kwargs map[string]value.Value) map[string]value.Value

CloneKwargs returns a deep copy of the keyword-arguments map suitable for handing to host callbacks without exposing script-side aliases.

func CloneKwargsDataOnly added in v0.60.0

func CloneKwargsDataOnly(method string, kwargs map[string]value.Value) (map[string]value.Value, error)

CloneKwargsDataOnly validates and deep-copies keyword arguments in one pass so host callbacks receive isolated data-only values.

func CloneMethodResult

func CloneMethodResult(method string, result value.Value) (value.Value, error)

CloneMethodResult validates and deep-copies a host-returned Value so the host's mutable state is not aliased into the script heap.

func DeepCloneValue

func DeepCloneValue(val value.Value) value.Value

DeepCloneValue recursively copies arrays, hashes, and objects so the host receives a fully isolated snapshot of script-supplied data. Scalar kinds and runtime-only kinds are returned unchanged.

func EnsureBlock

func EnsureBlock(block value.Value, name string) error

EnsureBlock returns a "%s requires a block" error when block is not a block Value. The name argument is the script-facing method name.

func IsNilImplementation

func IsNilImplementation(impl any) bool

IsNilImplementation reports whether impl is a nil interface or a typed-nil pointer / channel / func / map / slice. Capability constructors use it to reject zero-value implementations that would later panic with a nil-pointer dereference at call time.

func NameArg

func NameArg(method, label string, val value.Value) (string, error)

NameArg validates that val is a non-empty string or symbol and returns its textual form. Used by capability adapters to interpret leading "name" arguments such as the collection passed to db.find.

func ValidateAnyReturn

func ValidateAnyReturn(method string) func(result value.Value) error

ValidateAnyReturn returns the post-call return validator used in CapabilityMethodContract.ValidateReturn entries for methods that allow any data-only return value.

func ValidateDataOnlyValue

func ValidateDataOnlyValue(label string, val value.Value) error

ValidateDataOnlyValue rejects callable payloads (functions, blocks, builtins, classes, instances), runtime-only payloads (shape values), and cyclic structures anywhere inside val. Capability boundaries call it so host code never receives a script-side callable it cannot safely invoke or an opaque runtime payload that is not plain data.

func ValidateHashValue

func ValidateHashValue(label string, val value.Value) error

ValidateHashValue checks that val is a hash (or object) and data-only. The error string format matches the original validateCapabilityHashValue wrapper so capability tests that grep on it continue to pass.

func ValidateKwargsDataOnly

func ValidateKwargsDataOnly(method string, kwargs map[string]value.Value) error

ValidateKwargsDataOnly applies ValidateDataOnlyValue to every keyword argument, labeling errors with method and keyword name.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL