op

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package op provides implementations for JSON Patch operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewContains creates a new contains operation
	NewContains = NewOpContainsOperation
	// NewContainsWithIgnoreCase creates a new contains operation with ignore case
	NewContainsWithIgnoreCase = NewOpContainsOperationWithIgnoreCase
)

Short aliases for common use

View Source
var (
	// NewEnds creates a new ends operation
	NewEnds = NewOpEndsOperation
	// NewEndsWithIgnoreCase creates a new ends operation with ignore case
	NewEndsWithIgnoreCase = NewOpEndsOperationWithIgnoreCase
)

Short aliases for common use

View Source
var (
	// Core path errors - aligned with json-joy patterns
	ErrPathNotFound     = errors.New("NOT_FOUND")
	ErrPathDoesNotExist = errors.New("NOT_FOUND")
	ErrInvalidPath      = errors.New("OP_PATH_INVALID")
	ErrPathEmpty        = errors.New("OP_PATH_INVALID")
	ErrFromPathEmpty    = errors.New("OP_FROM_INVALID")
	ErrPathsIdentical   = errors.New("cannot move into own children")

	// Array operation errors - aligned with json-joy patterns
	ErrArrayIndexOutOfBounds = errors.New("INVALID_INDEX")
	ErrIndexOutOfRange       = errors.New("INVALID_INDEX")
	ErrNotAnArray            = errors.New("Not a array")
	ErrArrayTooSmall         = errors.New("array must have at least 2 elements")
	ErrPositionOutOfBounds   = errors.New("INVALID_INDEX")
	ErrPositionNegative      = errors.New("INVALID_INDEX")

	// Type validation errors - aligned with json-joy patterns
	ErrNotString     = errors.New("value is not a string")
	ErrNotNumber     = errors.New("value must be a number")
	ErrNotObject     = errors.New("value is not an object")
	ErrInvalidType   = errors.New("invalid type")
	ErrEmptyTypeList = errors.New("empty type list")

	// Operation execution errors - aligned with json-joy patterns
	ErrTestFailed          = errors.New("test failed")
	ErrDefinedTestFailed   = errors.New("defined test failed")
	ErrUndefinedTestFailed = errors.New("undefined test failed")
	ErrAndTestFailed       = errors.New("and test failed")
	ErrOrTestFailed        = errors.New("or test failed")
	ErrNotTestFailed       = errors.New("not test failed")

	// Value operation errors - aligned with json-joy patterns
	ErrCannotReplace          = errors.New("NOT_FOUND")
	ErrCannotAddToValue       = errors.New("cannot add to non-object/non-array value")
	ErrCannotRemoveFromValue  = errors.New("cannot remove from non-object/non-array document")
	ErrPathMissingRecursive   = errors.New("NOT_FOUND")
	ErrCannotMoveIntoChildren = errors.New("cannot move into own children")
	ErrPropertiesNil          = errors.New("properties cannot be nil")
	ErrValuesArrayEmpty       = errors.New("'in' operation 'value' must be an array")

	// Key type errors
	ErrInvalidKeyTypeMap     = errors.New("invalid key type for map")
	ErrInvalidKeyTypeSlice   = errors.New("invalid key type for slice")
	ErrUnsupportedParentType = errors.New("unsupported parent type")

	// String operation errors - aligned with json-joy patterns
	ErrPositionOutOfStringRange = errors.New("INVALID_INDEX")
	ErrSubstringTooLong         = errors.New("value too long")
	ErrSubstringMismatch        = errors.New("substring does not match")
	ErrStringLengthMismatch     = errors.New("string length mismatch")
	ErrPatternEmpty             = errors.New("pattern cannot be empty")
	ErrLengthNegative           = errors.New("INVALID_INDEX")

	// Type comparison errors
	ErrTypeMismatch = errors.New("type mismatch")

	// Predicate operation errors - aligned with json-joy patterns
	ErrInvalidPredicateInAnd = errors.New("OP_INVALID")
	ErrInvalidPredicateInNot = errors.New("OP_INVALID")
	ErrInvalidPredicateInOr  = errors.New("OP_INVALID")
	ErrAndNoOperands         = errors.New("empty operation patch")
	ErrNotNoOperands         = errors.New("empty operation patch")
	ErrOrNoOperands          = errors.New("empty operation patch")

	// Operation modification errors
	ErrCannotModifyRootArray     = errors.New("cannot modify root array directly")
	ErrCannotUpdateParent        = errors.New("cannot update parent")
	ErrCannotUpdateGrandparent   = errors.New("cannot update grandparent")
	ErrCannotAppendInPlace       = errors.New("cannot append to slice in place - caller must handle")
	ErrSliceDeletionNotSupported = errors.New("slice deletion not supported in place - caller must handle")
	ErrKeyDoesNotExist           = errors.New("key does not exist")

	// Value conversion errors
	ErrCannotConvertNilToString = errors.New("cannot convert nil to string")

	// Test operation errors
	ErrTestOperationNumberStringMismatch = errors.New("test operation failed: number is not equal to string")
	ErrTestOperationStringNotEquivalent  = errors.New("test operation failed: string not equivalent")

	// Base errors for dynamic wrapping with fmt.Errorf
	ErrComparisonFailed    = errors.New("comparison failed")
	ErrStringMismatch      = errors.New("string mismatch")
	ErrTestOperationFailed = errors.New("test operation failed")
	ErrInvalidIndex        = errors.New("invalid index")
	ErrRegexPattern        = errors.New("regex pattern error")
	ErrOperationFailed     = errors.New("operation failed")
)

Sentinel errors for path and validation related operations

View Source
var (
	// NewNot creates a new not operation
	NewNot = NewOpNotOperation
	// NewNotMultiple creates a new not operation with multiple operands
	NewNotMultiple = NewOpNotOperationMultiple
)

Short aliases for common use

View Source
var (
	// NewRemove creates a new remove operation
	NewRemove = NewOpRemoveOperation
	// NewRemoveWithOldValue creates a new remove operation with old value
	NewRemoveWithOldValue = NewOpRemoveOperationWithOldValue
)

Short aliases for common use

View Source
var (
	// NewReplace creates a new replace operation
	NewReplace = NewOpReplaceOperation
	// NewReplaceWithOldValue creates a new replace operation with old value
	NewReplaceWithOldValue = NewOpReplaceOperationWithOldValue
)

Short aliases for common use

View Source
var (
	// NewStarts creates a new starts operation
	NewStarts = NewOpStartsOperation
	// NewStartsWithIgnoreCase creates a new starts operation with ignore case
	NewStartsWithIgnoreCase = NewOpStartsOperationWithIgnoreCase
)

Short aliases for common use

View Source
var (
	// NewStrDel creates a new string delete operation
	NewStrDel = NewOpStrDelOperation
	// NewStrDelWithStr creates a new string delete operation with string
	NewStrDelWithStr = NewOpStrDelOperationWithStr
)

Short aliases for common use

View Source
var (
	// NewTestString creates a new test string operation
	NewTestString = NewOpTestStringOperation
	// NewTestStringWithPos creates a new test string operation with position
	NewTestStringWithPos = NewOpTestStringOperationWithPos
)

Short aliases for common use

View Source
var (
	// NewTestStringLen creates a new test string length operation
	NewTestStringLen = NewOpTestStringLenOperation
	// NewTestStringLenWithNot creates a new test string length operation with not flag
	NewTestStringLenWithNot = NewOpTestStringLenOperationWithNot
)

Short aliases for common use

View Source
var (
	// NewTestType creates a new test type operation
	NewTestType = NewOpTestTypeOperation
	// NewTestTypeMultiple creates a new test type operation with multiple types
	NewTestTypeMultiple = NewOpTestTypeOperationMultiple
)

Short aliases for common use

View Source
var (
	// NewAnd creates a new and operation
	NewAnd = NewOpAndOperation
)

Short aliases for common use

View Source
var (
	// NewCopy creates a new copy operation
	NewCopy = NewOpCopyOperation
)

Short aliases for common use

View Source
var (
	// NewDefined creates a new defined operation
	NewDefined = NewOpDefinedOperation
)

Short aliases for common use

View Source
var (
	// NewExtend creates a new extend operation
	NewExtend = NewOpExtendOperation
)

Short aliases for common use

View Source
var (
	// NewFlip creates a new flip operation
	NewFlip = NewOpFlipOperation
)

Short aliases for common use

View Source
var (
	// NewIn creates a new in operation
	NewIn = NewOpInOperation
)

Short aliases for common use

View Source
var (
	// NewInc creates a new inc operation
	NewInc = NewOpIncOperation
)

Short aliases for common use

View Source
var (
	// NewMatches creates a new matches operation
	NewMatches = NewOpMatchesOperation
)

Short aliases for common use

View Source
var (
	// NewMerge creates a new merge operation
	NewMerge = NewOpMergeOperation
)

Short aliases for common use

View Source
var (
	// NewMore creates a new more operation
	NewMore = NewOpMoreOperation
)

Short aliases for common use

View Source
var (
	// NewMove creates a new move operation
	NewMove = NewOpMoveOperation
)

Short aliases for common use

View Source
var (
	// NewOr creates a new or operation
	NewOr = NewOpOrOperation
)

Short aliases for common use

View Source
var (
	// NewSplit creates a new split operation
	NewSplit = NewOpSplitOperation
)

Short aliases for common use

View Source
var (
	// NewStrIns creates a new string insert operation
	NewStrIns = NewOpStrInsOperation
)

Short aliases for common use

View Source
var (
	// NewTest creates a new test operation
	NewTest = NewOpTestOperation
)

Short aliases for common use

View Source
var (
	// NewType creates a new type operation
	NewType = NewOpTypeOperation
)

Short aliases for common use

View Source
var (
	// NewUndefined creates a new undefined operation
	NewUndefined = NewOpUndefinedOperation
)

Short aliases for common use

Functions

func DeepClone

func DeepClone(value interface{}) (interface{}, error)

DeepClone performs a deep clone of a value.

func IsMutationOp

func IsMutationOp(opType internal.OpType) bool

IsMutationOp checks if an operation type is a mutation operation.

func IsPredicateOp

func IsPredicateOp(opType internal.OpType) bool

IsPredicateOp checks if an operation type is a predicate operation.

func IsSecondOrderPredicateOp

func IsSecondOrderPredicateOp(opType internal.OpType) bool

IsSecondOrderPredicateOp checks if an operation type is a second-order predicate operation.

func ToFloat64 added in v0.4.5

func ToFloat64(val interface{}) (float64, bool)

ToFloat64 converts a value to float64, handling various numeric types, booleans, and strings. This matches JavaScript's Number() behavior for type coercion. Optimized for common numeric types with fast paths.

Types

type AddOperation added in v0.4.3

type AddOperation struct {
	BaseOp
	Value interface{} `json:"value"` // Value to add
}

AddOperation represents an add operation that adds a value at a specified path.

func NewAdd added in v0.4.3

func NewAdd(path []string, value interface{}) *AddOperation

NewAdd creates a new AddOperation operation.

func (*AddOperation) Apply added in v0.4.3

func (o *AddOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the add operation.

func (*AddOperation) Code added in v0.4.3

func (o *AddOperation) Code() int

Code returns the operation code.

func (*AddOperation) Op added in v0.4.3

func (o *AddOperation) Op() internal.OpType

Op returns the operation type.

func (*AddOperation) Path added in v0.4.3

func (o *AddOperation) Path() []string

Path returns the operation path.

func (*AddOperation) ToCompact added in v0.4.3

func (o *AddOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*AddOperation) ToJSON added in v0.4.3

func (o *AddOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*AddOperation) Validate added in v0.4.3

func (o *AddOperation) Validate() error

Validate validates the add operation.

type AndOperation added in v0.4.3

type AndOperation struct {
	BaseOp
	Operations []interface{} `json:"apply"` // Array of operations to apply
}

AndOperation represents an and operation that combines multiple predicate operations.

func NewOpAndOperation

func NewOpAndOperation(path []string, ops []interface{}) *AndOperation

NewOpAndOperation creates a new AndOperation operation.

func (*AndOperation) Apply added in v0.4.3

func (o *AndOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the AND operation.

func (*AndOperation) Code added in v0.4.3

func (o *AndOperation) Code() int

Code returns the operation code.

func (*AndOperation) Not added in v0.4.3

func (o *AndOperation) Not() bool

Not returns false since this is not a NOT operation.

func (*AndOperation) Op added in v0.4.3

func (o *AndOperation) Op() internal.OpType

Op returns the operation type.

func (*AndOperation) Ops added in v0.4.3

func (o *AndOperation) Ops() []internal.PredicateOp

Ops returns the predicate operations.

func (*AndOperation) Path added in v0.4.3

func (o *AndOperation) Path() []string

Path returns the path for the AND operation.

func (*AndOperation) Test added in v0.4.3

func (o *AndOperation) Test(doc interface{}) (bool, error)

Test performs the AND operation.

func (*AndOperation) ToCompact added in v0.4.3

func (o *AndOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*AndOperation) ToJSON added in v0.4.3

func (o *AndOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*AndOperation) Validate added in v0.4.3

func (o *AndOperation) Validate() error

Validate validates the AND operation.

type BaseOp

type BaseOp struct {
	// contains filtered or unexported fields
}

BaseOp provides common functionality for all operations.

func NewBaseOp

func NewBaseOp(path []string) BaseOp

NewBaseOp creates a new BaseOp with the given path.

func NewBaseOpWithFrom

func NewBaseOpWithFrom(path, from []string) BaseOp

NewBaseOpWithFrom creates a new BaseOp with path and from path.

func (*BaseOp) From

func (b *BaseOp) From() []string

From returns the from path for move/copy operations.

func (*BaseOp) HasFrom

func (b *BaseOp) HasFrom() bool

HasFrom returns true if the operation has a from path.

func (*BaseOp) Path

func (b *BaseOp) Path() []string

Path returns the operation path.

type ContainsOperation added in v0.4.3

type ContainsOperation struct {
	BaseOp
	Value      string `json:"value"`       // Substring to search for
	IgnoreCase bool   `json:"ignore_case"` // Whether to ignore case when comparing
	NotFlag    bool   `json:"not"`         // Whether to negate the result
}

ContainsOperation represents a contains operation that tests if a string contains a substring.

func NewOpContainsOperation

func NewOpContainsOperation(path []string, substring string) *ContainsOperation

NewOpContainsOperation creates a new OpContainsOperation operation.

func NewOpContainsOperationWithFlags added in v0.5.1

func NewOpContainsOperationWithFlags(path []string, substring string, ignoreCase bool, notFlag bool) *ContainsOperation

NewOpContainsOperationWithFlags creates a new OpContainsOperation operation with full options.

func NewOpContainsOperationWithIgnoreCase

func NewOpContainsOperationWithIgnoreCase(path []string, substring string, ignoreCase bool) *ContainsOperation

NewOpContainsOperationWithIgnoreCase creates a new OpContainsOperation operation with ignore case option.

func (*ContainsOperation) Apply added in v0.4.3

func (op *ContainsOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the contains test operation to the document.

func (*ContainsOperation) Code added in v0.4.3

func (op *ContainsOperation) Code() int

Code returns the operation code.

func (*ContainsOperation) Not added in v0.4.3

func (op *ContainsOperation) Not() bool

Not returns the negation flag.

func (*ContainsOperation) Op added in v0.4.3

Op returns the operation type.

func (*ContainsOperation) Path added in v0.4.3

func (op *ContainsOperation) Path() []string

Path returns the path for the contains operation.

func (*ContainsOperation) Test added in v0.4.3

func (op *ContainsOperation) Test(doc any) (bool, error)

Test performs the contains test operation.

func (*ContainsOperation) ToCompact added in v0.4.3

func (op *ContainsOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*ContainsOperation) ToJSON added in v0.4.3

func (op *ContainsOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*ContainsOperation) Validate added in v0.4.3

func (op *ContainsOperation) Validate() error

Validate validates the contains operation.

type CopyOperation added in v0.4.3

type CopyOperation struct {
	BaseOp
	FromPath []string `json:"from"` // Source path
}

CopyOperation represents a copy operation that copies a value from one path to another.

func NewOpCopyOperation

func NewOpCopyOperation(path, from []string) *CopyOperation

NewOpCopyOperation creates a new OpCopyOperation operation.

func (*CopyOperation) Apply added in v0.4.3

func (o *CopyOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the copy operation.

func (*CopyOperation) Code added in v0.4.3

func (o *CopyOperation) Code() int

Code returns the operation code.

func (*CopyOperation) From added in v0.4.3

func (o *CopyOperation) From() []string

From returns the source path.

func (*CopyOperation) Op added in v0.4.3

func (o *CopyOperation) Op() internal.OpType

Op returns the operation type.

func (*CopyOperation) ToCompact added in v0.4.3

func (o *CopyOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*CopyOperation) ToJSON added in v0.4.3

func (o *CopyOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*CopyOperation) Validate added in v0.4.3

func (o *CopyOperation) Validate() error

Validate validates the copy operation.

type DefinedOperation added in v0.4.3

type DefinedOperation struct {
	BaseOp
}

DefinedOperation represents a test operation that checks if a path is defined.

func NewOpDefinedOperation

func NewOpDefinedOperation(path []string) *DefinedOperation

NewOpDefinedOperation creates a new OpDefinedOperation operation.

func (*DefinedOperation) Apply added in v0.4.3

func (o *DefinedOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the defined operation.

func (*DefinedOperation) Code added in v0.4.3

func (o *DefinedOperation) Code() int

Code returns the operation code.

func (*DefinedOperation) Not added in v0.4.3

func (o *DefinedOperation) Not() bool

Not returns false (defined operation doesn't support not modifier).

func (*DefinedOperation) Op added in v0.4.3

Op returns the operation type.

func (*DefinedOperation) Path added in v0.4.3

func (o *DefinedOperation) Path() []string

Path returns the path for the defined operation.

func (*DefinedOperation) Test added in v0.4.3

func (o *DefinedOperation) Test(doc interface{}) (bool, error)

Test performs the defined operation.

func (*DefinedOperation) ToCompact added in v0.4.3

func (o *DefinedOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*DefinedOperation) ToJSON added in v0.4.3

func (o *DefinedOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*DefinedOperation) Validate added in v0.4.3

func (o *DefinedOperation) Validate() error

Validate validates the defined operation.

type EndsOperation added in v0.4.3

type EndsOperation struct {
	BaseOp
	Value      string `json:"value"`       // Expected suffix
	IgnoreCase bool   `json:"ignore_case"` // Whether to ignore case
	NotFlag    bool   `json:"not"`         // Whether to negate the result
}

EndsOperation represents a test operation that checks if a string value ends with a specific suffix.

func NewOpEndsOperation

func NewOpEndsOperation(path []string, suffix string) *EndsOperation

NewOpEndsOperation creates a new OpEndsOperation operation.

func NewOpEndsOperationWithIgnoreCase

func NewOpEndsOperationWithIgnoreCase(path []string, suffix string, ignoreCase bool) *EndsOperation

NewOpEndsOperationWithIgnoreCase creates a new OpEndsOperation operation with ignore case option.

func (*EndsOperation) Apply added in v0.4.3

func (op *EndsOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the ends test operation to the document.

func (*EndsOperation) Code added in v0.4.3

func (op *EndsOperation) Code() int

Code returns the operation code.

func (*EndsOperation) Not added in v0.5.1

func (op *EndsOperation) Not() bool

Not returns the negation flag for this operation.

func (*EndsOperation) Op added in v0.4.3

func (op *EndsOperation) Op() internal.OpType

Op returns the operation type.

func (*EndsOperation) Path added in v0.4.3

func (op *EndsOperation) Path() []string

Path returns the operation path.

func (*EndsOperation) Test added in v0.4.3

func (op *EndsOperation) Test(doc any) (bool, error)

Test evaluates the ends predicate condition.

func (*EndsOperation) ToCompact added in v0.4.3

func (op *EndsOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*EndsOperation) ToJSON added in v0.4.3

func (op *EndsOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*EndsOperation) Validate added in v0.4.3

func (op *EndsOperation) Validate() error

Validate validates the ends operation.

type ExtendOperation added in v0.4.3

type ExtendOperation struct {
	BaseOp
	Properties map[string]interface{} `json:"props"`      // Properties to add
	DeleteNull bool                   `json:"deleteNull"` // Whether to delete null properties
}

ExtendOperation represents an object extend operation. path: target path props: properties to add/update deleteNull: whether to delete properties with null values Only supports object type fields.

func NewOpExtendOperation

func NewOpExtendOperation(path []string, properties map[string]interface{}, deleteNull bool) *ExtendOperation

NewOpExtendOperation creates a new object extend operation.

func (*ExtendOperation) Apply added in v0.4.3

func (op *ExtendOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the object extend operation.

func (*ExtendOperation) Code added in v0.4.3

func (op *ExtendOperation) Code() int

Code returns the operation code.

func (*ExtendOperation) Op added in v0.4.3

func (op *ExtendOperation) Op() internal.OpType

Op returns the operation type.

func (*ExtendOperation) ToCompact added in v0.4.3

func (op *ExtendOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*ExtendOperation) ToJSON added in v0.4.3

func (op *ExtendOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*ExtendOperation) Validate added in v0.4.3

func (op *ExtendOperation) Validate() error

Validate validates the extend operation.

type FlipOperation added in v0.4.3

type FlipOperation struct {
	BaseOp
}

FlipOperation represents a flip operation that inverts boolean values or converts other types to boolean and then inverts them

func NewOpFlipOperation

func NewOpFlipOperation(path []string) *FlipOperation

NewOpFlipOperation creates a new flip operation

func (*FlipOperation) Apply added in v0.4.3

func (op *FlipOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the flip operation to the document

func (*FlipOperation) Code added in v0.4.3

func (op *FlipOperation) Code() int

Code returns the operation code

func (*FlipOperation) Op added in v0.4.3

func (op *FlipOperation) Op() internal.OpType

Op returns the operation type

func (*FlipOperation) ToCompact added in v0.4.3

func (op *FlipOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*FlipOperation) ToJSON added in v0.4.3

func (op *FlipOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*FlipOperation) Validate added in v0.4.3

func (op *FlipOperation) Validate() error

Validate validates the flip operation.

type InOperation added in v0.4.3

type InOperation struct {
	BaseOp
	Value []interface{} `json:"value"` // Array of values to check against
}

InOperation represents a test operation that checks if a value is present in a specified array.

func NewOpInOperation

func NewOpInOperation(path []string, values []interface{}) *InOperation

NewOpInOperation creates a new OpInOperation operation.

func (*InOperation) Apply added in v0.4.3

func (op *InOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the in test operation to the document.

func (*InOperation) Code added in v0.4.3

func (op *InOperation) Code() int

Code returns the operation code.

func (*InOperation) Not added in v0.4.3

func (op *InOperation) Not() bool

Not returns false since this is not a NOT operation.

func (*InOperation) Op added in v0.4.3

func (op *InOperation) Op() internal.OpType

Op returns the operation type.

func (*InOperation) Path added in v0.4.3

func (op *InOperation) Path() []string

Path returns the operation path.

func (*InOperation) Test added in v0.4.3

func (op *InOperation) Test(doc any) (bool, error)

Test evaluates the in predicate condition.

func (*InOperation) ToCompact added in v0.4.3

func (op *InOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*InOperation) ToJSON added in v0.4.3

func (op *InOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*InOperation) Validate added in v0.4.3

func (op *InOperation) Validate() error

Validate validates the in operation.

type IncOperation added in v0.4.3

type IncOperation struct {
	BaseOp
	Inc float64 `json:"inc"` // Increment value
}

IncOperation represents an increment operation that increments a numeric value.

func NewOpIncOperation

func NewOpIncOperation(path []string, inc float64) *IncOperation

NewOpIncOperation creates a new OpIncOperation operation.

func (*IncOperation) Apply added in v0.4.3

func (op *IncOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the increment operation to the document.

func (*IncOperation) Code added in v0.4.3

func (op *IncOperation) Code() int

Code returns the operation code.

func (*IncOperation) Op added in v0.4.3

func (op *IncOperation) Op() internal.OpType

Op returns the operation type.

func (*IncOperation) Path added in v0.4.3

func (op *IncOperation) Path() []string

Path returns the operation path.

func (*IncOperation) ToCompact added in v0.4.3

func (op *IncOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*IncOperation) ToJSON added in v0.4.3

func (op *IncOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*IncOperation) Validate added in v0.4.3

func (op *IncOperation) Validate() error

Validate validates the increment operation.

type LessOperation added in v0.4.3

type LessOperation struct {
	BaseOp
	Value float64 `json:"value"` // Value to compare against
}

LessOperation represents a test operation that checks if a numeric value is less than a specified value.

func NewOpLessOperation

func NewOpLessOperation(path []string, value float64) *LessOperation

NewOpLessOperation creates a new OpLessOperation operation.

func (*LessOperation) Apply added in v0.4.3

func (op *LessOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the less test operation to the document.

func (*LessOperation) Code added in v0.4.3

func (op *LessOperation) Code() int

Code returns the operation code.

func (*LessOperation) Not added in v0.4.3

func (op *LessOperation) Not() bool

Not returns false since this is not a NOT operation.

func (*LessOperation) Op added in v0.4.3

func (op *LessOperation) Op() internal.OpType

Op returns the operation type.

func (*LessOperation) Path added in v0.4.3

func (op *LessOperation) Path() []string

Path returns the path for the less operation.

func (*LessOperation) Test added in v0.4.3

func (op *LessOperation) Test(doc any) (bool, error)

Test evaluates the less predicate condition.

func (*LessOperation) ToCompact added in v0.4.3

func (op *LessOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*LessOperation) ToJSON added in v0.4.3

func (op *LessOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*LessOperation) Validate added in v0.4.3

func (op *LessOperation) Validate() error

Validate validates the less operation.

type MatchesOperation added in v0.4.3

type MatchesOperation struct {
	BaseOp
	Pattern    string `json:"value"`       // The regex pattern string
	IgnoreCase bool   `json:"ignore_case"` // Case insensitive flag
	NotFlag    bool   `json:"not"`         // Whether to negate the result
	// contains filtered or unexported fields
}

MatchesOperation represents a "matches" predicate operation that checks if a string matches a regex pattern.

func NewOpMatchesOperation

func NewOpMatchesOperation(path []string, pattern string, ignoreCase bool) (*MatchesOperation, error)

NewOpMatchesOperation creates a new matches operation.

func NewOpMatchesOperationWithFlags added in v0.5.1

func NewOpMatchesOperationWithFlags(path []string, pattern string, ignoreCase bool, notFlag bool) (*MatchesOperation, error)

NewOpMatchesOperationWithFlags creates a new matches operation with full options.

func (*MatchesOperation) Apply added in v0.4.3

func (o *MatchesOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the matches operation.

func (*MatchesOperation) Code added in v0.4.3

func (o *MatchesOperation) Code() int

Code returns the operation code.

func (*MatchesOperation) Not added in v0.5.1

func (o *MatchesOperation) Not() bool

Not returns the negation flag.

func (*MatchesOperation) Op added in v0.4.3

Op returns the operation type.

func (*MatchesOperation) Path added in v0.4.3

func (o *MatchesOperation) Path() []string

Path returns the path for the matches operation.

func (*MatchesOperation) Test added in v0.4.3

func (o *MatchesOperation) Test(doc interface{}) (bool, error)

Test evaluates the matches predicate condition.

func (*MatchesOperation) ToCompact added in v0.4.3

func (o *MatchesOperation) ToCompact() (internal.CompactOperation, error)

ToCompact converts the operation to compact array representation.

func (*MatchesOperation) ToJSON added in v0.4.3

func (o *MatchesOperation) ToJSON() (internal.Operation, error)

ToJSON converts the operation to JSON representation.

func (*MatchesOperation) Validate added in v0.4.3

func (o *MatchesOperation) Validate() error

Validate validates the matches operation.

type MergeOperation added in v0.4.3

type MergeOperation struct {
	BaseOp
	Pos   float64                `json:"pos"`   // Merge position
	Props map[string]interface{} `json:"props"` // Properties to apply after merge
}

MergeOperation represents an array merge operation. path: target path pos: merge position (array index) props: properties to apply after merge (can be nil) Only supports array type fields.

func NewOpMergeOperation

func NewOpMergeOperation(path []string, pos float64, props map[string]interface{}) *MergeOperation

NewOpMergeOperation creates a new array merge operation.

func (*MergeOperation) Apply added in v0.4.3

func (op *MergeOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the merge operation following TypeScript reference.

func (*MergeOperation) Code added in v0.4.3

func (op *MergeOperation) Code() int

Code returns the operation code.

func (*MergeOperation) Op added in v0.4.3

func (op *MergeOperation) Op() internal.OpType

Op returns the operation type.

func (*MergeOperation) Path added in v0.4.3

func (op *MergeOperation) Path() []string

Path returns the operation path.

func (*MergeOperation) ToCompact added in v0.4.3

func (op *MergeOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*MergeOperation) ToJSON added in v0.4.3

func (op *MergeOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*MergeOperation) Validate added in v0.4.3

func (op *MergeOperation) Validate() error

Validate validates the merge operation.

type MoreOperation added in v0.4.3

type MoreOperation struct {
	BaseOp
	Value   float64 `json:"value"` // The number to compare against
	NotFlag bool    `json:"not"`   // Whether to negate the result
}

MoreOperation represents a "more" predicate operation that checks if a value is greater than a specified number.

func NewOpMoreOperation

func NewOpMoreOperation(path []string, value float64) *MoreOperation

NewOpMoreOperation creates a new more operation.

func NewOpMoreOperationWithFlags added in v0.5.1

func NewOpMoreOperationWithFlags(path []string, value float64, notFlag bool) *MoreOperation

NewOpMoreOperationWithFlags creates a new more operation with full options.

func (*MoreOperation) Apply added in v0.4.3

func (o *MoreOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the more operation.

func (*MoreOperation) Code added in v0.4.3

func (o *MoreOperation) Code() int

Code returns the operation code.

func (*MoreOperation) Not added in v0.5.1

func (o *MoreOperation) Not() bool

Not returns the negation flag.

func (*MoreOperation) Op added in v0.4.3

func (o *MoreOperation) Op() internal.OpType

Op returns the operation type.

func (*MoreOperation) Path added in v0.4.3

func (o *MoreOperation) Path() []string

Path returns the path for the more operation.

func (*MoreOperation) Test added in v0.4.3

func (o *MoreOperation) Test(doc interface{}) (bool, error)

Test evaluates the more predicate condition.

func (*MoreOperation) ToCompact added in v0.4.3

func (o *MoreOperation) ToCompact() (internal.CompactOperation, error)

ToCompact converts the operation to compact array representation.

func (*MoreOperation) ToJSON added in v0.4.3

func (o *MoreOperation) ToJSON() (internal.Operation, error)

ToJSON converts the operation to JSON representation.

func (*MoreOperation) Validate added in v0.4.3

func (o *MoreOperation) Validate() error

Validate validates the more operation.

type MoveOperation added in v0.4.3

type MoveOperation struct {
	BaseOp
	FromPath []string `json:"from"` // Source path
}

MoveOperation represents a move operation that moves a value from one path to another.

func NewOpMoveOperation

func NewOpMoveOperation(path, from []string) *MoveOperation

NewOpMoveOperation creates a new OpMoveOperation operation.

func (*MoveOperation) Apply added in v0.4.3

func (o *MoveOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the move operation following RFC 6902: remove then add.

func (*MoveOperation) Code added in v0.4.3

func (o *MoveOperation) Code() int

Code returns the operation code.

func (*MoveOperation) From added in v0.4.3

func (o *MoveOperation) From() []string

From returns the source path.

func (*MoveOperation) Op added in v0.4.3

func (o *MoveOperation) Op() internal.OpType

Op returns the operation type.

func (*MoveOperation) ToCompact added in v0.4.3

func (o *MoveOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*MoveOperation) ToJSON added in v0.4.3

func (o *MoveOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*MoveOperation) Validate added in v0.4.3

func (o *MoveOperation) Validate() error

Validate validates the move operation.

type NotOperation added in v0.4.3

type NotOperation struct {
	BaseOp
	Operations []interface{} `json:"apply"` // Array of operations to apply (then negate)
}

NotOperation represents a logical NOT operation that negates predicates.

func NewOpNotOperation

func NewOpNotOperation(operand internal.PredicateOp) *NotOperation

NewOpNotOperation creates a new NOT operation.

func NewOpNotOperationMultiple

func NewOpNotOperationMultiple(path []string, ops []interface{}) *NotOperation

NewOpNotOperationMultiple creates a new NOT operation with multiple operands.

func (*NotOperation) Apply added in v0.4.3

func (o *NotOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the NOT operation.

func (*NotOperation) Code added in v0.4.3

func (o *NotOperation) Code() int

Code returns the operation code.

func (*NotOperation) Not added in v0.4.3

func (o *NotOperation) Not() bool

Not returns true since this is a NOT operation.

func (*NotOperation) Op added in v0.4.3

func (o *NotOperation) Op() internal.OpType

Op returns the operation type.

func (*NotOperation) Ops added in v0.4.3

func (o *NotOperation) Ops() []internal.PredicateOp

Ops returns the operand operations.

func (*NotOperation) Path added in v0.4.3

func (o *NotOperation) Path() []string

Path returns the operation path.

func (*NotOperation) Test added in v0.4.3

func (o *NotOperation) Test(doc any) (bool, error)

Test evaluates the NOT predicate condition.

func (*NotOperation) ToCompact added in v0.4.3

func (o *NotOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*NotOperation) ToJSON added in v0.4.3

func (o *NotOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*NotOperation) Validate added in v0.4.3

func (o *NotOperation) Validate() error

Validate validates the NOT operation.

type Op

type Op = internal.Op

Op interface defines the core operation behavior.

type OpAndOperation

type OpAndOperation = AndOperation //nolint:revive // Backward compatibility alias

type OpContainsOperation

type OpContainsOperation = ContainsOperation //nolint:revive // Backward compatibility alias

type OpCopyOperation

type OpCopyOperation = CopyOperation //nolint:revive // Backward compatibility alias

type OpDefinedOperation

type OpDefinedOperation = DefinedOperation //nolint:revive // Backward compatibility alias

type OpEndsOperation

type OpEndsOperation = EndsOperation //nolint:revive // Backward compatibility alias

type OpExtendOperation

type OpExtendOperation = ExtendOperation //nolint:revive // Backward compatibility alias

type OrOperation added in v0.4.3

type OrOperation struct {
	BaseOp
	Operations []interface{} `json:"apply"` // Array of operations to apply
}

OrOperation represents an OR operation that combines multiple predicate operations.

func NewOpOrOperation

func NewOpOrOperation(path []string, ops []interface{}) *OrOperation

NewOpOrOperation creates a new OpOrOperation operation.

func (*OrOperation) Apply added in v0.4.3

func (o *OrOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the OR operation to the document.

func (*OrOperation) Code added in v0.4.3

func (o *OrOperation) Code() int

Code returns the operation code.

func (*OrOperation) Not added in v0.4.3

func (o *OrOperation) Not() bool

Not returns false since this is not a NOT operation.

func (*OrOperation) Op added in v0.4.3

func (o *OrOperation) Op() internal.OpType

Op returns the operation type.

func (*OrOperation) Ops added in v0.4.3

func (o *OrOperation) Ops() []internal.PredicateOp

Ops returns the predicate operations.

func (*OrOperation) Path added in v0.4.3

func (o *OrOperation) Path() []string

Path returns the path for the OR operation.

func (*OrOperation) Test added in v0.4.3

func (o *OrOperation) Test(doc interface{}) (bool, error)

Test performs the OR operation.

func (*OrOperation) ToCompact added in v0.4.3

func (o *OrOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*OrOperation) ToJSON added in v0.4.3

func (o *OrOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*OrOperation) Validate added in v0.4.3

func (o *OrOperation) Validate() error

Validate validates the OR operation.

type PredicateOp

type PredicateOp = internal.PredicateOp

PredicateOp represents predicate operations used for testing conditions.

type PredicateOpBase

type PredicateOpBase struct {
	BaseOp
	// contains filtered or unexported fields
}

PredicateOpBase provides common functionality for predicate operations.

func NewPredicateOp

func NewPredicateOp(path []string, not bool) PredicateOpBase

NewPredicateOp creates a new PredicateOpBase.

func (*PredicateOpBase) Not

func (p *PredicateOpBase) Not() bool

Not returns the negation flag.

type RemoveOperation added in v0.4.3

type RemoveOperation struct {
	BaseOp
	OldValue    interface{} `json:"oldValue,omitempty"` // The value that was removed (optional)
	HasOldValue bool        // Whether oldValue is explicitly set
}

RemoveOperation represents a remove operation that removes a value at a specified path.

func NewOpRemoveOperation

func NewOpRemoveOperation(path []string) *RemoveOperation

NewOpRemoveOperation creates a new OpRemoveOperation operation.

func NewOpRemoveOperationWithOldValue

func NewOpRemoveOperationWithOldValue(path []string, oldValue interface{}) *RemoveOperation

NewOpRemoveOperationWithOldValue creates a new OpRemoveOperation operation with oldValue.

func (*RemoveOperation) Apply added in v0.4.3

func (o *RemoveOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the remove operation to the document.

func (*RemoveOperation) Code added in v0.4.3

func (o *RemoveOperation) Code() int

Code returns the operation code.

func (*RemoveOperation) Op added in v0.4.3

Op returns the operation type.

func (*RemoveOperation) Path added in v0.4.3

func (o *RemoveOperation) Path() []string

Path returns the operation path.

func (*RemoveOperation) ToCompact added in v0.4.3

func (o *RemoveOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*RemoveOperation) ToJSON added in v0.4.3

func (o *RemoveOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*RemoveOperation) Validate added in v0.4.3

func (o *RemoveOperation) Validate() error

Validate validates the remove operation.

type ReplaceOperation added in v0.4.3

type ReplaceOperation struct {
	BaseOp
	Value    interface{} `json:"value"`              // New value
	OldValue interface{} `json:"oldValue,omitempty"` // The value that was replaced (optional)
}

ReplaceOperation represents a replace operation that replaces a value at a specified path.

func NewOpReplaceOperation

func NewOpReplaceOperation(path []string, value interface{}) *ReplaceOperation

NewOpReplaceOperation creates a new OpReplaceOperation operation.

func NewOpReplaceOperationWithOldValue

func NewOpReplaceOperationWithOldValue(path []string, value interface{}, oldValue interface{}) *ReplaceOperation

NewOpReplaceOperationWithOldValue creates a new OpReplaceOperation operation with oldValue.

func (*ReplaceOperation) Apply added in v0.4.3

func (o *ReplaceOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the replace operation to the document.

func (*ReplaceOperation) Code added in v0.4.3

func (o *ReplaceOperation) Code() int

Code returns the operation code.

func (*ReplaceOperation) Op added in v0.4.3

Op returns the operation type.

func (*ReplaceOperation) Path added in v0.4.3

func (o *ReplaceOperation) Path() []string

Path returns the operation path.

func (*ReplaceOperation) ToCompact added in v0.4.3

func (o *ReplaceOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*ReplaceOperation) ToJSON added in v0.4.3

func (o *ReplaceOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*ReplaceOperation) Validate added in v0.4.3

func (o *ReplaceOperation) Validate() error

Validate validates the replace operation.

type Result added in v0.4.3

type Result[T internal.Document] = internal.OpResult[T]

Result represents the result of applying an operation.

type SecondOrderPredicateOp

type SecondOrderPredicateOp = internal.SecondOrderPredicateOp

SecondOrderPredicateOp represents operations that combine multiple predicate operations.

type SplitOperation added in v0.4.3

type SplitOperation struct {
	BaseOp
	Pos   float64     `json:"pos"`   // Split position
	Props interface{} `json:"props"` // Properties to apply after split
}

SplitOperation represents a string split operation. path: target path pos: split position (rune index) props: properties to apply after split (can be nil) Only supports string type fields.

func NewOpSplitOperation

func NewOpSplitOperation(path []string, pos float64, props interface{}) *SplitOperation

NewOpSplitOperation creates a new string split operation.

func (*SplitOperation) Apply added in v0.4.3

func (op *SplitOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the split operation following TypeScript reference.

func (*SplitOperation) Code added in v0.4.3

func (op *SplitOperation) Code() int

Code returns the operation code.

func (*SplitOperation) Op added in v0.4.3

func (op *SplitOperation) Op() internal.OpType

Op returns the operation type.

func (*SplitOperation) Path added in v0.4.3

func (op *SplitOperation) Path() []string

Path returns the operation path.

func (*SplitOperation) ToCompact added in v0.4.3

func (op *SplitOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*SplitOperation) ToJSON added in v0.4.3

func (op *SplitOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*SplitOperation) Validate added in v0.4.3

func (op *SplitOperation) Validate() error

Validate validates the split operation.

type StartsOperation added in v0.4.3

type StartsOperation struct {
	BaseOp
	Value      string `json:"value"`       // Expected prefix
	IgnoreCase bool   `json:"ignore_case"` // Whether to ignore case
	NotFlag    bool   `json:"not"`         // Whether to negate the result
}

StartsOperation represents a test operation that checks if a string value starts with a specific prefix.

func NewOpStartsOperation

func NewOpStartsOperation(path []string, prefix string) *StartsOperation

NewOpStartsOperation creates a new OpStartsOperation operation.

func NewOpStartsOperationWithIgnoreCase

func NewOpStartsOperationWithIgnoreCase(path []string, prefix string, ignoreCase bool) *StartsOperation

NewOpStartsOperationWithIgnoreCase creates a new OpStartsOperation operation with ignore case option.

func NewOpStartsOperationWithNot added in v0.5.1

func NewOpStartsOperationWithNot(path []string, prefix string, not bool) *StartsOperation

NewOpStartsOperationWithNot creates a new OpStartsOperation operation with negation.

func (*StartsOperation) Apply added in v0.4.3

func (op *StartsOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the starts test operation to the document.

func (*StartsOperation) Code added in v0.4.3

func (op *StartsOperation) Code() int

Code returns the operation code.

func (*StartsOperation) Not added in v0.5.1

func (op *StartsOperation) Not() bool

Not returns the negation flag for this operation.

func (*StartsOperation) Op added in v0.4.3

func (op *StartsOperation) Op() internal.OpType

Op returns the operation type.

func (*StartsOperation) Path added in v0.4.3

func (op *StartsOperation) Path() []string

Path returns the operation path.

func (*StartsOperation) Test added in v0.4.3

func (op *StartsOperation) Test(doc any) (bool, error)

Test evaluates the starts predicate condition.

func (*StartsOperation) ToCompact added in v0.4.3

func (op *StartsOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*StartsOperation) ToJSON added in v0.4.3

func (op *StartsOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*StartsOperation) Validate added in v0.4.3

func (op *StartsOperation) Validate() error

Validate validates the starts operation.

type StrDelOperation added in v0.4.3

type StrDelOperation struct {
	BaseOp
	Pos float64 `json:"pos"` // Delete position
	Len float64 `json:"len"` // Number of characters to delete
	Str string  `json:"str"` // Specific string to delete (optional)
}

StrDelOperation represents a string delete operation. path: target path pos: start position (rune index) len: number of runes to delete (when Str is empty) str: specific string to delete (when not empty, takes precedence) Only supports string type fields.

func NewOpStrDelOperation

func NewOpStrDelOperation(path []string, pos, length float64) *StrDelOperation

NewOpStrDelOperation creates a new string delete operation with length.

func NewOpStrDelOperationWithStr

func NewOpStrDelOperationWithStr(path []string, pos float64, str string) *StrDelOperation

NewOpStrDelOperationWithStr creates a new string delete operation with specific string.

func (*StrDelOperation) Apply added in v0.4.3

func (op *StrDelOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the string delete operation.

func (*StrDelOperation) Code added in v0.4.3

func (op *StrDelOperation) Code() int

Code returns the operation code.

func (*StrDelOperation) Op added in v0.4.3

func (op *StrDelOperation) Op() internal.OpType

Op returns the operation type.

func (*StrDelOperation) ToCompact added in v0.4.3

func (op *StrDelOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*StrDelOperation) ToJSON added in v0.4.3

func (op *StrDelOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*StrDelOperation) Validate added in v0.4.3

func (op *StrDelOperation) Validate() error

Validate validates the string delete operation.

type StrInsOperation added in v0.4.3

type StrInsOperation struct {
	BaseOp
	Pos float64 `json:"pos"` // Insert position
	Str string  `json:"str"` // String to insert
}

StrInsOperation represents a string insert operation. path: target path pos: insert position (rune index) str: string to insert Only supports string type fields.

func NewOpStrInsOperation

func NewOpStrInsOperation(path []string, pos float64, str string) *StrInsOperation

NewOpStrInsOperation creates a new string insert operation.

func (*StrInsOperation) Apply added in v0.4.3

func (op *StrInsOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the string insert operation.

func (*StrInsOperation) Code added in v0.4.3

func (op *StrInsOperation) Code() int

Code returns the operation code.

func (*StrInsOperation) Op added in v0.4.3

func (op *StrInsOperation) Op() internal.OpType

Op returns the operation type.

func (*StrInsOperation) ToCompact added in v0.4.3

func (op *StrInsOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*StrInsOperation) ToJSON added in v0.4.3

func (op *StrInsOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*StrInsOperation) Validate added in v0.4.3

func (op *StrInsOperation) Validate() error

Validate validates the string insert operation.

type TestOperation added in v0.4.3

type TestOperation struct {
	BaseOp
	Value   interface{} `json:"value"`         // Expected value
	NotFlag bool        `json:"not,omitempty"` // Whether to negate the test
}

TestOperation represents a test operation that checks if a value equals a specified value.

func NewOpTestOperation

func NewOpTestOperation(path []string, value interface{}) *TestOperation

NewOpTestOperation creates a new OpTestOperation operation.

func (*TestOperation) Apply added in v0.4.3

func (o *TestOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the test operation.

func (*TestOperation) Code added in v0.4.3

func (o *TestOperation) Code() int

Code returns the operation code.

func (*TestOperation) Not added in v0.4.3

func (o *TestOperation) Not() bool

Not returns whether this operation is negated.

func (*TestOperation) Op added in v0.4.3

func (o *TestOperation) Op() internal.OpType

Op returns the operation type.

func (*TestOperation) Path added in v0.4.3

func (o *TestOperation) Path() []string

Path returns the operation path.

func (*TestOperation) Test added in v0.4.3

func (o *TestOperation) Test(doc interface{}) (bool, error)

Test performs the test operation.

func (*TestOperation) ToCompact added in v0.4.3

func (o *TestOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*TestOperation) ToJSON added in v0.4.3

func (o *TestOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*TestOperation) Validate added in v0.4.3

func (o *TestOperation) Validate() error

Validate validates the test operation.

type TestStringLenOperation added in v0.4.3

type TestStringLenOperation struct {
	BaseOp
	Length  float64 `json:"len"` // Expected string length
	NotFlag bool    `json:"not"` // Whether to negate the result
}

TestStringLenOperation represents a test operation that checks if a string value has a specific length.

func NewOpTestStringLenOperation

func NewOpTestStringLenOperation(path []string, expectedLength float64) *TestStringLenOperation

NewOpTestStringLenOperation creates a new OpTestStringLenOperation operation.

func NewOpTestStringLenOperationWithNot

func NewOpTestStringLenOperationWithNot(path []string, expectedLength float64, not bool) *TestStringLenOperation

NewOpTestStringLenOperationWithNot creates a new OpTestStringLenOperation operation with not flag.

func (*TestStringLenOperation) Apply added in v0.4.3

func (op *TestStringLenOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the test string length operation to the document.

func (*TestStringLenOperation) Code added in v0.4.3

func (op *TestStringLenOperation) Code() int

Code returns the operation code.

func (*TestStringLenOperation) Not added in v0.4.3

func (op *TestStringLenOperation) Not() bool

Not returns whether this is a negation predicate.

func (*TestStringLenOperation) Op added in v0.4.3

Op returns the operation type.

func (*TestStringLenOperation) Path added in v0.4.3

func (op *TestStringLenOperation) Path() []string

Path returns the operation path.

func (*TestStringLenOperation) Test added in v0.5.1

func (op *TestStringLenOperation) Test(doc any) (bool, error)

Test tests the string length condition on the document.

func (*TestStringLenOperation) ToCompact added in v0.4.3

ToCompact serializes the operation to compact format.

func (*TestStringLenOperation) ToJSON added in v0.4.3

ToJSON serializes the operation to JSON format.

func (*TestStringLenOperation) Validate added in v0.4.3

func (op *TestStringLenOperation) Validate() error

Validate validates the test string length operation.

type TestStringOperation added in v0.4.3

type TestStringOperation struct {
	BaseOp
	Str        string `json:"str"`                   // Expected string value
	Pos        int    `json:"pos"`                   // Position within string
	NotFlag    bool   `json:"not,omitempty"`         // Whether to negate the result
	IgnoreCase bool   `json:"ignore_case,omitempty"` // Whether to ignore case
}

TestStringOperation represents a test operation that checks if a value is a string and matches a pattern.

func NewOpTestStringOperation

func NewOpTestStringOperation(path []string, expectedValue string) *TestStringOperation

NewOpTestStringOperation creates a new OpTestStringOperation operation.

func NewOpTestStringOperationWithIgnoreCase added in v0.5.1

func NewOpTestStringOperationWithIgnoreCase(path []string, expectedValue string, pos float64, notFlag bool, ignoreCase bool) *TestStringOperation

NewOpTestStringOperationWithIgnoreCase creates a new OpTestStringOperation operation with ignore case flag.

func NewOpTestStringOperationWithPos

func NewOpTestStringOperationWithPos(path []string, expectedValue string, pos float64) *TestStringOperation

NewOpTestStringOperationWithPos creates a new OpTestStringOperation operation with position.

func NewOpTestStringOperationWithPosAndNot added in v0.5.1

func NewOpTestStringOperationWithPosAndNot(path []string, expectedValue string, pos float64, notFlag bool) *TestStringOperation

NewOpTestStringOperationWithPosAndNot creates a new OpTestStringOperation operation with position and not flag.

func (*TestStringOperation) Apply added in v0.4.3

func (op *TestStringOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the test string operation to the document.

func (*TestStringOperation) Code added in v0.4.3

func (op *TestStringOperation) Code() int

Code returns the operation code.

func (*TestStringOperation) Not added in v0.5.1

func (op *TestStringOperation) Not() bool

Not returns whether this operation is a negation predicate.

func (*TestStringOperation) Op added in v0.4.3

Op returns the operation type.

func (*TestStringOperation) Path added in v0.4.3

func (op *TestStringOperation) Path() []string

Path returns the operation path.

func (*TestStringOperation) Test added in v0.4.3

func (op *TestStringOperation) Test(doc any) (bool, error)

Test evaluates the test string predicate condition.

func (*TestStringOperation) ToCompact added in v0.4.3

ToCompact serializes the operation to compact format.

func (*TestStringOperation) ToJSON added in v0.4.3

func (op *TestStringOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*TestStringOperation) Validate added in v0.4.3

func (op *TestStringOperation) Validate() error

Validate validates the test string operation.

type TestTypeOperation added in v0.4.3

type TestTypeOperation struct {
	BaseOp
	Types []string `json:"type"` // Expected type names
}

TestTypeOperation represents a test operation that checks if a value is of a specific type.

func NewOpTestTypeOperation

func NewOpTestTypeOperation(path []string, expectedType string) *TestTypeOperation

NewOpTestTypeOperation creates a new OpTestTypeOperation operation.

func NewOpTestTypeOperationMultiple

func NewOpTestTypeOperationMultiple(path []string, expectedTypes []string) *TestTypeOperation

NewOpTestTypeOperationMultiple creates a new OpTestTypeOperation operation with multiple internal.

func (*TestTypeOperation) Apply added in v0.4.3

func (op *TestTypeOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the test type operation to the document.

func (*TestTypeOperation) Code added in v0.4.3

func (op *TestTypeOperation) Code() int

Code returns the operation code.

func (*TestTypeOperation) Not added in v0.4.3

func (op *TestTypeOperation) Not() bool

Not returns false (test_type operation doesn't support not modifier).

func (*TestTypeOperation) Op added in v0.4.3

Op returns the operation type.

func (*TestTypeOperation) Path added in v0.4.3

func (op *TestTypeOperation) Path() []string

Path returns the operation path.

func (*TestTypeOperation) Test added in v0.4.3

func (op *TestTypeOperation) Test(doc any) (bool, error)

Test evaluates the test type predicate condition.

func (*TestTypeOperation) ToCompact added in v0.4.3

func (op *TestTypeOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*TestTypeOperation) ToJSON added in v0.4.3

func (op *TestTypeOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*TestTypeOperation) Validate added in v0.4.3

func (op *TestTypeOperation) Validate() error

Validate validates the test type operation.

type TypeOperation added in v0.4.3

type TypeOperation struct {
	BaseOp
	TypeValue string `json:"value"` // Expected type name
}

TypeOperation represents a type operation that checks if a value is of a specific type.

func NewOpTypeOperation

func NewOpTypeOperation(path []string, expectedType string) *TypeOperation

NewOpTypeOperation creates a new OpTypeOperation operation.

func (*TypeOperation) Apply added in v0.4.3

func (op *TypeOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the type operation to the document.

func (*TypeOperation) Code added in v0.4.3

func (op *TypeOperation) Code() int

Code returns the operation code.

func (*TypeOperation) Not added in v0.4.3

func (op *TypeOperation) Not() bool

Not returns false (type operation doesn't support not modifier).

func (*TypeOperation) Op added in v0.4.3

func (op *TypeOperation) Op() internal.OpType

Op returns the operation type.

func (*TypeOperation) Path added in v0.4.3

func (op *TypeOperation) Path() []string

Path returns the operation path.

func (*TypeOperation) Test added in v0.4.3

func (op *TypeOperation) Test(doc any) (bool, error)

Test evaluates the type predicate condition.

func (*TypeOperation) ToCompact added in v0.4.3

func (op *TypeOperation) ToCompact() (internal.CompactOperation, error)

ToCompact serializes the operation to compact format.

func (*TypeOperation) ToJSON added in v0.4.3

func (op *TypeOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*TypeOperation) Validate added in v0.4.3

func (op *TypeOperation) Validate() error

Validate validates the type operation.

type UndefinedOperation added in v0.4.3

type UndefinedOperation struct {
	BaseOp
}

UndefinedOperation represents an undefined operation that checks if a path doesn't exist.

func NewOpUndefinedOperation

func NewOpUndefinedOperation(path []string) *UndefinedOperation

NewOpUndefinedOperation creates a new undefined operation.

func (*UndefinedOperation) Apply added in v0.4.3

func (o *UndefinedOperation) Apply(doc any) (internal.OpResult[any], error)

Apply applies the undefined operation.

func (*UndefinedOperation) Code added in v0.4.3

func (o *UndefinedOperation) Code() int

Code returns the operation code.

func (*UndefinedOperation) Not added in v0.4.3

func (o *UndefinedOperation) Not() bool

Not returns false (undefined operation doesn't support not modifier).

func (*UndefinedOperation) Op added in v0.4.3

Op returns the operation type.

func (*UndefinedOperation) Path added in v0.4.3

func (o *UndefinedOperation) Path() []string

Path returns the path for the undefined operation.

func (*UndefinedOperation) Test added in v0.4.3

func (o *UndefinedOperation) Test(doc interface{}) (bool, error)

Test performs the undefined operation.

func (*UndefinedOperation) ToCompact added in v0.4.3

ToCompact serializes the operation to compact format.

func (*UndefinedOperation) ToJSON added in v0.4.3

func (o *UndefinedOperation) ToJSON() (internal.Operation, error)

ToJSON serializes the operation to JSON format.

func (*UndefinedOperation) Validate added in v0.4.3

func (o *UndefinedOperation) Validate() error

Validate validates the undefined operation.

Jump to

Keyboard shortcuts

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