mapper

package
v0.0.0-...-ae5b880 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 24 Imported by: ? 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

Overview

Package mapper compiles a stream's mapper list against its JSON schema and runs the compiled chain on one record at a time.

Index

Constants

View Source
const (
	OnErrorFail = "fail"
	OnErrorNull = "null"
	OnErrorSkip = "skip"
)

OnError values.

View Source
const (
	CastString    = "string"
	CastInteger   = "integer"
	CastNumber    = "number"
	CastBoolean   = "boolean"
	CastTimestamp = "timestamp"
	CastDatetime  = "datetime"
	CastDate      = "date"
	CastObject    = "object"
	CastArray     = "array"
)

Cast targets.

View Source
const (
	FormatISO8601 = "iso8601"
	FormatUnix    = "unix"
	FormatUnixMs  = "unix_ms"
)

Timestamp formats besides token patterns.

View Source
const DefaultCostLimit uint64 = 100000

DefaultCostLimit is the CEL cost limit per expression evaluation when Input.CostLimit is zero.

View Source
const SelectionStep = -1

SelectionStep is the Issue.Step of a problem with the field selection.

Variables

This section is empty.

Functions

func Compile

func Compile(input Input) (*Chain, *Result)

Compile checks the steps against the schema and returns the runnable chain with the output schema and primary key, or a nil chain and the errors.

func DecodeRecord

func DecodeRecord(data []byte) (map[string]any, error)

DecodeRecord decodes a record's JSON data, keeping numbers as json.Number so Run reads them as the schema says.

Types

type CastSpec

type CastSpec struct {
	To                 string   `json:"to"`
	Format             string   `json:"format,omitempty"`
	Timezone           string   `json:"timezone,omitempty"`
	DecimalSeparator   string   `json:"decimal_separator,omitempty"`
	ThousandsSeparator string   `json:"thousands_separator,omitempty"`
	Trim               bool     `json:"trim,omitempty"`
	StripPrefix        string   `json:"strip_prefix,omitempty"`
	StripSuffix        string   `json:"strip_suffix,omitempty"`
	TrueValues         []string `json:"true_values,omitempty"`
	FalseValues        []string `json:"false_values,omitempty"`
	Source             string   `json:"source,omitempty"`
	OnError            string   `json:"on_error,omitempty"`
}

CastSpec converts one field to a target type.

func (*CastSpec) UnmarshalJSON

func (c *CastSpec) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts either a full spec object or a bare target string.

type Chain

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

Chain is a compiled mapper list, safe for concurrent use.

func (*Chain) Run

func (c *Chain) Run(rec map[string]any, sync SyncInfo) (out map[string]any, keep bool, err error)

Run applies the chain to one record and projects it to the field selection. keep is false when a filter or an on_error skip drops the record; err is a *StepError when a step with on_error fail fails. The input map is not modified.

type Input

type Input struct {
	Schema              json.RawMessage
	Steps               []Step
	SelectedFields      []protocol.SelectedField
	PrimaryKey          [][]string
	CursorField         []string
	SyncMode            protocol.SyncMode
	DestinationSyncMode protocol.DestinationSyncMode
	Salt                []byte
	CostLimit           uint64
}

Input is everything Compile needs about one stream.

type Issue

type Issue struct {
	Step    int    `json:"step"`
	Field   string `json:"field,omitempty"`
	Message string `json:"message"`
}

Issue is a problem found in one step, or in the field selection when Step is SelectionStep.

type MaskSpec

type MaskSpec struct {
	KeepFirst int `json:"keep_first,omitempty"`
	KeepLast  int `json:"keep_last,omitempty"`
}

MaskSpec keeps the first and last characters of a value and stars the rest.

type Result

type Result struct {
	Schema      json.RawMessage
	PrimaryKey  [][]string
	CursorField []string
	Errors      []Issue
	Warnings    []Issue
}

Result is the output of Compile: the output schema, primary key and cursor field, or the issues found. CursorField is nil when a step dropped the cursor.

type Step

type Step struct {
	Rename  map[string]string   `json:"rename,omitempty"`
	Cast    map[string]CastSpec `json:"cast,omitempty"`
	Set     map[string]string   `json:"set,omitempty"`
	Hash    []string            `json:"hash,omitempty"`
	Mask    map[string]MaskSpec `json:"mask,omitempty"`
	Filter  *string             `json:"filter,omitempty"`
	Drop    []string            `json:"drop,omitempty"`
	OnError string              `json:"on_error,omitempty"`
}

Step is one mapper of a stream's chain. Exactly one mapper field is set.

type StepError

type StepError struct {
	Step  int
	Field string
	Err   error
}

StepError is a runtime failure of a step whose on_error is fail.

func (*StepError) Error

func (e *StepError) Error() string

func (*StepError) Unwrap

func (e *StepError) Unwrap() error

type SyncInfo

type SyncInfo struct {
	StartedAt  time.Time
	JobID      string
	Connection string
}

SyncInfo is the job metadata expressions see as `sync`.

Jump to

Keyboard shortcuts

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