Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ type WriteParams struct {
Associations any // optional
}

func (p WriteParams) GetRecord() (Record, error) {
return RecordDataToMap(p.RecordData)
Comment thread
Cobalt0s marked this conversation as resolved.
}

// RecordDataToMap converts WriteParams.RecordData into a map[string]any.
//
// When possible use WriteParams.GetRecord instead.
//
// If RecordData is already a map, it is returned directly.
// Otherwise, it is serialized to JSON and then deserialized back into a map.
func RecordDataToMap(recordData any) (map[string]any, error) {
Expand Down Expand Up @@ -318,6 +325,22 @@ type BatchWriteParam struct {
Records []any
}

func (p BatchWriteParam) IsCreate() bool {
return p.Type == BatchWriteTypeCreate
}

func (p BatchWriteParam) IsUpdate() bool {
return p.Type == BatchWriteTypeUpdate
}

type Record map[string]any
Comment thread
Cobalt0s marked this conversation as resolved.

func (p BatchWriteParam) GetRecords() ([]Record, error) {
return datautils.ForEachWithErr(p.Records, func(record any) (Record, error) {
return RecordDataToMap(record)
})
}

// BatchWriteResult aggregates the outcome of a synchronous batch write operation.
// It reports an overall batch status, any top-level errors, and the per-record
// results for each record processed in the batch.
Expand Down Expand Up @@ -586,6 +609,10 @@ type ObjectEvents struct {

type ObjectName string

func (n ObjectName) String() string {
return string(n)
}

type SubscribeParams struct {
Request any
// RegistrationResult is the result of the Connector.Register call.
Expand Down
7 changes: 6 additions & 1 deletion common/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ func (p DeleteParams) ValidateParams() error {
return nil
}

var ErrUnknownBatchWriteType = errors.New("unknown batch write type")
var (
// ErrUnknownBatchWriteType is returned when enum option for the write type is invalid.
ErrUnknownBatchWriteType = errors.New("unknown batch write type")
// ErrUnsupportedBatchWriteType is returned when connector doesn't implement batch write type.
ErrUnsupportedBatchWriteType = errors.New("batch write type is not supported")
)

func (p BatchWriteParam) ValidateParams() error {
if len(p.ObjectName) == 0 {
Expand Down