Documentation
¶
Overview ¶
Package op provides implementations for JSON Patch operations.
Index ¶
- Variables
- func DeepClone(value any) (any, error)
- func ToFloat64(val any) (float64, bool)
- type AddOperation
- func (a *AddOperation) Apply(doc any) (internal.OpResult[any], error)
- func (a *AddOperation) Code() int
- func (a *AddOperation) Op() internal.OpType
- func (a *AddOperation) ToCompact() (internal.CompactOperation, error)
- func (a *AddOperation) ToJSON() (internal.Operation, error)
- func (a *AddOperation) Validate() error
- type AndOperation
- func (ao *AndOperation) Apply(doc any) (internal.OpResult[any], error)
- func (ao *AndOperation) Code() int
- func (ao *AndOperation) Op() internal.OpType
- func (ao *AndOperation) Ops() []internal.PredicateOp
- func (ao *AndOperation) Test(doc any) (bool, error)
- func (ao *AndOperation) ToCompact() (internal.CompactOperation, error)
- func (ao *AndOperation) ToJSON() (internal.Operation, error)
- func (ao *AndOperation) Validate() error
- type BaseOp
- type ContainsOperation
- func (co *ContainsOperation) Apply(doc any) (internal.OpResult[any], error)
- func (co *ContainsOperation) Code() int
- func (co *ContainsOperation) Op() internal.OpType
- func (co *ContainsOperation) Test(doc any) (bool, error)
- func (co *ContainsOperation) ToCompact() (internal.CompactOperation, error)
- func (co *ContainsOperation) ToJSON() (internal.Operation, error)
- func (co *ContainsOperation) Validate() error
- type CopyOperation
- func (c *CopyOperation) Apply(doc any) (internal.OpResult[any], error)
- func (c *CopyOperation) Code() int
- func (c *CopyOperation) Op() internal.OpType
- func (c *CopyOperation) ToCompact() (internal.CompactOperation, error)
- func (c *CopyOperation) ToJSON() (internal.Operation, error)
- func (c *CopyOperation) Validate() error
- type DefinedOperation
- func (d *DefinedOperation) Apply(doc any) (internal.OpResult[any], error)
- func (d *DefinedOperation) Code() int
- func (d *DefinedOperation) Op() internal.OpType
- func (d *DefinedOperation) Test(doc any) (bool, error)
- func (d *DefinedOperation) ToCompact() (internal.CompactOperation, error)
- func (d *DefinedOperation) ToJSON() (internal.Operation, error)
- func (d *DefinedOperation) Validate() error
- type EndsOperation
- func (e *EndsOperation) Apply(doc any) (internal.OpResult[any], error)
- func (e *EndsOperation) Code() int
- func (e *EndsOperation) Op() internal.OpType
- func (e *EndsOperation) Test(doc any) (bool, error)
- func (e *EndsOperation) ToCompact() (internal.CompactOperation, error)
- func (e *EndsOperation) ToJSON() (internal.Operation, error)
- func (e *EndsOperation) Validate() error
- type ExtendOperation
- func (ex *ExtendOperation) Apply(doc any) (internal.OpResult[any], error)
- func (ex *ExtendOperation) Code() int
- func (ex *ExtendOperation) Op() internal.OpType
- func (ex *ExtendOperation) ToCompact() (internal.CompactOperation, error)
- func (ex *ExtendOperation) ToJSON() (internal.Operation, error)
- func (ex *ExtendOperation) Validate() error
- type FlipOperation
- func (f *FlipOperation) Apply(doc any) (internal.OpResult[any], error)
- func (f *FlipOperation) Code() int
- func (f *FlipOperation) Op() internal.OpType
- func (f *FlipOperation) ToCompact() (internal.CompactOperation, error)
- func (f *FlipOperation) ToJSON() (internal.Operation, error)
- func (f *FlipOperation) Validate() error
- type InOperation
- func (in *InOperation) Apply(doc any) (internal.OpResult[any], error)
- func (in *InOperation) Code() int
- func (in *InOperation) Op() internal.OpType
- func (in *InOperation) Test(doc any) (bool, error)
- func (in *InOperation) ToCompact() (internal.CompactOperation, error)
- func (in *InOperation) ToJSON() (internal.Operation, error)
- func (in *InOperation) Validate() error
- type IncOperation
- func (ic *IncOperation) Apply(doc any) (internal.OpResult[any], error)
- func (ic *IncOperation) Code() int
- func (ic *IncOperation) Op() internal.OpType
- func (ic *IncOperation) ToCompact() (internal.CompactOperation, error)
- func (ic *IncOperation) ToJSON() (internal.Operation, error)
- func (ic *IncOperation) Validate() error
- type LessOperation
- func (l *LessOperation) Apply(doc any) (internal.OpResult[any], error)
- func (l *LessOperation) Code() int
- func (l *LessOperation) Op() internal.OpType
- func (l *LessOperation) Test(doc any) (bool, error)
- func (l *LessOperation) ToCompact() (internal.CompactOperation, error)
- func (l *LessOperation) ToJSON() (internal.Operation, error)
- func (l *LessOperation) Validate() error
- type MatchesOperation
- func (ma *MatchesOperation) Apply(doc any) (internal.OpResult[any], error)
- func (ma *MatchesOperation) Code() int
- func (ma *MatchesOperation) Op() internal.OpType
- func (ma *MatchesOperation) Test(doc any) (bool, error)
- func (ma *MatchesOperation) ToCompact() (internal.CompactOperation, error)
- func (ma *MatchesOperation) ToJSON() (internal.Operation, error)
- func (ma *MatchesOperation) Validate() error
- type MergeOperation
- func (mg *MergeOperation) Apply(doc any) (internal.OpResult[any], error)
- func (mg *MergeOperation) Code() int
- func (mg *MergeOperation) Op() internal.OpType
- func (mg *MergeOperation) ToCompact() (internal.CompactOperation, error)
- func (mg *MergeOperation) ToJSON() (internal.Operation, error)
- func (mg *MergeOperation) Validate() error
- type MoreOperation
- func (mo *MoreOperation) Apply(doc any) (internal.OpResult[any], error)
- func (mo *MoreOperation) Code() int
- func (mo *MoreOperation) Op() internal.OpType
- func (mo *MoreOperation) Test(doc any) (bool, error)
- func (mo *MoreOperation) ToCompact() (internal.CompactOperation, error)
- func (mo *MoreOperation) ToJSON() (internal.Operation, error)
- func (mo *MoreOperation) Validate() error
- type MoveOperation
- func (m *MoveOperation) Apply(doc any) (internal.OpResult[any], error)
- func (m *MoveOperation) Code() int
- func (m *MoveOperation) Op() internal.OpType
- func (m *MoveOperation) ToCompact() (internal.CompactOperation, error)
- func (m *MoveOperation) ToJSON() (internal.Operation, error)
- func (m *MoveOperation) Validate() error
- type NotOperation
- func (n *NotOperation) Apply(doc any) (internal.OpResult[any], error)
- func (n *NotOperation) Code() int
- func (n *NotOperation) Not() bool
- func (n *NotOperation) Op() internal.OpType
- func (n *NotOperation) Ops() []internal.PredicateOp
- func (n *NotOperation) Test(doc any) (bool, error)
- func (n *NotOperation) ToCompact() (internal.CompactOperation, error)
- func (n *NotOperation) ToJSON() (internal.Operation, error)
- func (n *NotOperation) Validate() error
- type Op
- type OrOperation
- func (oo *OrOperation) Apply(doc any) (internal.OpResult[any], error)
- func (oo *OrOperation) Code() int
- func (oo *OrOperation) Op() internal.OpType
- func (oo *OrOperation) Ops() []internal.PredicateOp
- func (oo *OrOperation) Test(doc any) (bool, error)
- func (oo *OrOperation) ToCompact() (internal.CompactOperation, error)
- func (oo *OrOperation) ToJSON() (internal.Operation, error)
- func (oo *OrOperation) Validate() error
- type PredicateOp
- type RemoveOperation
- func (r *RemoveOperation) Apply(doc any) (internal.OpResult[any], error)
- func (r *RemoveOperation) Code() int
- func (r *RemoveOperation) Op() internal.OpType
- func (r *RemoveOperation) ToCompact() (internal.CompactOperation, error)
- func (r *RemoveOperation) ToJSON() (internal.Operation, error)
- func (r *RemoveOperation) Validate() error
- type ReplaceOperation
- func (rp *ReplaceOperation) Apply(doc any) (internal.OpResult[any], error)
- func (rp *ReplaceOperation) Code() int
- func (rp *ReplaceOperation) Op() internal.OpType
- func (rp *ReplaceOperation) ToCompact() (internal.CompactOperation, error)
- func (rp *ReplaceOperation) ToJSON() (internal.Operation, error)
- func (rp *ReplaceOperation) Validate() error
- type Result
- type SecondOrderPredicateOp
- type SplitOperation
- func (sp *SplitOperation) Apply(doc any) (internal.OpResult[any], error)
- func (sp *SplitOperation) Code() int
- func (sp *SplitOperation) Op() internal.OpType
- func (sp *SplitOperation) ToCompact() (internal.CompactOperation, error)
- func (sp *SplitOperation) ToJSON() (internal.Operation, error)
- func (sp *SplitOperation) Validate() error
- type StartsOperation
- func (s *StartsOperation) Apply(doc any) (internal.OpResult[any], error)
- func (s *StartsOperation) Code() int
- func (s *StartsOperation) Op() internal.OpType
- func (s *StartsOperation) Test(doc any) (bool, error)
- func (s *StartsOperation) ToCompact() (internal.CompactOperation, error)
- func (s *StartsOperation) ToJSON() (internal.Operation, error)
- func (s *StartsOperation) Validate() error
- type StrDelOperation
- func (sd *StrDelOperation) Apply(doc any) (internal.OpResult[any], error)
- func (sd *StrDelOperation) Code() int
- func (sd *StrDelOperation) Op() internal.OpType
- func (sd *StrDelOperation) ToCompact() (internal.CompactOperation, error)
- func (sd *StrDelOperation) ToJSON() (internal.Operation, error)
- func (sd *StrDelOperation) Validate() error
- type StrInsOperation
- func (si *StrInsOperation) Apply(doc any) (internal.OpResult[any], error)
- func (si *StrInsOperation) Code() int
- func (si *StrInsOperation) Op() internal.OpType
- func (si *StrInsOperation) ToCompact() (internal.CompactOperation, error)
- func (si *StrInsOperation) ToJSON() (internal.Operation, error)
- func (si *StrInsOperation) Validate() error
- type TestOperation
- func (t *TestOperation) Apply(doc any) (internal.OpResult[any], error)
- func (t *TestOperation) Code() int
- func (t *TestOperation) Not() bool
- func (t *TestOperation) Op() internal.OpType
- func (t *TestOperation) Test(doc any) (bool, error)
- func (t *TestOperation) ToCompact() (internal.CompactOperation, error)
- func (t *TestOperation) ToJSON() (internal.Operation, error)
- func (t *TestOperation) Validate() error
- type TestStringLenOperation
- func (tl *TestStringLenOperation) Apply(doc any) (internal.OpResult[any], error)
- func (tl *TestStringLenOperation) Code() int
- func (tl *TestStringLenOperation) Not() bool
- func (tl *TestStringLenOperation) Op() internal.OpType
- func (tl *TestStringLenOperation) Test(doc any) (bool, error)
- func (tl *TestStringLenOperation) ToCompact() (internal.CompactOperation, error)
- func (tl *TestStringLenOperation) ToJSON() (internal.Operation, error)
- func (tl *TestStringLenOperation) Validate() error
- type TestStringOperation
- func (ts *TestStringOperation) Apply(doc any) (internal.OpResult[any], error)
- func (ts *TestStringOperation) Code() int
- func (ts *TestStringOperation) Not() bool
- func (ts *TestStringOperation) Op() internal.OpType
- func (ts *TestStringOperation) Test(doc any) (bool, error)
- func (ts *TestStringOperation) ToCompact() (internal.CompactOperation, error)
- func (ts *TestStringOperation) ToJSON() (internal.Operation, error)
- func (ts *TestStringOperation) Validate() error
- type TestTypeOperation
- func (tt *TestTypeOperation) Apply(doc any) (internal.OpResult[any], error)
- func (tt *TestTypeOperation) Code() int
- func (tt *TestTypeOperation) Op() internal.OpType
- func (tt *TestTypeOperation) Test(doc any) (bool, error)
- func (tt *TestTypeOperation) ToCompact() (internal.CompactOperation, error)
- func (tt *TestTypeOperation) ToJSON() (internal.Operation, error)
- func (tt *TestTypeOperation) Validate() error
- type TypeOperation
- func (tp *TypeOperation) Apply(doc any) (internal.OpResult[any], error)
- func (tp *TypeOperation) Code() int
- func (tp *TypeOperation) Op() internal.OpType
- func (tp *TypeOperation) Test(doc any) (bool, error)
- func (tp *TypeOperation) ToCompact() (internal.CompactOperation, error)
- func (tp *TypeOperation) ToJSON() (internal.Operation, error)
- func (tp *TypeOperation) Validate() error
- type UndefinedOperation
- func (u *UndefinedOperation) Apply(doc any) (internal.OpResult[any], error)
- func (u *UndefinedOperation) Code() int
- func (u *UndefinedOperation) Op() internal.OpType
- func (u *UndefinedOperation) Test(doc any) (bool, error)
- func (u *UndefinedOperation) ToCompact() (internal.CompactOperation, error)
- func (u *UndefinedOperation) ToJSON() (internal.Operation, error)
- func (u *UndefinedOperation) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ( // Core path errors ErrPathNotFound = errors.New("path not found") ErrInvalidPath = errors.New("invalid path") ErrPathEmpty = errors.New("path cannot be empty") ErrFromPathEmpty = errors.New("from path cannot be empty") ErrPathsIdentical = errors.New("cannot move into own children") // Array operation errors ErrIndexOutOfRange = errors.New("index out of range") ErrNotAnArray = errors.New("not an array") ErrArrayTooSmall = errors.New("array must have at least 2 elements") ErrPositionOutOfBounds = errors.New("position out of bounds") ErrPositionNegative = errors.New("position cannot be negative") ErrInvalidTarget = errors.New("invalid target") // Type validation errors 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") ErrContainsValueMustBeString = errors.New("contains operation value must be a string") // Operation execution errors 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 ErrCannotReplace = errors.New("path not found for replace") ErrCannotAddToValue = errors.New("cannot add to non-object/non-array value") ErrCannotRemoveFromValue = errors.New("cannot remove from non-object/non-array document") 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 ErrPositionOutOfStringRange = errors.New("position out of string range") 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("length cannot be negative") // Type comparison errors ErrTypeMismatch = errors.New("type mismatch") ErrContainsMismatch = errors.New("contains check failed") // Predicate operation errors ErrInvalidPredicateInAnd = errors.New("invalid predicate in and operation") ErrInvalidPredicateInNot = errors.New("invalid predicate in not operation") ErrInvalidPredicateInOr = errors.New("invalid predicate in or operation") ErrNotNoOperands = errors.New("not operation requires operands") // Operation modification errors ErrCannotModifyRootArray = errors.New("cannot modify root array directly") ErrCannotUpdateParent = errors.New("cannot update parent") ErrCannotUpdateGrandparent = errors.New("cannot update grandparent") // Value conversion errors ErrCannotConvertNilToString = errors.New("cannot convert nil to string") ErrCannotConvertToString = errors.New("cannot convert value to string") // Test operation errors ErrTestOperationNumberStringMismatch = errors.New("number is not equal to string") ErrTestOperationStringNotEquivalent = errors.New("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
Functions ¶
Types ¶
type AddOperation ¶ added in v0.4.3
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 any) *AddOperation
NewAdd creates a new add operation.
func (*AddOperation) Code ¶ added in v0.4.3
func (a *AddOperation) Code() int
Code returns the operation code.
func (*AddOperation) Op ¶ added in v0.4.3
func (a *AddOperation) Op() internal.OpType
Op returns the operation type.
func (*AddOperation) ToCompact ¶ added in v0.4.3
func (a *AddOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*AddOperation) ToJSON ¶ added in v0.4.3
func (a *AddOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*AddOperation) Validate ¶ added in v0.4.3
func (a *AddOperation) Validate() error
Validate validates the add operation.
type AndOperation ¶ added in v0.4.3
AndOperation represents an and operation that combines multiple predicate operations.
func NewAnd ¶ added in v0.4.3
func NewAnd(path []string, ops []any) *AndOperation
NewAnd creates a new AND operation.
func (*AndOperation) Code ¶ added in v0.4.3
func (ao *AndOperation) Code() int
Code returns the operation code.
func (*AndOperation) Op ¶ added in v0.4.3
func (ao *AndOperation) Op() internal.OpType
Op returns the operation type.
func (*AndOperation) Ops ¶ added in v0.4.3
func (ao *AndOperation) Ops() []internal.PredicateOp
Ops returns the predicate operations.
func (*AndOperation) Test ¶ added in v0.4.3
func (ao *AndOperation) Test(doc any) (bool, error)
Test performs the AND operation.
func (*AndOperation) ToCompact ¶ added in v0.4.3
func (ao *AndOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*AndOperation) ToJSON ¶ added in v0.4.3
func (ao *AndOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*AndOperation) Validate ¶ added in v0.4.3
func (ao *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. It stores the target path and optional source path (for move/copy operations). All operation types embed BaseOp to inherit path management functionality.
func NewBaseOp ¶
NewBaseOp creates a new BaseOp with the given path. The path is a JSON Pointer path represented as a slice of string segments.
func NewBaseOpWithFrom ¶
NewBaseOpWithFrom creates a new BaseOp with both target path and source path. This is used for move and copy operations that require both paths.
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
}
ContainsOperation represents a contains operation that tests if a string contains a substring.
func NewContains ¶ added in v0.4.3
func NewContains(path []string, substring string) *ContainsOperation
NewContains creates a new contains operation.
func NewContainsWithIgnoreCase ¶ added in v0.4.3
func NewContainsWithIgnoreCase(path []string, substring string, ignoreCase bool) *ContainsOperation
NewContainsWithIgnoreCase creates a new contains operation with ignore case option.
func (*ContainsOperation) Apply ¶ added in v0.4.3
Apply applies the contains test operation to the document.
func (*ContainsOperation) Code ¶ added in v0.4.3
func (co *ContainsOperation) Code() int
Code returns the operation code.
func (*ContainsOperation) Op ¶ added in v0.4.3
func (co *ContainsOperation) Op() internal.OpType
Op returns the operation type.
func (*ContainsOperation) Test ¶ added in v0.4.3
func (co *ContainsOperation) Test(doc any) (bool, error)
Test performs the contains test operation.
func (*ContainsOperation) ToCompact ¶ added in v0.4.3
func (co *ContainsOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*ContainsOperation) ToJSON ¶ added in v0.4.3
func (co *ContainsOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*ContainsOperation) Validate ¶ added in v0.4.3
func (co *ContainsOperation) Validate() error
Validate validates the contains operation.
type CopyOperation ¶ added in v0.4.3
type CopyOperation struct {
BaseOp
}
CopyOperation represents a copy operation that copies a value from one path to another.
func NewCopy ¶ added in v0.4.3
func NewCopy(path, from []string) *CopyOperation
NewCopy creates a new copy operation.
func (*CopyOperation) Code ¶ added in v0.4.3
func (c *CopyOperation) Code() int
Code returns the operation code.
func (*CopyOperation) Op ¶ added in v0.4.3
func (c *CopyOperation) Op() internal.OpType
Op returns the operation type.
func (*CopyOperation) ToCompact ¶ added in v0.4.3
func (c *CopyOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*CopyOperation) ToJSON ¶ added in v0.4.3
func (c *CopyOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*CopyOperation) Validate ¶ added in v0.4.3
func (c *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 NewDefined ¶ added in v0.4.3
func NewDefined(path []string) *DefinedOperation
NewDefined creates a new defined operation.
func (*DefinedOperation) Code ¶ added in v0.4.3
func (d *DefinedOperation) Code() int
Code returns the operation code.
func (*DefinedOperation) Op ¶ added in v0.4.3
func (d *DefinedOperation) Op() internal.OpType
Op returns the operation type.
func (*DefinedOperation) Test ¶ added in v0.4.3
func (d *DefinedOperation) Test(doc any) (bool, error)
Test performs the defined operation.
func (*DefinedOperation) ToCompact ¶ added in v0.4.3
func (d *DefinedOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*DefinedOperation) ToJSON ¶ added in v0.4.3
func (d *DefinedOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*DefinedOperation) Validate ¶ added in v0.4.3
func (d *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
}
EndsOperation represents a test operation that checks if a string value ends with a specific suffix.
func NewEnds ¶ added in v0.4.3
func NewEnds(path []string, suffix string) *EndsOperation
NewEnds creates a new ends operation.
func NewEndsWithIgnoreCase ¶ added in v0.4.3
func NewEndsWithIgnoreCase(path []string, suffix string, ignoreCase bool) *EndsOperation
NewEndsWithIgnoreCase creates a new ends operation with ignore case option.
func (*EndsOperation) Apply ¶ added in v0.4.3
Apply applies the ends test operation to the document.
func (*EndsOperation) Code ¶ added in v0.4.3
func (e *EndsOperation) Code() int
Code returns the operation code.
func (*EndsOperation) Op ¶ added in v0.4.3
func (e *EndsOperation) Op() internal.OpType
Op returns the operation type.
func (*EndsOperation) Test ¶ added in v0.4.3
func (e *EndsOperation) Test(doc any) (bool, error)
Test evaluates the ends predicate condition.
func (*EndsOperation) ToCompact ¶ added in v0.4.3
func (e *EndsOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*EndsOperation) ToJSON ¶ added in v0.4.3
func (e *EndsOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*EndsOperation) Validate ¶ added in v0.4.3
func (e *EndsOperation) Validate() error
Validate validates the ends operation.
type ExtendOperation ¶ added in v0.4.3
type ExtendOperation struct {
BaseOp
Properties map[string]any `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 NewExtend ¶ added in v0.4.3
func NewExtend(path []string, properties map[string]any, deleteNull bool) *ExtendOperation
NewExtend creates a new object extend operation.
func (*ExtendOperation) Code ¶ added in v0.4.3
func (ex *ExtendOperation) Code() int
Code returns the operation code.
func (*ExtendOperation) Op ¶ added in v0.4.3
func (ex *ExtendOperation) Op() internal.OpType
Op returns the operation type.
func (*ExtendOperation) ToCompact ¶ added in v0.4.3
func (ex *ExtendOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*ExtendOperation) ToJSON ¶ added in v0.4.3
func (ex *ExtendOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*ExtendOperation) Validate ¶ added in v0.4.3
func (ex *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 NewFlip ¶ added in v0.4.3
func NewFlip(path []string) *FlipOperation
NewFlip creates a new flip operation.
func (*FlipOperation) Code ¶ added in v0.4.3
func (f *FlipOperation) Code() int
Code returns the operation code.
func (*FlipOperation) Op ¶ added in v0.4.3
func (f *FlipOperation) Op() internal.OpType
Op returns the operation type.
func (*FlipOperation) ToCompact ¶ added in v0.4.3
func (f *FlipOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*FlipOperation) ToJSON ¶ added in v0.4.3
func (f *FlipOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*FlipOperation) Validate ¶ added in v0.4.3
func (f *FlipOperation) Validate() error
Validate validates the flip operation.
type InOperation ¶ added in v0.4.3
InOperation represents a test operation that checks if a value is present in a specified array.
func NewIn ¶ added in v0.4.3
func NewIn(path []string, values []any) *InOperation
NewIn creates a new in operation.
func (*InOperation) Code ¶ added in v0.4.3
func (in *InOperation) Code() int
Code returns the operation code.
func (*InOperation) Op ¶ added in v0.4.3
func (in *InOperation) Op() internal.OpType
Op returns the operation type.
func (*InOperation) Test ¶ added in v0.4.3
func (in *InOperation) Test(doc any) (bool, error)
Test evaluates the in predicate condition.
func (*InOperation) ToCompact ¶ added in v0.4.3
func (in *InOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*InOperation) ToJSON ¶ added in v0.4.3
func (in *InOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*InOperation) Validate ¶ added in v0.4.3
func (in *InOperation) Validate() error
Validate validates the in operation.
type IncOperation ¶ added in v0.4.3
IncOperation represents an increment operation that increments a numeric value.
func NewInc ¶ added in v0.4.3
func NewInc(path []string, inc float64) *IncOperation
NewInc creates a new increment operation.
func (*IncOperation) Code ¶ added in v0.4.3
func (ic *IncOperation) Code() int
Code returns the operation code.
func (*IncOperation) Op ¶ added in v0.4.3
func (ic *IncOperation) Op() internal.OpType
Op returns the operation type.
func (*IncOperation) ToCompact ¶ added in v0.4.3
func (ic *IncOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*IncOperation) ToJSON ¶ added in v0.4.3
func (ic *IncOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*IncOperation) Validate ¶ added in v0.4.3
func (ic *IncOperation) Validate() error
Validate validates the increment operation.
type LessOperation ¶ added in v0.4.3
LessOperation represents a test operation that checks if a numeric value is less than a specified value.
func NewLess ¶ added in v0.5.10
func NewLess(path []string, value float64) *LessOperation
NewLess creates a new less operation.
func (*LessOperation) Apply ¶ added in v0.4.3
Apply applies the less test operation to the document.
func (*LessOperation) Code ¶ added in v0.4.3
func (l *LessOperation) Code() int
Code returns the operation code.
func (*LessOperation) Op ¶ added in v0.4.3
func (l *LessOperation) Op() internal.OpType
Op returns the operation type.
func (*LessOperation) Test ¶ added in v0.4.3
func (l *LessOperation) Test(doc any) (bool, error)
Test evaluates the less predicate condition.
func (*LessOperation) ToCompact ¶ added in v0.4.3
func (l *LessOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*LessOperation) ToJSON ¶ added in v0.4.3
func (l *LessOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*LessOperation) Validate ¶ added in v0.4.3
func (l *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
// contains filtered or unexported fields
}
MatchesOperation represents a "matches" predicate operation that checks if a string matches a regex pattern.
func NewMatches ¶ added in v0.4.3
func NewMatches(path []string, pattern string, ignoreCase bool, createMatcher internal.CreateRegexMatcher) *MatchesOperation
NewMatches creates a new matches operation. If createMatcher is nil, uses the default Go regexp implementation. This aligns with json-joy's OpMatches constructor pattern.
func (*MatchesOperation) Code ¶ added in v0.4.3
func (ma *MatchesOperation) Code() int
Code returns the operation code.
func (*MatchesOperation) Op ¶ added in v0.4.3
func (ma *MatchesOperation) Op() internal.OpType
Op returns the operation type.
func (*MatchesOperation) Test ¶ added in v0.4.3
func (ma *MatchesOperation) Test(doc any) (bool, error)
Test evaluates the matches predicate condition.
func (*MatchesOperation) ToCompact ¶ added in v0.4.3
func (ma *MatchesOperation) ToCompact() (internal.CompactOperation, error)
ToCompact converts the operation to compact array representation.
func (*MatchesOperation) ToJSON ¶ added in v0.4.3
func (ma *MatchesOperation) ToJSON() (internal.Operation, error)
ToJSON converts the operation to JSON representation.
func (*MatchesOperation) Validate ¶ added in v0.4.3
func (ma *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]any `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 NewMerge ¶ added in v0.4.3
func NewMerge(path []string, pos float64, props map[string]any) *MergeOperation
NewMerge creates a new merge operation.
func (*MergeOperation) Apply ¶ added in v0.4.3
Apply applies the merge operation following TypeScript reference.
func (*MergeOperation) Code ¶ added in v0.4.3
func (mg *MergeOperation) Code() int
Code returns the operation code.
func (*MergeOperation) Op ¶ added in v0.4.3
func (mg *MergeOperation) Op() internal.OpType
Op returns the operation type.
func (*MergeOperation) ToCompact ¶ added in v0.4.3
func (mg *MergeOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*MergeOperation) ToJSON ¶ added in v0.4.3
func (mg *MergeOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*MergeOperation) Validate ¶ added in v0.4.3
func (mg *MergeOperation) Validate() error
Validate validates the merge operation.
type MoreOperation ¶ added in v0.4.3
MoreOperation represents a "more" predicate operation that checks if a value is greater than a specified number.
func NewMore ¶ added in v0.4.3
func NewMore(path []string, value float64) *MoreOperation
NewMore creates a new more operation.
func (*MoreOperation) Code ¶ added in v0.4.3
func (mo *MoreOperation) Code() int
Code returns the operation code.
func (*MoreOperation) Op ¶ added in v0.4.3
func (mo *MoreOperation) Op() internal.OpType
Op returns the operation type.
func (*MoreOperation) Test ¶ added in v0.4.3
func (mo *MoreOperation) Test(doc any) (bool, error)
Test evaluates the more predicate condition.
func (*MoreOperation) ToCompact ¶ added in v0.4.3
func (mo *MoreOperation) ToCompact() (internal.CompactOperation, error)
ToCompact converts the operation to compact array representation.
func (*MoreOperation) ToJSON ¶ added in v0.4.3
func (mo *MoreOperation) ToJSON() (internal.Operation, error)
ToJSON converts the operation to JSON representation.
func (*MoreOperation) Validate ¶ added in v0.4.3
func (mo *MoreOperation) Validate() error
Validate validates the more operation.
type MoveOperation ¶ added in v0.4.3
type MoveOperation struct {
BaseOp
}
MoveOperation represents a move operation that moves a value from one path to another.
func NewMove ¶ added in v0.4.3
func NewMove(path, from []string) *MoveOperation
NewMove creates a new move operation.
func (*MoveOperation) Apply ¶ added in v0.4.3
Apply applies the move operation following RFC 6902: remove then add.
func (*MoveOperation) Code ¶ added in v0.4.3
func (m *MoveOperation) Code() int
Code returns the operation code.
func (*MoveOperation) Op ¶ added in v0.4.3
func (m *MoveOperation) Op() internal.OpType
Op returns the operation type.
func (*MoveOperation) ToCompact ¶ added in v0.4.3
func (m *MoveOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*MoveOperation) ToJSON ¶ added in v0.4.3
func (m *MoveOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*MoveOperation) Validate ¶ added in v0.4.3
func (m *MoveOperation) Validate() error
Validate validates the move operation.
type NotOperation ¶ added in v0.4.3
type NotOperation struct {
BaseOp
Operations []any `json:"apply"` // Array of operations to apply (then negate)
}
NotOperation represents a logical NOT operation that negates predicates.
func NewNot ¶ added in v0.4.3
func NewNot(operand internal.PredicateOp) *NotOperation
NewNot creates a new NOT operation.
func NewNotMultiple ¶ added in v0.4.3
func NewNotMultiple(path []string, ops []any) *NotOperation
NewNotMultiple creates a new NOT operation with multiple operands.
func (*NotOperation) Code ¶ added in v0.4.3
func (n *NotOperation) Code() int
Code returns the operation code.
func (*NotOperation) Not ¶ added in v0.4.3
func (n *NotOperation) Not() bool
Not returns true since this is a NOT operation.
func (*NotOperation) Op ¶ added in v0.4.3
func (n *NotOperation) Op() internal.OpType
Op returns the operation type.
func (*NotOperation) Ops ¶ added in v0.4.3
func (n *NotOperation) Ops() []internal.PredicateOp
Ops returns the operand operations.
func (*NotOperation) Test ¶ added in v0.4.3
func (n *NotOperation) Test(doc any) (bool, error)
Test evaluates the NOT predicate condition.
func (*NotOperation) ToCompact ¶ added in v0.4.3
func (n *NotOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*NotOperation) ToJSON ¶ added in v0.4.3
func (n *NotOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*NotOperation) Validate ¶ added in v0.4.3
func (n *NotOperation) Validate() error
Validate validates the NOT operation.
type OrOperation ¶ added in v0.4.3
OrOperation represents an OR operation that combines multiple predicate operations.
func NewOr ¶ added in v0.4.3
func NewOr(path []string, ops []any) *OrOperation
NewOr creates a new OR operation.
func (*OrOperation) Code ¶ added in v0.4.3
func (oo *OrOperation) Code() int
Code returns the operation code.
func (*OrOperation) Op ¶ added in v0.4.3
func (oo *OrOperation) Op() internal.OpType
Op returns the operation type.
func (*OrOperation) Ops ¶ added in v0.4.3
func (oo *OrOperation) Ops() []internal.PredicateOp
Ops returns the predicate operations.
func (*OrOperation) Test ¶ added in v0.4.3
func (oo *OrOperation) Test(doc any) (bool, error)
Test performs the OR operation.
func (*OrOperation) ToCompact ¶ added in v0.4.3
func (oo *OrOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*OrOperation) ToJSON ¶ added in v0.4.3
func (oo *OrOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*OrOperation) Validate ¶ added in v0.4.3
func (oo *OrOperation) Validate() error
Validate validates the OR operation.
type PredicateOp ¶
type PredicateOp = internal.PredicateOp
PredicateOp represents predicate operations used for testing conditions.
type RemoveOperation ¶ added in v0.4.3
type RemoveOperation struct {
BaseOp
OldValue any `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 NewRemove ¶ added in v0.4.3
func NewRemove(path []string) *RemoveOperation
NewRemove creates a new remove operation.
func NewRemoveWithOldValue ¶ added in v0.4.3
func NewRemoveWithOldValue(path []string, oldValue any) *RemoveOperation
NewRemoveWithOldValue creates a new remove operation with oldValue.
func (*RemoveOperation) Code ¶ added in v0.4.3
func (r *RemoveOperation) Code() int
Code returns the operation code.
func (*RemoveOperation) Op ¶ added in v0.4.3
func (r *RemoveOperation) Op() internal.OpType
Op returns the operation type.
func (*RemoveOperation) ToCompact ¶ added in v0.4.3
func (r *RemoveOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*RemoveOperation) ToJSON ¶ added in v0.4.3
func (r *RemoveOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*RemoveOperation) Validate ¶ added in v0.4.3
func (r *RemoveOperation) Validate() error
Validate validates the remove operation.
type ReplaceOperation ¶ added in v0.4.3
type ReplaceOperation struct {
BaseOp
Value any `json:"value"` // New value
OldValue any `json:"oldValue,omitempty"` // The value that was replaced (optional)
}
ReplaceOperation represents a replace operation that replaces a value at a specified path.
func NewReplace ¶ added in v0.4.3
func NewReplace(path []string, value any) *ReplaceOperation
NewReplace creates a new replace operation.
func NewReplaceWithOldValue ¶ added in v0.4.3
func NewReplaceWithOldValue(path []string, value any, oldValue any) *ReplaceOperation
NewReplaceWithOldValue creates a new replace operation with oldValue.
func (*ReplaceOperation) Apply ¶ added in v0.4.3
Apply applies the replace operation to the document.
func (*ReplaceOperation) Code ¶ added in v0.4.3
func (rp *ReplaceOperation) Code() int
Code returns the operation code.
func (*ReplaceOperation) Op ¶ added in v0.4.3
func (rp *ReplaceOperation) Op() internal.OpType
Op returns the operation type.
func (*ReplaceOperation) ToCompact ¶ added in v0.4.3
func (rp *ReplaceOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*ReplaceOperation) ToJSON ¶ added in v0.4.3
func (rp *ReplaceOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*ReplaceOperation) Validate ¶ added in v0.4.3
func (rp *ReplaceOperation) Validate() error
Validate validates the replace 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 any `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 NewSplit ¶ added in v0.4.3
func NewSplit(path []string, pos float64, props any) *SplitOperation
NewSplit creates a new split operation.
func (*SplitOperation) Apply ¶ added in v0.4.3
Apply applies the split operation following TypeScript reference.
func (*SplitOperation) Code ¶ added in v0.4.3
func (sp *SplitOperation) Code() int
Code returns the operation code.
func (*SplitOperation) Op ¶ added in v0.4.3
func (sp *SplitOperation) Op() internal.OpType
Op returns the operation type.
func (*SplitOperation) ToCompact ¶ added in v0.4.3
func (sp *SplitOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*SplitOperation) ToJSON ¶ added in v0.4.3
func (sp *SplitOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*SplitOperation) Validate ¶ added in v0.4.3
func (sp *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
}
StartsOperation represents a test operation that checks if a string value starts with a specific prefix.
func NewStarts ¶ added in v0.4.3
func NewStarts(path []string, prefix string) *StartsOperation
NewStarts creates a new starts operation.
func NewStartsWithIgnoreCase ¶ added in v0.4.3
func NewStartsWithIgnoreCase(path []string, prefix string, ignoreCase bool) *StartsOperation
NewStartsWithIgnoreCase creates a new starts operation with ignore case option.
func (*StartsOperation) Apply ¶ added in v0.4.3
Apply applies the starts test operation to the document.
func (*StartsOperation) Code ¶ added in v0.4.3
func (s *StartsOperation) Code() int
Code returns the operation code.
func (*StartsOperation) Op ¶ added in v0.4.3
func (s *StartsOperation) Op() internal.OpType
Op returns the operation type.
func (*StartsOperation) Test ¶ added in v0.4.3
func (s *StartsOperation) Test(doc any) (bool, error)
Test evaluates the starts predicate condition.
func (*StartsOperation) ToCompact ¶ added in v0.4.3
func (s *StartsOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*StartsOperation) ToJSON ¶ added in v0.4.3
func (s *StartsOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*StartsOperation) Validate ¶ added in v0.4.3
func (s *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 NewStrDel ¶ added in v0.4.3
func NewStrDel(path []string, pos, length float64) *StrDelOperation
NewStrDel creates a new string delete operation with length.
func NewStrDelWithStr ¶ added in v0.4.3
func NewStrDelWithStr(path []string, pos float64, str string) *StrDelOperation
NewStrDelWithStr creates a new string delete operation with specific string.
func (*StrDelOperation) Code ¶ added in v0.4.3
func (sd *StrDelOperation) Code() int
Code returns the operation code.
func (*StrDelOperation) Op ¶ added in v0.4.3
func (sd *StrDelOperation) Op() internal.OpType
Op returns the operation type.
func (*StrDelOperation) ToCompact ¶ added in v0.4.3
func (sd *StrDelOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*StrDelOperation) ToJSON ¶ added in v0.4.3
func (sd *StrDelOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*StrDelOperation) Validate ¶ added in v0.4.3
func (sd *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 NewStrIns ¶ added in v0.4.3
func NewStrIns(path []string, pos float64, str string) *StrInsOperation
NewStrIns creates a new string insert operation.
func (*StrInsOperation) Code ¶ added in v0.4.3
func (si *StrInsOperation) Code() int
Code returns the operation code.
func (*StrInsOperation) Op ¶ added in v0.4.3
func (si *StrInsOperation) Op() internal.OpType
Op returns the operation type.
func (*StrInsOperation) ToCompact ¶ added in v0.4.3
func (si *StrInsOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*StrInsOperation) ToJSON ¶ added in v0.4.3
func (si *StrInsOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*StrInsOperation) Validate ¶ added in v0.4.3
func (si *StrInsOperation) Validate() error
Validate validates the string insert operation.
type TestOperation ¶ added in v0.4.3
type TestOperation struct {
BaseOp
Value any `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 NewTest ¶ added in v0.4.3
func NewTest(path []string, value any) *TestOperation
NewTest creates a new test operation.
func NewTestWithNot ¶ added in v0.5.14
func NewTestWithNot(path []string, value any, not bool) *TestOperation
NewTestWithNot creates a new test operation with not flag.
func (*TestOperation) Code ¶ added in v0.4.3
func (t *TestOperation) Code() int
Code returns the operation code.
func (*TestOperation) Not ¶ added in v0.4.3
func (t *TestOperation) Not() bool
Not returns whether this operation is negated.
func (*TestOperation) Op ¶ added in v0.4.3
func (t *TestOperation) Op() internal.OpType
Op returns the operation type.
func (*TestOperation) Test ¶ added in v0.4.3
func (t *TestOperation) Test(doc any) (bool, error)
Test performs the test operation.
func (*TestOperation) ToCompact ¶ added in v0.4.3
func (t *TestOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*TestOperation) ToJSON ¶ added in v0.4.3
func (t *TestOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*TestOperation) Validate ¶ added in v0.4.3
func (t *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 NewTestStringLen ¶ added in v0.4.3
func NewTestStringLen(path []string, expectedLength float64) *TestStringLenOperation
NewTestStringLen creates a new test string length operation.
func NewTestStringLenWithNot ¶ added in v0.4.3
func NewTestStringLenWithNot(path []string, expectedLength float64, not bool) *TestStringLenOperation
NewTestStringLenWithNot creates a new test string length operation with not flag.
func (*TestStringLenOperation) Apply ¶ added in v0.4.3
Apply applies the test string length operation to the document.
func (*TestStringLenOperation) Code ¶ added in v0.4.3
func (tl *TestStringLenOperation) Code() int
Code returns the operation code.
func (*TestStringLenOperation) Not ¶ added in v0.4.3
func (tl *TestStringLenOperation) Not() bool
Not returns whether this is a negation predicate.
func (*TestStringLenOperation) Op ¶ added in v0.4.3
func (tl *TestStringLenOperation) Op() internal.OpType
Op returns the operation type.
func (*TestStringLenOperation) Test ¶ added in v0.5.1
func (tl *TestStringLenOperation) Test(doc any) (bool, error)
Test tests the string length condition on the document.
func (*TestStringLenOperation) ToCompact ¶ added in v0.4.3
func (tl *TestStringLenOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*TestStringLenOperation) ToJSON ¶ added in v0.4.3
func (tl *TestStringLenOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*TestStringLenOperation) Validate ¶ added in v0.4.3
func (tl *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 NewTestString ¶ added in v0.4.3
func NewTestString(path []string, str string, pos float64, not bool, ignoreCase bool) *TestStringOperation
NewTestString creates a new test string operation.
func (*TestStringOperation) Apply ¶ added in v0.4.3
Apply applies the test string operation to the document.
func (*TestStringOperation) Code ¶ added in v0.4.3
func (ts *TestStringOperation) Code() int
Code returns the operation code.
func (*TestStringOperation) Not ¶ added in v0.5.1
func (ts *TestStringOperation) Not() bool
Not returns whether this operation is a negation predicate.
func (*TestStringOperation) Op ¶ added in v0.4.3
func (ts *TestStringOperation) Op() internal.OpType
Op returns the operation type.
func (*TestStringOperation) Test ¶ added in v0.4.3
func (ts *TestStringOperation) Test(doc any) (bool, error)
Test evaluates the test string predicate condition.
func (*TestStringOperation) ToCompact ¶ added in v0.4.3
func (ts *TestStringOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*TestStringOperation) ToJSON ¶ added in v0.4.3
func (ts *TestStringOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*TestStringOperation) Validate ¶ added in v0.4.3
func (ts *TestStringOperation) Validate() error
Validate validates the test string operation.
type TestTypeOperation ¶ added in v0.4.3
TestTypeOperation represents a test operation that checks if a value is of a specific type.
func NewTestType ¶ added in v0.4.3
func NewTestType(path []string, expectedType string) *TestTypeOperation
NewTestType creates a new test type operation.
func NewTestTypeMultiple ¶ added in v0.4.3
func NewTestTypeMultiple(path []string, expectedTypes []string) *TestTypeOperation
NewTestTypeMultiple creates a new test type operation with multiple types.
func (*TestTypeOperation) Apply ¶ added in v0.4.3
Apply applies the test type operation to the document.
func (*TestTypeOperation) Code ¶ added in v0.4.3
func (tt *TestTypeOperation) Code() int
Code returns the operation code.
func (*TestTypeOperation) Op ¶ added in v0.4.3
func (tt *TestTypeOperation) Op() internal.OpType
Op returns the operation type.
func (*TestTypeOperation) Test ¶ added in v0.4.3
func (tt *TestTypeOperation) Test(doc any) (bool, error)
Test evaluates the test type predicate condition.
func (*TestTypeOperation) ToCompact ¶ added in v0.4.3
func (tt *TestTypeOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*TestTypeOperation) ToJSON ¶ added in v0.4.3
func (tt *TestTypeOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*TestTypeOperation) Validate ¶ added in v0.4.3
func (tt *TestTypeOperation) Validate() error
Validate validates the test type operation.
type TypeOperation ¶ added in v0.4.3
TypeOperation represents a type operation that checks if a value is of a specific type.
func NewType ¶ added in v0.4.3
func NewType(path []string, expectedType string) *TypeOperation
NewType creates a new type operation.
func (*TypeOperation) Code ¶ added in v0.4.3
func (tp *TypeOperation) Code() int
Code returns the operation code.
func (*TypeOperation) Op ¶ added in v0.4.3
func (tp *TypeOperation) Op() internal.OpType
Op returns the operation type.
func (*TypeOperation) Test ¶ added in v0.4.3
func (tp *TypeOperation) Test(doc any) (bool, error)
Test evaluates the type predicate condition.
func (*TypeOperation) ToCompact ¶ added in v0.4.3
func (tp *TypeOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*TypeOperation) ToJSON ¶ added in v0.4.3
func (tp *TypeOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*TypeOperation) Validate ¶ added in v0.4.3
func (tp *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 NewUndefined ¶ added in v0.4.3
func NewUndefined(path []string) *UndefinedOperation
NewUndefined creates a new undefined operation.
func (*UndefinedOperation) Code ¶ added in v0.4.3
func (u *UndefinedOperation) Code() int
Code returns the operation code.
func (*UndefinedOperation) Op ¶ added in v0.4.3
func (u *UndefinedOperation) Op() internal.OpType
Op returns the operation type.
func (*UndefinedOperation) Test ¶ added in v0.4.3
func (u *UndefinedOperation) Test(doc any) (bool, error)
Test performs the undefined operation.
func (*UndefinedOperation) ToCompact ¶ added in v0.4.3
func (u *UndefinedOperation) ToCompact() (internal.CompactOperation, error)
ToCompact serializes the operation to compact format.
func (*UndefinedOperation) ToJSON ¶ added in v0.4.3
func (u *UndefinedOperation) ToJSON() (internal.Operation, error)
ToJSON serializes the operation to JSON format.
func (*UndefinedOperation) Validate ¶ added in v0.4.3
func (u *UndefinedOperation) Validate() error
Validate validates the undefined operation.