capabilitycontract

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 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

This section is empty.

Variables

This section is empty.

Functions

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 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 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) and cyclic structures anywhere inside val. Capability boundaries call it so host code never receives a script-side callable it cannot safely invoke.

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