internal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2025 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// JSON Patch (RFC 6902) operations
	OpAddCode     = 0
	OpRemoveCode  = 1
	OpReplaceCode = 2
	OpCopyCode    = 3
	OpMoveCode    = 4
	OpTestCode    = 5

	// String editing
	OpStrInsCode = 6
	OpStrDelCode = 7

	// Extra
	OpFlipCode = 8
	OpIncCode  = 9

	// Slate.js
	OpSplitCode  = 10
	OpMergeCode  = 11
	OpExtendCode = 12

	// JSON Predicate
	OpContainsCode      = 30
	OpDefinedCode       = 31
	OpEndsCode          = 32
	OpInCode            = 33
	OpLessCode          = 34
	OpMatchesCode       = 35
	OpMoreCode          = 36
	OpStartsCode        = 37
	OpUndefinedCode     = 38
	OpTestTypeCode      = 39
	OpTestStringCode    = 40
	OpTestStringLenCode = 41
	OpTypeCode          = 42
	OpAndCode           = 43
	OpNotCode           = 44
	OpOrCode            = 45
)

Operation code constants, numeric codes

Variables

This section is empty.

Functions

func IsFirstOrderPredicateOperation

func IsFirstOrderPredicateOperation(op string) bool

IsFirstOrderPredicateOperation checks if operation is a first-order predicate

func IsJsonPatchExtendedOperation

func IsJsonPatchExtendedOperation(op string) bool

IsJsonPatchExtendedOperation checks if operation is an extended operation.

func IsJsonPatchOperation

func IsJsonPatchOperation(op string) bool

IsJsonPatchOperation checks if operation is a core JSON Patch operation

func IsPredicateOperation

func IsPredicateOperation(op string) bool

IsPredicateOperation checks if operation is a predicate operation

func IsSecondOrderPredicateOperation

func IsSecondOrderPredicateOperation(op string) bool

IsSecondOrderPredicateOperation checks if operation is a second-order predicate.

func IsValidJsonPatchType

func IsValidJsonPatchType(typeStr string) bool

IsValidJsonPatchType checks if a type string is a valid JSON Patch type

Types

type ApplyPatchOptions

type ApplyPatchOptions struct {
	Mutate           bool
	JsonPatchOptions JsonPatchOptions
}

ApplyPatchOptions contains options for applying patches.

type Codec

type Codec interface {
	// Decode decodes a JSON operation object into an Op instance
	Decode(operation Operation) (Op, error)
	// DecodeSlice decodes an array of operations into an Op slice
	DecodeSlice(operations []Operation) ([]Op, error)
	// Encode encodes an Op instance into a JSON operation object
	Encode(op Op) (Operation, error)
	// EncodeSlice encodes an Op slice into an array of operations
	EncodeSlice(ops []Op) ([]Operation, error)
}

Codec is the interface for codecs that provide unified encoding and decoding functionality.

type CompactOperation

type CompactOperation = []interface{}

CompactOperation represents a compact format operation actually []interface{}, but with clearer semantics

type CreateRegexMatcher

type CreateRegexMatcher func(pattern string, ignoreCase bool) RegexMatcher

CreateRegexMatcher is a function type that creates a regular expression matcher.

type JsonPatchOptions

type JsonPatchOptions struct {
	CreateMatcher CreateRegexMatcher
}

JsonPatchOptions contains options for JSON Patch operations.

type JsonPatchTypes

type JsonPatchTypes string

JsonPatchTypes represents the valid JSON types for type operations.

const (
	JsonPatchTypeString  JsonPatchTypes = "string"
	JsonPatchTypeNumber  JsonPatchTypes = "number"
	JsonPatchTypeBoolean JsonPatchTypes = "boolean"
	JsonPatchTypeObject  JsonPatchTypes = "object"
	JsonPatchTypeInteger JsonPatchTypes = "integer"
	JsonPatchTypeArray   JsonPatchTypes = "array"
	JsonPatchTypeNull    JsonPatchTypes = "null"
)

func GetJsonPatchType

func GetJsonPatchType(value interface{}) JsonPatchTypes

GetJsonPatchType returns the JSON Patch type for a given value

type Op

type Op interface {
	// Op returns the operation type string (e.g. "add", "remove", etc.)
	Op() OpType
	// Code returns the numeric code for the operation (consistent with constants)
	Code() int
	// Path returns the JSON Pointer path for the operation (slice form)
	Path() []string
	// Apply applies the operation to the document, returning the new document and old value
	Apply(doc any) (OpResult, error)
	// ToJSON returns the standard JSON Patch format
	ToJSON() (Operation, error)
	// ToCompact returns the compact array format
	ToCompact() (CompactOperation, error)
	// Validate validates the operation parameters
	Validate() error
}

Op is the unified interface for all JSON Patch operations. Any operation must implement these methods.

type OpResult

type OpResult struct {
	Doc interface{} `json:"doc"`
	Old interface{} `json:"old,omitempty"`
}

OpResult represents the result of a single operation

type OpType

type OpType string
const (
	// JSON Patch (RFC 6902) operations
	OpAddType     OpType = "add"
	OpRemoveType  OpType = "remove"
	OpReplaceType OpType = "replace"
	OpMoveType    OpType = "move"
	OpCopyType    OpType = "copy"
	OpTestType    OpType = "test"

	// JSON Predicate operations
	OpContainsType      OpType = "contains"
	OpDefinedType       OpType = "defined"
	OpUndefinedType     OpType = "undefined"
	OpTypeType          OpType = "type"
	OpTestTypeType      OpType = "test_type"
	OpTestStringType    OpType = "test_string"
	OpTestStringLenType OpType = "test_string_len"
	OpEndsType          OpType = "ends"
	OpStartsType        OpType = "starts"
	OpInType            OpType = "in"
	OpLessType          OpType = "less"
	OpMoreType          OpType = "more"
	OpMatchesType       OpType = "matches"

	// Composite operations
	OpAndType OpType = "and"
	OpOrType  OpType = "or"
	OpNotType OpType = "not"

	// Extended operations
	OpFlipType   OpType = "flip"
	OpIncType    OpType = "inc"
	OpStrInsType OpType = "str_ins"
	OpStrDelType OpType = "str_del"
	OpSplitType  OpType = "split"
	OpMergeType  OpType = "merge"
	OpExtendType OpType = "extend"
)

type Operation

type Operation = map[string]interface{}

Operation represents a JSON Patch operation object compatible with map format

type PatchResult

type PatchResult struct {
	Doc interface{} `json:"doc"`
	Res []OpResult  `json:"res"`
}

PatchResult represents the result of a patch operation

type PredicateOp

type PredicateOp interface {
	Op
	// Test tests the operation on the document, returning whether it passed
	Test(doc any) (bool, error)
	// Not returns whether the operation is a negation predicate
	Not() bool
}

PredicateOp is the interface for all predicate (test-type) operations.

type RegexMatcher

type RegexMatcher func(value string) bool

RegexMatcher is a function type that tests if a value matches a pattern.

type SecondOrderPredicateOp

type SecondOrderPredicateOp interface {
	PredicateOp
	// Ops returns all sub-predicate operations
	Ops() []PredicateOp
}

SecondOrderPredicateOp is the interface for second-order predicate operations that combine multiple predicates.

Jump to

Keyboard shortcuts

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