From a23328f45910a3dd4365f908a7ce5b73eb7bcd69 Mon Sep 17 00:00:00 2001 From: Brooks Townsend Date: Fri, 9 Aug 2024 11:22:33 -0400 Subject: [PATCH] feat: update provider to use couchbase bindings Signed-off-by: Brooks Townsend --- .../couchbase/document/bindings.wrpc.go | 8377 +++++++++++++++++ bindings/interfaces.wrpc.go | 32 + .../couchbase/types/bindings.wrpc.go | 1500 +++ go.mod | 2 +- main.go | 2 +- provider.go | 157 +- tracing.go | 5 +- wit/deps.lock | 5 - wit/deps/keyvalue/atomic.wit | 22 - wit/deps/keyvalue/batch.wit | 63 - wit/deps/keyvalue/store.wit | 114 - wit/deps/keyvalue/watch.wit | 15 - wit/deps/keyvalue/world.wit | 26 - wit/keyvalue/atomic.wit | 22 - wit/keyvalue/batch.wit | 63 - wit/keyvalue/store.wit | 114 - wit/keyvalue/watch.wit | 15 - wit/keyvalue/world.wit | 26 - 18 files changed, 9956 insertions(+), 604 deletions(-) create mode 100644 bindings/exports/wasmcloud/couchbase/document/bindings.wrpc.go create mode 100644 bindings/interfaces.wrpc.go create mode 100644 bindings/wasmcloud/couchbase/types/bindings.wrpc.go delete mode 100644 wit/deps/keyvalue/atomic.wit delete mode 100644 wit/deps/keyvalue/batch.wit delete mode 100644 wit/deps/keyvalue/store.wit delete mode 100644 wit/deps/keyvalue/watch.wit delete mode 100644 wit/deps/keyvalue/world.wit delete mode 100644 wit/keyvalue/atomic.wit delete mode 100644 wit/keyvalue/batch.wit delete mode 100644 wit/keyvalue/store.wit delete mode 100644 wit/keyvalue/watch.wit delete mode 100644 wit/keyvalue/world.wit diff --git a/bindings/exports/wasmcloud/couchbase/document/bindings.wrpc.go b/bindings/exports/wasmcloud/couchbase/document/bindings.wrpc.go new file mode 100644 index 0000000..5f56f29 --- /dev/null +++ b/bindings/exports/wasmcloud/couchbase/document/bindings.wrpc.go @@ -0,0 +1,8377 @@ +// Generated by `wit-bindgen-wrpc-go` 0.1.1. DO NOT EDIT! +package document + +import ( + bytes "bytes" + context "context" + binary "encoding/binary" + errors "errors" + fmt "fmt" + wasmcloud__couchbase__types "github.com/couchbase-examples/wasmcloud-provider-couchbase/bindings/wasmcloud/couchbase/types" + wrpc "github.com/wrpc/wrpc/go" + io "io" + slog "log/slog" + math "math" + sync "sync" + atomic "sync/atomic" + utf8 "unicode/utf8" +) + +type Document = wasmcloud__couchbase__types.Document +type DocumentId = wasmcloud__couchbase__types.DocumentId +type DocumentError = wasmcloud__couchbase__types.DocumentError +type MutationMetadata = wasmcloud__couchbase__types.MutationMetadata +type Time = wasmcloud__couchbase__types.Time +type DurabilityLevel = wasmcloud__couchbase__types.DurabilityLevel +type RetryStrategy = wasmcloud__couchbase__types.RetryStrategy +type RequestSpan = wasmcloud__couchbase__types.RequestSpan +type ReplicaReadLevel = wasmcloud__couchbase__types.ReplicaReadLevel + +// Document - Insert /// +// +// Options for performing a document insert +type DocumentInsertOptions struct { + // When the document should expire (nanoseconds) + ExpiresInNs uint64 + // (Deprecated) + // Traditional durability settings for persistence, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + PersistTo uint64 + // (Deprecated) + // Traditional durability settings for replication, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + ReplicateTo uint64 + // Durability level for the mutation + // + // (this should be used instead of persist-to/replicate-to) + DurabilityLevel wasmcloud__couchbase__types.DurabilityLevel + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentInsertOptions) String() string { return "DocumentInsertOptions" } + +func (v *DocumentInsertOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 7) + slog.Debug("writing field", "name", "expires-in-ns") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ExpiresInNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in-ns` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "persist-to") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.PersistTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `persist-to` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "replicate-to") + write2, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ReplicateTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `replicate-to` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "durability-level") + write3, err := (v.DurabilityLevel).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `durability-level` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "timeout-ns") + write4, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + slog.Debug("writing field", "name", "retry-strategy") + write5, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write5 != nil { + writes[5] = write5 + } + slog.Debug("writing field", "name", "parent-span") + write6, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write6 != nil { + writes[6] = write6 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Replace /// +// +// Options for performing a document replace +type DocumentReplaceOptions struct { + // CAS revision of the document + Cas uint64 + // When the document should expire (nanoseconds) + ExpiresInNs uint64 + // Whether to preserve expiration values set on any documents modified by the query + PreserveExpiry bool + // (Deprecated) + // Traditional durability settings for persistence, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + PersistTo uint64 + // (Deprecated) + // Traditional durability settings for replication, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + ReplicateTo uint64 + // Durability level for the mutation + // + // (this should be used instead of persist-to/replicate-to) + DurabilityLevel wasmcloud__couchbase__types.DurabilityLevel + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentReplaceOptions) String() string { return "DocumentReplaceOptions" } + +func (v *DocumentReplaceOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 9) + slog.Debug("writing field", "name", "cas") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Cas, w) + if err != nil { + return nil, fmt.Errorf("failed to write `cas` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "expires-in-ns") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ExpiresInNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in-ns` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "preserve-expiry") + write2, err := (func(wrpc.IndexWriter) error)(nil), func(v bool, w io.ByteWriter) error { + if !v { + slog.Debug("writing `false` byte") + return w.WriteByte(0) + } + slog.Debug("writing `true` byte") + return w.WriteByte(1) + }(v.PreserveExpiry, w) + if err != nil { + return nil, fmt.Errorf("failed to write `preserve-expiry` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "persist-to") + write3, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.PersistTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `persist-to` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "replicate-to") + write4, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ReplicateTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `replicate-to` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + slog.Debug("writing field", "name", "durability-level") + write5, err := (v.DurabilityLevel).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `durability-level` field: %w", err) + } + if write5 != nil { + writes[5] = write5 + } + slog.Debug("writing field", "name", "timeout-ns") + write6, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write6 != nil { + writes[6] = write6 + } + slog.Debug("writing field", "name", "retry-strategy") + write7, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write7 != nil { + writes[7] = write7 + } + slog.Debug("writing field", "name", "parent-span") + write8, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write8 != nil { + writes[8] = write8 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Upsert /// +// +// Options for performing a document upsert +type DocumentUpsertOptions struct { + // When the document should expire (nanoseconds) + ExpiresInNs uint64 + // Whether to preserve expiration values set on any documents modified by the query + PreserveExpiry bool + // (Deprecated) + // Traditional durability settings for persistence, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + PersistTo uint64 + // (Deprecated) + // Traditional durability settings for replication, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + ReplicateTo uint64 + // Durability level for the mutation + // + // (this should be used instead of persist-to/replicate-to) + DurabilityLevel wasmcloud__couchbase__types.DurabilityLevel + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentUpsertOptions) String() string { return "DocumentUpsertOptions" } + +func (v *DocumentUpsertOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 8) + slog.Debug("writing field", "name", "expires-in-ns") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ExpiresInNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in-ns` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "preserve-expiry") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v bool, w io.ByteWriter) error { + if !v { + slog.Debug("writing `false` byte") + return w.WriteByte(0) + } + slog.Debug("writing `true` byte") + return w.WriteByte(1) + }(v.PreserveExpiry, w) + if err != nil { + return nil, fmt.Errorf("failed to write `preserve-expiry` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "persist-to") + write2, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.PersistTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `persist-to` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "replicate-to") + write3, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ReplicateTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `replicate-to` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "durability-level") + write4, err := (v.DurabilityLevel).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `durability-level` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + slog.Debug("writing field", "name", "timeout-ns") + write5, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write5 != nil { + writes[5] = write5 + } + slog.Debug("writing field", "name", "retry-strategy") + write6, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write6 != nil { + writes[6] = write6 + } + slog.Debug("writing field", "name", "parent-span") + write7, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write7 != nil { + writes[7] = write7 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Get /// +// +// Options for performing a document get +type DocumentGetOptions struct { + // Whether expiry should also be retreived + WithExpiry bool + // Perform a projection of only specific paths of the result, returning only + // the fields indicated by the given list of paths. + Project []string + // Timeout that should be used, in nanoseconds + // If not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // Level of replica read to enable + UseReplica *ReplicaReadLevel + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentGetOptions) String() string { return "DocumentGetOptions" } + +func (v *DocumentGetOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 6) + slog.Debug("writing field", "name", "with-expiry") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v bool, w io.ByteWriter) error { + if !v { + slog.Debug("writing `false` byte") + return w.WriteByte(0) + } + slog.Debug("writing `true` byte") + return w.WriteByte(1) + }(v.WithExpiry, w) + if err != nil { + return nil, fmt.Errorf("failed to write `with-expiry` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "project") + write1, err := func(v []string, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := func(v []string, w interface { + io.ByteWriter + io.Writer + }) (write func(wrpc.IndexWriter) error, err error) { + n := len(v) + if n > math.MaxUint32 { + return nil, fmt.Errorf("list length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing list length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return nil, fmt.Errorf("failed to write list length of %d: %w", n, err) + } + slog.Debug("writing list elements") + writes := make(map[uint32]func(wrpc.IndexWriter) error, n) + for i, e := range v { + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(e, w) + if err != nil { + return nil, fmt.Errorf("failed to write list element %d: %w", i, err) + } + if write != nil { + writes[uint32(i)] = write + } + } + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil + }(v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.Project, w) + if err != nil { + return nil, fmt.Errorf("failed to write `project` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "timeout-ns") + write2, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "retry-strategy") + write3, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "use-replica") + write4, err := func(v *ReplicaReadLevel, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (*v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.UseReplica, w) + if err != nil { + return nil, fmt.Errorf("failed to write `use-replica` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + slog.Debug("writing field", "name", "parent-span") + write5, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write5 != nil { + writes[5] = write5 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Options for retrieving a document from any replica +type DocumentGetAnyReplicaOptions struct { + // Timeout that should be used, in nanoseconds + // If not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentGetAnyReplicaOptions) String() string { return "DocumentGetAnyReplicaOptions" } + +func (v *DocumentGetAnyReplicaOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 3) + slog.Debug("writing field", "name", "timeout-ns") + write0, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "retry-strategy") + write1, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "parent-span") + write2, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Options for retrieving a document from any replica +type DocumentGetAllReplicaOptions struct { + // Timeout that should be used, in nanoseconds + // If not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentGetAllReplicaOptions) String() string { return "DocumentGetAllReplicaOptions" } + +func (v *DocumentGetAllReplicaOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 3) + slog.Debug("writing field", "name", "timeout-ns") + write0, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "retry-strategy") + write1, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "parent-span") + write2, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Result of a successfully executed document get +type DocumentGetResult struct { + // Document that was retrieved + Document *wasmcloud__couchbase__types.Document + // CAS revision of the document + Cas uint64 + // When the document should expire (nanoseconds) + // + // Deprecated: use expires-at instead + ExpiresInNs *uint64 + // Time when the document expires + // + // This field may not be present if `document-get-options.with-expiry` is not set + ExpiresAt *Time +} + +func (v *DocumentGetResult) String() string { return "DocumentGetResult" } + +func (v *DocumentGetResult) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) + slog.Debug("writing field", "name", "document") + write0, err := (v.Document).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `document` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "cas") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Cas, w) + if err != nil { + return nil, fmt.Errorf("failed to write `cas` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "expires-in-ns") + write2, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ExpiresInNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in-ns` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "expires-at") + write3, err := func(v *Time, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ExpiresAt, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-at` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Result from a replica-aware document get +type DocumentGetReplicaResult struct { + // Whether this document came from a replica server + IsReplica bool + // CAS revision of the document + Cas uint64 + // Document that was retrieved + Document *wasmcloud__couchbase__types.Document + // When the document should expire (nanoseconds) + // + // Deprecated: use expires-at instead + ExpiresInNs *uint64 + // Time when the document expires + // + // This field may not be present if `document-get-options.with-expiry` is not set + ExpiresAt *Time +} + +func (v *DocumentGetReplicaResult) String() string { return "DocumentGetReplicaResult" } + +func (v *DocumentGetReplicaResult) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 5) + slog.Debug("writing field", "name", "is-replica") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v bool, w io.ByteWriter) error { + if !v { + slog.Debug("writing `false` byte") + return w.WriteByte(0) + } + slog.Debug("writing `true` byte") + return w.WriteByte(1) + }(v.IsReplica, w) + if err != nil { + return nil, fmt.Errorf("failed to write `is-replica` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "cas") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Cas, w) + if err != nil { + return nil, fmt.Errorf("failed to write `cas` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "document") + write2, err := (v.Document).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `document` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "expires-in-ns") + write3, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ExpiresInNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in-ns` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "expires-at") + write4, err := func(v *Time, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ExpiresAt, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-at` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Remove /// +// +// Options for performing a document remove +type DocumentRemoveOptions struct { + // CAS revision of the document + Cas uint64 + // (Deprecated) + // Traditional durability settings for persistence, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + PersistTo uint64 + // (Deprecated) + // Traditional durability settings for replication, only usable from Couchbase versions earlier than 6.0 + // + // See: https://docs.couchbase.com/go-sdk/current/howtos/subdocument-operations.html#1.6@go-sdk::durability.adoc + ReplicateTo uint64 + // Durability level for the mutation + // + // (this should be used instead of persist-to/replicate-to) + DurabilityLevel wasmcloud__couchbase__types.DurabilityLevel + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentRemoveOptions) String() string { return "DocumentRemoveOptions" } + +func (v *DocumentRemoveOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 7) + slog.Debug("writing field", "name", "cas") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Cas, w) + if err != nil { + return nil, fmt.Errorf("failed to write `cas` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "persist-to") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.PersistTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `persist-to` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "replicate-to") + write2, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ReplicateTo, w) + if err != nil { + return nil, fmt.Errorf("failed to write `replicate-to` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "durability-level") + write3, err := (v.DurabilityLevel).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `durability-level` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "timeout-ns") + write4, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + slog.Debug("writing field", "name", "retry-strategy") + write5, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write5 != nil { + writes[5] = write5 + } + slog.Debug("writing field", "name", "parent-span") + write6, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write6 != nil { + writes[6] = write6 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Get and Lock /// +// +// Options for performing a document lock +type DocumentGetAndLockOptions struct { + // Amount of time to lock the document (nanoseconds) + LockTime uint64 + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentGetAndLockOptions) String() string { return "DocumentGetAndLockOptions" } + +func (v *DocumentGetAndLockOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) + slog.Debug("writing field", "name", "lock-time") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.LockTime, w) + if err != nil { + return nil, fmt.Errorf("failed to write `lock-time` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "timeout-ns") + write1, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "retry-strategy") + write2, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "parent-span") + write3, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Unlock /// +// +// Options for performing a document lock +type DocumentUnlockOptions struct { + // CAS revision of the document + Cas uint64 + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentUnlockOptions) String() string { return "DocumentUnlockOptions" } + +func (v *DocumentUnlockOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) + slog.Debug("writing field", "name", "cas") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Cas, w) + if err != nil { + return nil, fmt.Errorf("failed to write `cas` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "timeout-ns") + write1, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "retry-strategy") + write2, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "parent-span") + write3, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Touch /// +// +// Options for performing a document lock +type DocumentTouchOptions struct { + // Time until the document expires (nanoseconds) + ExpiresIn uint64 + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentTouchOptions) String() string { return "DocumentTouchOptions" } + +func (v *DocumentTouchOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) + slog.Debug("writing field", "name", "expires-in") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ExpiresIn, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "timeout-ns") + write1, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "retry-strategy") + write2, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "parent-span") + write3, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Document - Get and Touch /// +// +// Options for performing a document touch +type DocumentGetAndTouchOptions struct { + // Time until the document expires (nanoseconds) + ExpiresIn uint64 + // Timeout that should be used, in nanoseconds + // Even if a timeout is not specified, the implementer *may* provide a default timeout. + TimeoutNs *uint64 + // How and whether to retry the operation + RetryStrategy *RetryStrategy + // A known span to associate this lookup with + ParentSpan *RequestSpan +} + +func (v *DocumentGetAndTouchOptions) String() string { return "DocumentGetAndTouchOptions" } + +func (v *DocumentGetAndTouchOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) + slog.Debug("writing field", "name", "expires-in") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.ExpiresIn, w) + if err != nil { + return nil, fmt.Errorf("failed to write `expires-in` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "timeout-ns") + write1, err := func(v *uint64, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.TimeoutNs, w) + if err != nil { + return nil, fmt.Errorf("failed to write `timeout-ns` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "retry-strategy") + write2, err := func(v *RetryStrategy, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (v).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.RetryStrategy, w) + if err != nil { + return nil, fmt.Errorf("failed to write `retry-strategy` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "parent-span") + write3, err := func(v *RequestSpan, w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + if v == nil { + slog.Debug("writing `option::none` status byte") + if err := w.WriteByte(0); err != nil { + return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) + } + return nil, nil + } + slog.Debug("writing `option::some` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) + } + slog.Debug("writing `option::some` payload") + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(*v, w) + if err != nil { + return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) + } + return write, nil + }(v.ParentSpan, w) + if err != nil { + return nil, fmt.Errorf("failed to write `parent-span` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +type Handler interface { + // Insert a document with a new ID + Insert(ctx__ context.Context, id string, doc *wasmcloud__couchbase__types.Document, options *DocumentInsertOptions) (*wrpc.Result[MutationMetadata, DocumentError], error) + // Replace a document with the given ID with a new document + Replace(ctx__ context.Context, id string, doc *wasmcloud__couchbase__types.Document, options *DocumentReplaceOptions) (*wrpc.Result[MutationMetadata, DocumentError], error) + // Create or update (replace) an existing document with the given ID + Upsert(ctx__ context.Context, id string, doc *wasmcloud__couchbase__types.Document, options *DocumentUpsertOptions) (*wrpc.Result[MutationMetadata, DocumentError], error) + // Retrieve a document by ID + Get(ctx__ context.Context, id string, options *DocumentGetOptions) (*wrpc.Result[DocumentGetResult, DocumentError], error) + // Retrieve a document by ID from any replica + GetAnyRepliacs(ctx__ context.Context, id string, options *DocumentGetAnyReplicaOptions) (*wrpc.Result[DocumentGetReplicaResult, DocumentError], error) + // Retrieve a document by ID from all replicas + GetAllReplicas(ctx__ context.Context, id string, options *DocumentGetAllReplicaOptions) (*wrpc.Result[[]*DocumentGetReplicaResult, DocumentError], error) + // Remove a document by ID + Remove(ctx__ context.Context, id string, options *DocumentRemoveOptions) (*wrpc.Result[MutationMetadata, DocumentError], error) + // Retrieve and Lock a document by ID + GetAndLock(ctx__ context.Context, id string, options *DocumentGetAndLockOptions) (*wrpc.Result[DocumentGetResult, DocumentError], error) + // Retrieve and Lock a document by ID + Unlock(ctx__ context.Context, id string, options *DocumentUnlockOptions) (*wrpc.Result[struct{}, DocumentError], error) + // Retrieve and Lock a document by ID + Touch(ctx__ context.Context, id string, options *DocumentTouchOptions) (*wrpc.Result[MutationMetadata, DocumentError], error) + // Retrieve and Touch a document by ID + GetAndTouch(ctx__ context.Context, id string, options *DocumentGetAndTouchOptions) (*wrpc.Result[DocumentGetResult, DocumentError], error) +} + +func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { + stops := make([]func() error, 0, 11) + stop = func() error { + for _, stop := range stops { + if err := stop(); err != nil { + return err + } + } + return nil + } + stop0, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "insert", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + } + if b < 0x80 { + if i == 4 && b > 1 { + return "", errors.New("owned resource ID length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.insert`: %w", err) + } + stops = append(stops, stop0) + stop1, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "replace", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + } + if b < 0x80 { + if i == 4 && b > 1 { + return "", errors.New("owned resource ID length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.replace`: %w", err) + } + stops = append(stops, stop1) + stop2, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "upsert", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + } + if b < 0x80 { + if i == 4 && b > 1 { + return "", errors.New("owned resource ID length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.upsert`: %w", err) + } + stops = append(stops, stop2) + stop3, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "get", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return nil, fmt.Errorf("failed to read list length byte: %w", err) + } + if b < 0x80 { + if i == 4 && b > 1 { + return nil, errors.New("list length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.get`: %w", err) + } + stops = append(stops, stop3) + stop4, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "get-any-repliacs", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.get-any-repliacs`: %w", err) + } + stops = append(stops, stop4) + stop5, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "get-all-replicas", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< math.MaxUint32 { + return nil, fmt.Errorf("list length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing list length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return nil, fmt.Errorf("failed to write list length of %d: %w", n, err) + } + slog.Debug("writing list elements") + writes := make(map[uint32]func(wrpc.IndexWriter) error, n) + for i, e := range v { + write, err := (e).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write list element %d: %w", i, err) + } + if write != nil { + writes[uint32(i)] = write + } + } + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil + }(*v.Ok, w) + if err != nil { + return nil, fmt.Errorf("failed to write `result::ok` payload: %w", err) + } + if write != nil { + return write, nil + } + return nil, nil + default: + slog.Debug("writing `result::err` status byte") + if err := w.WriteByte(1); err != nil { + return nil, fmt.Errorf("failed to write `result::err` status byte: %w", err) + } + slog.Debug("writing `result::err` payload") + write, err := (v.Err).WriteToIndex(w) + if err != nil { + return nil, fmt.Errorf("failed to write `result::err` payload: %w", err) + } + if write != nil { + return write, nil + } + return nil, nil + } + }(r0, &buf) + if err != nil { + return fmt.Errorf("failed to write result value 0: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.DebugContext(ctx, "transmitting `wasmcloud:couchbase/document@0.1.0-draft.get-all-replicas` result") + _, err = w.Write(buf.Bytes()) + if err != nil { + return fmt.Errorf("failed to write result: %w", err) + } + if len(writes) > 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.get-all-replicas`: %w", err) + } + stops = append(stops, stop5) + stop6, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "remove", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.remove`: %w", err) + } + stops = append(stops, stop6) + stop7, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "get-and-lock", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.get-and-lock`: %w", err) + } + stops = append(stops, stop7) + stop8, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "unlock", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.unlock`: %w", err) + } + stops = append(stops, stop8) + stop9, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "touch", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.touch`: %w", err) + } + stops = append(stops, stop9) + stop10, err := s.Serve("wasmcloud:couchbase/document@0.1.0-draft", "get-and-touch", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { + slog.DebugContext(ctx, "reading parameter", "i", 0) + p0, err := func() (DocumentId, error) { + v, err := func() (wasmcloud__couchbase__types.DocumentId, error) { + v, err := func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u64 byte: %w", err) + } + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< 0 { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + } + return nil + }) + if err != nil { + return nil, fmt.Errorf("failed to serve `wasmcloud:couchbase/document@0.1.0-draft.get-and-touch`: %w", err) + } + stops = append(stops, stop10) + return stop, nil +} diff --git a/bindings/interfaces.wrpc.go b/bindings/interfaces.wrpc.go new file mode 100644 index 0000000..c694bc1 --- /dev/null +++ b/bindings/interfaces.wrpc.go @@ -0,0 +1,32 @@ +// Generated by `wit-bindgen-wrpc-go` 0.1.1. DO NOT EDIT! +// interfaces package contains wRPC bindings for `interfaces` world +package interfaces + +import ( + exports__wasmcloud__couchbase__document "github.com/couchbase-examples/wasmcloud-provider-couchbase/bindings/exports/wasmcloud/couchbase/document" + wrpc "github.com/wrpc/wrpc/go" +) + +func Serve(s wrpc.Server, h0 exports__wasmcloud__couchbase__document.Handler) (stop func() error, err error) { + stops := make([]func() error, 0, 1) + stop = func() error { + for _, stop := range stops { + if err := stop(); err != nil { + return err + } + } + return nil + } + stop0, err := exports__wasmcloud__couchbase__document.ServeInterface(s, h0) + if err != nil { + return + } + stops = append(stops, stop0) + stop = func() error { + if err := stop0(); err != nil { + return err + } + return nil + } + return +} diff --git a/bindings/wasmcloud/couchbase/types/bindings.wrpc.go b/bindings/wasmcloud/couchbase/types/bindings.wrpc.go new file mode 100644 index 0000000..4ac6c09 --- /dev/null +++ b/bindings/wasmcloud/couchbase/types/bindings.wrpc.go @@ -0,0 +1,1500 @@ +// Generated by `wit-bindgen-wrpc-go` 0.1.1. DO NOT EDIT! +package types + +import ( + bytes "bytes" + context "context" + binary "encoding/binary" + errors "errors" + fmt "fmt" + wrpc "github.com/wrpc/wrpc/go" + io "io" + slog "log/slog" + math "math" + sync "sync" + atomic "sync/atomic" + utf8 "unicode/utf8" +) + +// ID of a Document +// +// Note that Document IDs are expected to be: +// - Assigned at the application level +// - Be valid UTF-8 at the application level +// - Be no longer than 250 bytes (not characters) +type DocumentId = string + +// The span of a request, normally used when performing/enabling tracing +type RequestSpan = string + +// A string that is properly formatted JSON +type JsonString = string + +// Whether to enable replica reads for the request +type ReplicaReadLevel uint8 + +const ( + ReplicaReadLevel_Off ReplicaReadLevel = 0 + ReplicaReadLevel_On ReplicaReadLevel = 1 +) + +func (v ReplicaReadLevel) String() string { + switch v { + case ReplicaReadLevel_Off: + return "off" + case ReplicaReadLevel_On: + return "on" + default: + panic("invalid enum") + } +} +func (v ReplicaReadLevel) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + if err := func(v uint8, w io.Writer) error { + b := make([]byte, 2) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u8 discriminant") + _, err := w.Write(b[:i]) + return err + }(uint8(v), w); err != nil { + return nil, fmt.Errorf("failed to write discriminant: %w", err) + } + return nil, nil +} + +// Port of https://pkg.go.dev/time#Time +type Time struct { + // Offsets are assumed to be against the western hemisphere (GMT) + // i.e. -14 -> 0 -> +14 UTC + Offset int8 + Year int32 + Month uint8 + Day uint8 + // 24hr time (i.e. 6PM is represented as `18`) + Hour uint8 + Minute uint8 + Second uint8 + Milliseconds uint32 + Nanoseconds uint32 +} + +func (v *Time) String() string { return "Time" } + +func (v *Time) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 9) + slog.Debug("writing field", "name", "offset") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v int8, w io.ByteWriter) error { + slog.Debug("writing s8 byte") + return w.WriteByte(byte(v)) + }(v.Offset, w) + if err != nil { + return nil, fmt.Errorf("failed to write `offset` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "year") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v int32, w io.ByteWriter) (err error) { + for { + b := byte(v & 0x7f) + v >>= 7 + + signb := b & 0x40 + + last := false + if (v == 0 && signb == 0) || (v == -1 && signb != 0) { + last = true + } else { + b = b | 0x80 + } + slog.Debug("writing s32 byte") + if err = w.WriteByte(b); err != nil { + return fmt.Errorf("failed to write `s32` byte: %w", err) + } + if last { + return nil + } + } + }(v.Year, w) + if err != nil { + return nil, fmt.Errorf("failed to write `year` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "month") + write2, err := (func(wrpc.IndexWriter) error)(nil), func(v uint8, w io.ByteWriter) error { + slog.Debug("writing u8 byte") + return w.WriteByte(v) + }(v.Month, w) + if err != nil { + return nil, fmt.Errorf("failed to write `month` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "day") + write3, err := (func(wrpc.IndexWriter) error)(nil), func(v uint8, w io.ByteWriter) error { + slog.Debug("writing u8 byte") + return w.WriteByte(v) + }(v.Day, w) + if err != nil { + return nil, fmt.Errorf("failed to write `day` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "hour") + write4, err := (func(wrpc.IndexWriter) error)(nil), func(v uint8, w io.ByteWriter) error { + slog.Debug("writing u8 byte") + return w.WriteByte(v) + }(v.Hour, w) + if err != nil { + return nil, fmt.Errorf("failed to write `hour` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + slog.Debug("writing field", "name", "minute") + write5, err := (func(wrpc.IndexWriter) error)(nil), func(v uint8, w io.ByteWriter) error { + slog.Debug("writing u8 byte") + return w.WriteByte(v) + }(v.Minute, w) + if err != nil { + return nil, fmt.Errorf("failed to write `minute` field: %w", err) + } + if write5 != nil { + writes[5] = write5 + } + slog.Debug("writing field", "name", "second") + write6, err := (func(wrpc.IndexWriter) error)(nil), func(v uint8, w io.ByteWriter) error { + slog.Debug("writing u8 byte") + return w.WriteByte(v) + }(v.Second, w) + if err != nil { + return nil, fmt.Errorf("failed to write `second` field: %w", err) + } + if write6 != nil { + writes[6] = write6 + } + slog.Debug("writing field", "name", "milliseconds") + write7, err := (func(wrpc.IndexWriter) error)(nil), func(v uint32, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u32") + _, err = w.Write(b[:i]) + return err + }(v.Milliseconds, w) + if err != nil { + return nil, fmt.Errorf("failed to write `milliseconds` field: %w", err) + } + if write7 != nil { + writes[7] = write7 + } + slog.Debug("writing field", "name", "nanoseconds") + write8, err := (func(wrpc.IndexWriter) error)(nil), func(v uint32, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u32") + _, err = w.Write(b[:i]) + return err + }(v.Nanoseconds, w) + if err != nil { + return nil, fmt.Errorf("failed to write `nanoseconds` field: %w", err) + } + if write8 != nil { + writes[8] = write8 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Errors that can occur during operations on documents +type DocumentError struct { + payload any + discriminant DocumentErrorDiscriminant +} + +func (v *DocumentError) Discriminant() DocumentErrorDiscriminant { return v.discriminant } + +type DocumentErrorDiscriminant uint8 + +const ( + // Document could not be found + DocumentErrorNotFound DocumentErrorDiscriminant = 0 + // CAS revision submitted to operation does not match value on server + DocumentErrorCasMismatch DocumentErrorDiscriminant = 1 + // Document is locked + DocumentErrorLocked DocumentErrorDiscriminant = 2 + // Unlock con a document that is not locked + DocumentErrorNotLocked DocumentErrorDiscriminant = 3 + // Document cannot be retrieved (from any replica) + DocumentErrorUnretrievable DocumentErrorDiscriminant = 4 + // Document already exists (i.e. a duplicate) + DocumentErrorAlreadyExists DocumentErrorDiscriminant = 5 + // Document is not JSON + DocumentErrorNotJson DocumentErrorDiscriminant = 6 + // Document does not contain the specified sub-document path + DocumentErrorPathNotFound DocumentErrorDiscriminant = 7 + // Sub-document path is invalid (could not be parsed) + DocumentErrorPathInvalid DocumentErrorDiscriminant = 8 + // Sub-document path is too deeply nested + DocumentErrorPathTooDeep DocumentErrorDiscriminant = 9 + // Sub-document operation could not insert + DocumentErrorInvalidValue DocumentErrorDiscriminant = 10 + // An invalid delta is used when performing a sub-document operation + DocumentErrorSubdocumentDeltaInvalid DocumentErrorDiscriminant = 11 +) + +func (v *DocumentError) String() string { + switch v.discriminant { + case DocumentErrorNotFound: + return "not-found" + case DocumentErrorCasMismatch: + return "cas-mismatch" + case DocumentErrorLocked: + return "locked" + case DocumentErrorNotLocked: + return "not-locked" + case DocumentErrorUnretrievable: + return "unretrievable" + case DocumentErrorAlreadyExists: + return "already-exists" + case DocumentErrorNotJson: + return "not-json" + case DocumentErrorPathNotFound: + return "path-not-found" + case DocumentErrorPathInvalid: + return "path-invalid" + case DocumentErrorPathTooDeep: + return "path-too-deep" + case DocumentErrorInvalidValue: + return "invalid-value" + case DocumentErrorSubdocumentDeltaInvalid: + return "subdocument-delta-invalid" + default: + panic("invalid variant") + } +} + +// Document could not be found +func (v *DocumentError) GetNotFound() (ok bool) { + if ok = (v.discriminant == DocumentErrorNotFound); !ok { + return + } + return +} + +// Document could not be found +func (v *DocumentError) SetNotFound() *DocumentError { + v.discriminant = DocumentErrorNotFound + v.payload = nil + return v +} + +// Document could not be found +func NewDocumentErrorNotFound() *DocumentError { + return (&DocumentError{}).SetNotFound() +} + +// CAS revision submitted to operation does not match value on server +func (v *DocumentError) GetCasMismatch() (ok bool) { + if ok = (v.discriminant == DocumentErrorCasMismatch); !ok { + return + } + return +} + +// CAS revision submitted to operation does not match value on server +func (v *DocumentError) SetCasMismatch() *DocumentError { + v.discriminant = DocumentErrorCasMismatch + v.payload = nil + return v +} + +// CAS revision submitted to operation does not match value on server +func NewDocumentErrorCasMismatch() *DocumentError { + return (&DocumentError{}).SetCasMismatch() +} + +// Document is locked +func (v *DocumentError) GetLocked() (ok bool) { + if ok = (v.discriminant == DocumentErrorLocked); !ok { + return + } + return +} + +// Document is locked +func (v *DocumentError) SetLocked() *DocumentError { + v.discriminant = DocumentErrorLocked + v.payload = nil + return v +} + +// Document is locked +func NewDocumentErrorLocked() *DocumentError { + return (&DocumentError{}).SetLocked() +} + +// Unlock con a document that is not locked +func (v *DocumentError) GetNotLocked() (ok bool) { + if ok = (v.discriminant == DocumentErrorNotLocked); !ok { + return + } + return +} + +// Unlock con a document that is not locked +func (v *DocumentError) SetNotLocked() *DocumentError { + v.discriminant = DocumentErrorNotLocked + v.payload = nil + return v +} + +// Unlock con a document that is not locked +func NewDocumentErrorNotLocked() *DocumentError { + return (&DocumentError{}).SetNotLocked() +} + +// Document cannot be retrieved (from any replica) +func (v *DocumentError) GetUnretrievable() (ok bool) { + if ok = (v.discriminant == DocumentErrorUnretrievable); !ok { + return + } + return +} + +// Document cannot be retrieved (from any replica) +func (v *DocumentError) SetUnretrievable() *DocumentError { + v.discriminant = DocumentErrorUnretrievable + v.payload = nil + return v +} + +// Document cannot be retrieved (from any replica) +func NewDocumentErrorUnretrievable() *DocumentError { + return (&DocumentError{}).SetUnretrievable() +} + +// Document already exists (i.e. a duplicate) +func (v *DocumentError) GetAlreadyExists() (ok bool) { + if ok = (v.discriminant == DocumentErrorAlreadyExists); !ok { + return + } + return +} + +// Document already exists (i.e. a duplicate) +func (v *DocumentError) SetAlreadyExists() *DocumentError { + v.discriminant = DocumentErrorAlreadyExists + v.payload = nil + return v +} + +// Document already exists (i.e. a duplicate) +func NewDocumentErrorAlreadyExists() *DocumentError { + return (&DocumentError{}).SetAlreadyExists() +} + +// Document is not JSON +func (v *DocumentError) GetNotJson() (ok bool) { + if ok = (v.discriminant == DocumentErrorNotJson); !ok { + return + } + return +} + +// Document is not JSON +func (v *DocumentError) SetNotJson() *DocumentError { + v.discriminant = DocumentErrorNotJson + v.payload = nil + return v +} + +// Document is not JSON +func NewDocumentErrorNotJson() *DocumentError { + return (&DocumentError{}).SetNotJson() +} + +// Document does not contain the specified sub-document path +func (v *DocumentError) GetPathNotFound() (ok bool) { + if ok = (v.discriminant == DocumentErrorPathNotFound); !ok { + return + } + return +} + +// Document does not contain the specified sub-document path +func (v *DocumentError) SetPathNotFound() *DocumentError { + v.discriminant = DocumentErrorPathNotFound + v.payload = nil + return v +} + +// Document does not contain the specified sub-document path +func NewDocumentErrorPathNotFound() *DocumentError { + return (&DocumentError{}).SetPathNotFound() +} + +// Sub-document path is invalid (could not be parsed) +func (v *DocumentError) GetPathInvalid() (ok bool) { + if ok = (v.discriminant == DocumentErrorPathInvalid); !ok { + return + } + return +} + +// Sub-document path is invalid (could not be parsed) +func (v *DocumentError) SetPathInvalid() *DocumentError { + v.discriminant = DocumentErrorPathInvalid + v.payload = nil + return v +} + +// Sub-document path is invalid (could not be parsed) +func NewDocumentErrorPathInvalid() *DocumentError { + return (&DocumentError{}).SetPathInvalid() +} + +// Sub-document path is too deeply nested +func (v *DocumentError) GetPathTooDeep() (ok bool) { + if ok = (v.discriminant == DocumentErrorPathTooDeep); !ok { + return + } + return +} + +// Sub-document path is too deeply nested +func (v *DocumentError) SetPathTooDeep() *DocumentError { + v.discriminant = DocumentErrorPathTooDeep + v.payload = nil + return v +} + +// Sub-document path is too deeply nested +func NewDocumentErrorPathTooDeep() *DocumentError { + return (&DocumentError{}).SetPathTooDeep() +} + +// Sub-document operation could not insert +func (v *DocumentError) GetInvalidValue() (ok bool) { + if ok = (v.discriminant == DocumentErrorInvalidValue); !ok { + return + } + return +} + +// Sub-document operation could not insert +func (v *DocumentError) SetInvalidValue() *DocumentError { + v.discriminant = DocumentErrorInvalidValue + v.payload = nil + return v +} + +// Sub-document operation could not insert +func NewDocumentErrorInvalidValue() *DocumentError { + return (&DocumentError{}).SetInvalidValue() +} + +// An invalid delta is used when performing a sub-document operation +func (v *DocumentError) GetSubdocumentDeltaInvalid() (ok bool) { + if ok = (v.discriminant == DocumentErrorSubdocumentDeltaInvalid); !ok { + return + } + return +} + +// An invalid delta is used when performing a sub-document operation +func (v *DocumentError) SetSubdocumentDeltaInvalid() *DocumentError { + v.discriminant = DocumentErrorSubdocumentDeltaInvalid + v.payload = nil + return v +} + +// An invalid delta is used when performing a sub-document operation +func NewDocumentErrorSubdocumentDeltaInvalid() *DocumentError { + return (&DocumentError{}).SetSubdocumentDeltaInvalid() +} +func (v *DocumentError) Error() string { return v.String() } +func (v *DocumentError) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + if err := func(v uint8, w io.Writer) error { + b := make([]byte, 2) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u8 discriminant") + _, err := w.Write(b[:i]) + return err + }(uint8(v.discriminant), w); err != nil { + return nil, fmt.Errorf("failed to write discriminant: %w", err) + } + switch v.discriminant { + case DocumentErrorNotFound: + case DocumentErrorCasMismatch: + case DocumentErrorLocked: + case DocumentErrorNotLocked: + case DocumentErrorUnretrievable: + case DocumentErrorAlreadyExists: + case DocumentErrorNotJson: + case DocumentErrorPathNotFound: + case DocumentErrorPathInvalid: + case DocumentErrorPathTooDeep: + case DocumentErrorInvalidValue: + case DocumentErrorSubdocumentDeltaInvalid: + default: + return nil, errors.New("invalid variant") + } + return nil, nil +} + +// Errors that occur when building/using document values +type DocumentValueCreateError struct { + payload any + discriminant DocumentValueCreateErrorDiscriminant +} + +func (v *DocumentValueCreateError) Discriminant() DocumentValueCreateErrorDiscriminant { + return v.discriminant +} + +type DocumentValueCreateErrorDiscriminant uint8 + +const ( + // JSON used to create the document value was invalid + DocumentValueCreateErrorInvalidJson DocumentValueCreateErrorDiscriminant = 0 +) + +func (v *DocumentValueCreateError) String() string { + switch v.discriminant { + case DocumentValueCreateErrorInvalidJson: + return "invalid-json" + default: + panic("invalid variant") + } +} + +// JSON used to create the document value was invalid +func (v *DocumentValueCreateError) GetInvalidJson() (payload string, ok bool) { + if ok = (v.discriminant == DocumentValueCreateErrorInvalidJson); !ok { + return + } + payload, ok = v.payload.(string) + return +} + +// JSON used to create the document value was invalid +func (v *DocumentValueCreateError) SetInvalidJson(payload string) *DocumentValueCreateError { + v.discriminant = DocumentValueCreateErrorInvalidJson + v.payload = payload + return v +} + +// JSON used to create the document value was invalid +func NewDocumentValueCreateErrorInvalidJson(payload string) *DocumentValueCreateError { + return (&DocumentValueCreateError{}).SetInvalidJson( + payload) +} +func (v *DocumentValueCreateError) Error() string { return v.String() } +func (v *DocumentValueCreateError) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + if err := func(v uint8, w io.Writer) error { + b := make([]byte, 2) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u8 discriminant") + _, err := w.Write(b[:i]) + return err + }(uint8(v.discriminant), w); err != nil { + return nil, fmt.Errorf("failed to write discriminant: %w", err) + } + switch v.discriminant { + case DocumentValueCreateErrorInvalidJson: + payload, ok := v.payload.(string) + if !ok { + return nil, errors.New("invalid payload") + } + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(payload, w) + if err != nil { + return nil, fmt.Errorf("failed to write payload: %w", err) + } + + if write != nil { + return func(w wrpc.IndexWriter) error { + w, err := w.Index(0) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + return write(w) + }, nil + } + default: + return nil, errors.New("invalid variant") + } + return nil, nil +} + +// WIT cannot currently support passing recursive value types, which means JSON cannot be properly +// represetned as a WIT level type. +// +// What we use instead is a variant with two types: +// - a valid JSON string (which may or may not be an object) +// - an implementer-controlled value which is a valid JSON object (as defined by the implementer) +// +// The implementer-controlled value can be any implementation (usually a more efficient one) +// that can be understood by the implementer. One requirement on this value is that it must be +// possible to convert it to/from a raw JSON string at any time. +// +// An opaque resource that represents a JSON value, and can be efficiently +// manipulated by implementers. +type Document struct { + payload any + discriminant DocumentDiscriminant +} + +func (v *Document) Discriminant() DocumentDiscriminant { return v.discriminant } + +type DocumentDiscriminant uint8 + +const ( + // A stringified JSON value represented by a resource, often used by callers + // that cannot or do not want to construct an efficient implementer specific JSON value + DocumentRaw DocumentDiscriminant = 0 + // A JSON value represented by a more efficient but opaque implementer-specific representation + DocumentResource DocumentDiscriminant = 1 +) + +func (v *Document) String() string { + switch v.discriminant { + case DocumentRaw: + return "raw" + case DocumentResource: + return "resource" + default: + panic("invalid variant") + } +} + +// A stringified JSON value represented by a resource, often used by callers +// that cannot or do not want to construct an efficient implementer specific JSON value +func (v *Document) GetRaw() (payload JsonString, ok bool) { + if ok = (v.discriminant == DocumentRaw); !ok { + return + } + payload, ok = v.payload.(JsonString) + return +} + +// A stringified JSON value represented by a resource, often used by callers +// that cannot or do not want to construct an efficient implementer specific JSON value +func (v *Document) SetRaw(payload string) *Document { + v.discriminant = DocumentRaw + v.payload = payload + return v +} + +// A stringified JSON value represented by a resource, often used by callers +// that cannot or do not want to construct an efficient implementer specific JSON value +func NewDocumentRaw(payload string) *Document { + return (&Document{}).SetRaw( + payload) +} + +// A JSON value represented by a more efficient but opaque implementer-specific representation +func (v *Document) GetResource() (payload wrpc.Own[DocumentValue], ok bool) { + if ok = (v.discriminant == DocumentResource); !ok { + return + } + payload, ok = v.payload.(wrpc.Own[DocumentValue]) + return +} + +// A JSON value represented by a more efficient but opaque implementer-specific representation +func (v *Document) SetResource(payload wrpc.Own[DocumentValue]) *Document { + v.discriminant = DocumentResource + v.payload = payload + return v +} + +// A JSON value represented by a more efficient but opaque implementer-specific representation +func NewDocumentResource(payload wrpc.Own[DocumentValue]) *Document { + return (&Document{}).SetResource( + payload) +} +func (v *Document) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + if err := func(v uint8, w io.Writer) error { + b := make([]byte, 2) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u8 discriminant") + _, err := w.Write(b[:i]) + return err + }(uint8(v.discriminant), w); err != nil { + return nil, fmt.Errorf("failed to write discriminant: %w", err) + } + switch v.discriminant { + case DocumentRaw: + payload, ok := v.payload.(string) + if !ok { + return nil, errors.New("invalid payload") + } + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(payload, w) + if err != nil { + return nil, fmt.Errorf("failed to write payload: %w", err) + } + + if write != nil { + return func(w wrpc.IndexWriter) error { + w, err := w.Index(0) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + return write(w) + }, nil + } + case DocumentResource: + payload, ok := v.payload.(wrpc.Own[DocumentValue]) + if !ok { + return nil, errors.New("invalid payload") + } + write, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(string(payload), w) + if err != nil { + return nil, fmt.Errorf("failed to write payload: %w", err) + } + + if write != nil { + return func(w wrpc.IndexWriter) error { + w, err := w.Index(1) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + return write(w) + }, nil + } + default: + return nil, errors.New("invalid variant") + } + return nil, nil +} + +// Metadata related to any mutation on a Couchbase collection (ex. CRUD operations) +type MutationMetadata struct { + // CAS revision of the document + Cas uint64 + // The bucket on which the mutation was performed + Bucket string + // The ID of the vbucket (partition) that the operation was performed on + PartitionId uint64 + // The UUID of the vbucket (partition) that the operation was performed on + PartitionUuid uint64 + // The sequence number of the operation performed on the vbucket (partition) + Seq uint64 +} + +func (v *MutationMetadata) String() string { return "MutationMetadata" } + +func (v *MutationMetadata) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 5) + slog.Debug("writing field", "name", "cas") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Cas, w) + if err != nil { + return nil, fmt.Errorf("failed to write `cas` field: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing field", "name", "bucket") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) { + n := len(v) + if n > math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(v.Bucket, w) + if err != nil { + return nil, fmt.Errorf("failed to write `bucket` field: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + slog.Debug("writing field", "name", "partition-id") + write2, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.PartitionId, w) + if err != nil { + return nil, fmt.Errorf("failed to write `partition-id` field: %w", err) + } + if write2 != nil { + writes[2] = write2 + } + slog.Debug("writing field", "name", "partition-uuid") + write3, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.PartitionUuid, w) + if err != nil { + return nil, fmt.Errorf("failed to write `partition-uuid` field: %w", err) + } + if write3 != nil { + writes[3] = write3 + } + slog.Debug("writing field", "name", "seq") + write4, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.Seq, w) + if err != nil { + return nil, fmt.Errorf("failed to write `seq` field: %w", err) + } + if write4 != nil { + writes[4] = write4 + } + + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil +} + +// Durability level that should be used for operations +type DurabilityLevel uint8 + +const ( + DurabilityLevel_Unknown DurabilityLevel = 0 + DurabilityLevel_None DurabilityLevel = 1 + // Replicate (hold in memory) to a majority of nodes + DurabilityLevel_ReplicateMajority DurabilityLevel = 2 + // Replicate (hold in memory) to a majority of nodes, persist (write to disk) to master + DurabilityLevel_ReplicateMajorityPersistMaster DurabilityLevel = 3 + // Persist to a majority of nodes + DurabilityLevel_PersistMajority DurabilityLevel = 4 +) + +func (v DurabilityLevel) String() string { + switch v { + case DurabilityLevel_Unknown: + return "unknown" + case DurabilityLevel_None: + return "none" + case DurabilityLevel_ReplicateMajority: + return "replicate-majority" + case DurabilityLevel_ReplicateMajorityPersistMaster: + return "replicate-majority-persist-master" + case DurabilityLevel_PersistMajority: + return "persist-majority" + default: + panic("invalid enum") + } +} +func (v DurabilityLevel) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + if err := func(v uint8, w io.Writer) error { + b := make([]byte, 2) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u8 discriminant") + _, err := w.Write(b[:i]) + return err + }(uint8(v), w); err != nil { + return nil, fmt.Errorf("failed to write discriminant: %w", err) + } + return nil, nil +} + +// As functions cannot be represented as part of types in WIT, +// we represent static retry strategies +type RetryStrategy struct { + payload any + discriminant RetryStrategyDiscriminant +} + +func (v *RetryStrategy) Discriminant() RetryStrategyDiscriminant { return v.discriminant } + +type RetryStrategyDiscriminant uint8 + +const ( + // Retry a certain number of times with a given interval between each retry) + RetryStrategyIntervalTimesMs RetryStrategyDiscriminant = 0 +) + +func (v *RetryStrategy) String() string { + switch v.discriminant { + case RetryStrategyIntervalTimesMs: + return "interval-times-ms" + default: + panic("invalid variant") + } +} + +// Retry a certain number of times with a given interval between each retry) +func (v *RetryStrategy) GetIntervalTimesMs() (payload wrpc.Tuple2[uint64, uint64], ok bool) { + if ok = (v.discriminant == RetryStrategyIntervalTimesMs); !ok { + return + } + payload, ok = v.payload.(wrpc.Tuple2[uint64, uint64]) + return +} + +// Retry a certain number of times with a given interval between each retry) +func (v *RetryStrategy) SetIntervalTimesMs(payload *wrpc.Tuple2[uint64, uint64]) *RetryStrategy { + v.discriminant = RetryStrategyIntervalTimesMs + v.payload = payload + return v +} + +// Retry a certain number of times with a given interval between each retry) +func NewRetryStrategyIntervalTimesMs(payload *wrpc.Tuple2[uint64, uint64]) *RetryStrategy { + return (&RetryStrategy{}).SetIntervalTimesMs( + payload) +} +func (v *RetryStrategy) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { + if err := func(v uint8, w io.Writer) error { + b := make([]byte, 2) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u8 discriminant") + _, err := w.Write(b[:i]) + return err + }(uint8(v.discriminant), w); err != nil { + return nil, fmt.Errorf("failed to write discriminant: %w", err) + } + switch v.discriminant { + case RetryStrategyIntervalTimesMs: + payload, ok := v.payload.(*wrpc.Tuple2[uint64, uint64]) + if !ok { + return nil, errors.New("invalid payload") + } + write, err := func(v *wrpc.Tuple2[uint64, uint64], w interface { + io.ByteWriter + io.Writer + }) (func(wrpc.IndexWriter) error, error) { + writes := make(map[uint32]func(wrpc.IndexWriter) error, 2) + slog.Debug("writing tuple element 0") + write0, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.V0, w) + if err != nil { + return nil, fmt.Errorf("failed to write tuple element 0: %w", err) + } + if write0 != nil { + writes[0] = write0 + } + slog.Debug("writing tuple element 1") + write1, err := (func(wrpc.IndexWriter) error)(nil), func(v uint64, w io.Writer) (err error) { + b := make([]byte, binary.MaxVarintLen64) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing u64") + _, err = w.Write(b[:i]) + return err + }(v.V1, w) + if err != nil { + return nil, fmt.Errorf("failed to write tuple element 1: %w", err) + } + if write1 != nil { + writes[1] = write1 + } + if len(writes) > 0 { + return func(w wrpc.IndexWriter) error { + var wg sync.WaitGroup + var wgErr atomic.Value + for index, write := range writes { + wg.Add(1) + w, err := w.Index(index) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + write := write + go func() { + defer wg.Done() + if err := write(w); err != nil { + wgErr.Store(err) + } + }() + } + wg.Wait() + err := wgErr.Load() + if err == nil { + return nil + } + return err.(error) + }, nil + } + return nil, nil + }(payload, w) + if err != nil { + return nil, fmt.Errorf("failed to write payload: %w", err) + } + + if write != nil { + return func(w wrpc.IndexWriter) error { + w, err := w.Index(0) + if err != nil { + return fmt.Errorf("failed to index writer: %w", err) + } + return write(w) + }, nil + } + default: + return nil, errors.New("invalid variant") + } + return nil, nil +} + +// Construct an empty document value (a dictionary, by default) +func NewDocumentValue(ctx__ context.Context, wrpc__ wrpc.Invoker) (r0__ wrpc.Own[DocumentValue], close__ func() error, err__ error) { + if err__ = wrpc__.Invoke(ctx__, "wasmcloud:couchbase/types@0.1.0-draft", "document-value", func(w__ wrpc.IndexWriter, r__ wrpc.IndexReadCloser) error { + close__ = r__.Close + _, err__ = w__.Write(nil) + if err__ != nil { + return fmt.Errorf("failed to write empty parameters: %w", err__) + } + r0__, err__ = func(r interface { + io.ByteReader + io.Reader + }) (wrpc.Own[DocumentValue], error) { + var x uint32 + var s uint + for i := 0; i < 5; i++ { + slog.Debug("reading owned resource ID length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + } + if b < 0x80 { + if i == 4 && b > 1 { + return "", errors.New("owned resource ID length overflows a 32-bit integer") + } + x = x | uint32(b)< math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(string(self), &buf__) + if err__ != nil { + return fmt.Errorf("failed to write `self` parameter: %w", err__) + } + if write0__ != nil { + writes__[0] = write0__ + } + _, err__ = w__.Write(buf__.Bytes()) + if err__ != nil { + return fmt.Errorf("failed to write parameters: %w", err__) + } + r0__, err__ = func(r interface { + io.ByteReader + io.Reader + }) (string, error) { + var x uint32 + var s uint8 + for i := 0; i < 5; i++ { + slog.Debug("reading string length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< math.MaxUint32 { + return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n) + } + if err = func(v int, w io.Writer) error { + b := make([]byte, binary.MaxVarintLen32) + i := binary.PutUvarint(b, uint64(v)) + slog.Debug("writing string byte length", "len", n) + _, err = w.Write(b[:i]) + return err + }(n, w); err != nil { + return fmt.Errorf("failed to write string byte length of %d: %w", n, err) + } + slog.Debug("writing string bytes") + _, err = w.Write([]byte(v)) + if err != nil { + return fmt.Errorf("failed to write string bytes: %w", err) + } + return nil + }(json, &buf__) + if err__ != nil { + return fmt.Errorf("failed to write `json` parameter: %w", err__) + } + if write0__ != nil { + writes__[0] = write0__ + } + _, err__ = w__.Write(buf__.Bytes()) + if err__ != nil { + return fmt.Errorf("failed to write parameters: %w", err__) + } + r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[wrpc.Own[DocumentValue], DocumentValueCreateError], error) { + slog.Debug("reading result status byte") + status, err := r.ReadByte() + if err != nil { + return nil, fmt.Errorf("failed to read result status byte: %w", err) + } + switch status { + case 0: + slog.Debug("reading `result::ok` payload") + v, err := func(r interface { + io.ByteReader + io.Reader + }) (wrpc.Own[DocumentValue], error) { + var x uint32 + var s uint + for i := 0; i < 5; i++ { + slog.Debug("reading owned resource ID length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + } + if b < 0x80 { + if i == 4 && b > 1 { + return "", errors.New("owned resource ID length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) + } + if s == 7 && b > 0x01 { + return x, errors.New("discriminant overflows an 8-bit integer") + } + if b < 0x80 { + return x | uint8(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) + } + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") + } + if b < 0x80 { + x = x | uint32(b)< result; -} diff --git a/wit/deps/keyvalue/batch.wit b/wit/deps/keyvalue/batch.wit deleted file mode 100644 index 29fb49d..0000000 --- a/wit/deps/keyvalue/batch.wit +++ /dev/null @@ -1,63 +0,0 @@ -/// A keyvalue interface that provides batch operations. -/// -/// A batch operation is an operation that operates on multiple keys at once. -/// -/// Batch operations are useful for reducing network round-trip time. For example, if you want to -/// get the values associated with 100 keys, you can either do 100 get operations or you can do 1 -/// batch get operation. The batch operation is faster because it only needs to make 1 network call -/// instead of 100. -/// -/// A batch operation does not guarantee atomicity, meaning that if the batch operation fails, some -/// of the keys may have been modified and some may not. -/// -/// This interface does has the same consistency guarantees as the `store` interface, meaning that -/// you should be able to "read your writes." -/// -/// Please note that this interface is bare functions that take a reference to a bucket. This is to -/// get around the current lack of a way to "extend" a resource with additional methods inside of -/// wit. Future version of the interface will instead extend these methods on the base `bucket` -/// resource. -interface batch { - use store.{error}; - - /// Get the key-value pairs associated with the keys in the store. It returns a list of - /// key-value pairs. - /// - /// If any of the keys do not exist in the store, it returns a `none` value for that pair in the - /// list. - /// - /// MAY show an out-of-date value if there are concurrent writes to the store. - /// - /// If any other error occurs, it returns an `Err(error)`. - get-many: func(bucket: string, keys: list) -> result>>>, error>; - - /// Set the values associated with the keys in the store. If the key already exists in the - /// store, it overwrites the value. - /// - /// Note that the key-value pairs are not guaranteed to be set in the order they are provided. - /// - /// If any of the keys do not exist in the store, it creates a new key-value pair. - /// - /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it does not - /// rollback the key-value pairs that were already set. Thus, this batch operation does not - /// guarantee atomicity, implying that some key-value pairs could be set while others might - /// fail. - /// - /// Other concurrent operations may also be able to see the partial results. - set-many: func(bucket: string, key-values: list>>) -> result<_, error>; - - /// Delete the key-value pairs associated with the keys in the store. - /// - /// Note that the key-value pairs are not guaranteed to be deleted in the order they are - /// provided. - /// - /// If any of the keys do not exist in the store, it skips the key. - /// - /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it does not - /// rollback the key-value pairs that were already deleted. Thus, this batch operation does not - /// guarantee atomicity, implying that some key-value pairs could be deleted while others might - /// fail. - /// - /// Other concurrent operations may also be able to see the partial results. - delete-many: func(bucket: string, keys: list) -> result<_, error>; -} diff --git a/wit/deps/keyvalue/store.wit b/wit/deps/keyvalue/store.wit deleted file mode 100644 index 2b66a3b..0000000 --- a/wit/deps/keyvalue/store.wit +++ /dev/null @@ -1,114 +0,0 @@ -/// A keyvalue interface that provides eventually consistent key-value operations. -/// -/// Each of these operations acts on a single key-value pair. -/// -/// The value in the key-value pair is defined as a `u8` byte array and the intention is that it is -/// the common denominator for all data types defined by different key-value stores to handle data, -/// ensuring compatibility between different key-value stores. Note: the clients will be expecting -/// serialization/deserialization overhead to be handled by the key-value store. The value could be -/// a serialized object from JSON, HTML or vendor-specific data types like AWS S3 objects. -/// -/// Data consistency in a key value store refers to the guarantee that once a write operation -/// completes, all subsequent read operations will return the value that was written. -/// -/// Any implementation of this interface must have enough consistency to guarantee "reading your -/// writes." In particular, this means that the client should never get a value that is older than -/// the one it wrote, but it MAY get a newer value if one was written around the same time. These -/// guarantees only apply to the same client (which will likely be provided by the host or an -/// external capability of some kind). In this context a "client" is referring to the caller or -/// guest that is consuming this interface. Once a write request is committed by a specific client, -/// all subsequent read requests by the same client will reflect that write or any subsequent -/// writes. Another client running in a different context may or may not immediately see the result -/// due to the replication lag. As an example of all of this, if a value at a given key is A, and -/// the client writes B, then immediately reads, it should get B. If something else writes C in -/// quick succession, then the client may get C. However, a client running in a separate context may -/// still see A or B -interface store { - /// The set of errors which may be raised by functions in this package - variant error { - /// The host does not recognize the store identifier requested. - no-such-store, - - /// The requesting component does not have access to the specified store - /// (which may or may not exist). - access-denied, - - /// Some implementation-specific error has occurred (e.g. I/O) - other(string) - } - - /// A response to a `list-keys` operation. - record key-response { - /// The list of keys returned by the query. - keys: list, - /// The continuation token to use to fetch the next page of keys. If this is `null`, then - /// there are no more keys to fetch. - cursor: option - } - - /// A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the - /// bucket, and the bucket itself acts as a collection of all these entries. - /// - /// It is worth noting that the exact terminology for bucket in key-value stores can very - /// depending on the specific implementation. For example: - /// - /// 1. Amazon DynamoDB calls a collection of key-value pairs a table - /// 2. Redis has hashes, sets, and sorted sets as different types of collections - /// 3. Cassandra calls a collection of key-value pairs a column family - /// 4. MongoDB calls a collection of key-value pairs a collection - /// 5. Riak calls a collection of key-value pairs a bucket - /// 6. Memcached calls a collection of key-value pairs a slab - /// 7. Azure Cosmos DB calls a collection of key-value pairs a container - /// - /// In this interface, we use the term `bucket` to refer to a collection of key-value pairs - - /// Get the value associated with the specified `key` - /// - /// The value is returned as an option. If the key-value pair exists in the - /// store, it returns `Ok(value)`. If the key does not exist in the - /// store, it returns `Ok(none)`. - /// - /// If any other error occurs, it returns an `Err(error)`. - get: func(bucket: string, key: string) -> result>, error>; - - /// Set the value associated with the key in the store. If the key already - /// exists in the store, it overwrites the value. - /// - /// If the key does not exist in the store, it creates a new key-value pair. - /// - /// If any other error occurs, it returns an `Err(error)`. - set: func(bucket: string, key: string, value: list) -> result<_, error>; - - /// Delete the key-value pair associated with the key in the store. - /// - /// If the key does not exist in the store, it does nothing. - /// - /// If any other error occurs, it returns an `Err(error)`. - delete: func(bucket: string, key: string) -> result<_, error>; - - /// Check if the key exists in the store. - /// - /// If the key exists in the store, it returns `Ok(true)`. If the key does - /// not exist in the store, it returns `Ok(false)`. - /// - /// If any other error occurs, it returns an `Err(error)`. - exists: func(bucket: string, key: string) -> result; - - /// Get all the keys in the store with an optional cursor (for use in pagination). It - /// returns a list of keys. Please note that for most KeyValue implementations, this is a - /// can be a very expensive operation and so it should be used judiciously. Implementations - /// can return any number of keys in a single response, but they should never attempt to - /// send more data than is reasonable (i.e. on a small edge device, this may only be a few - /// KB, while on a large machine this could be several MB). Any response should also return - /// a cursor that can be used to fetch the next page of keys. See the `key-response` record - /// for more information. - /// - /// Note that the keys are not guaranteed to be returned in any particular order. - /// - /// If the store is empty, it returns an empty list. - /// - /// MAY show an out-of-date list of keys if there are concurrent writes to the store. - /// - /// If any error occurs, it returns an `Err(error)`. - list-keys: func(bucket: string, cursor: option) -> result; -} diff --git a/wit/deps/keyvalue/watch.wit b/wit/deps/keyvalue/watch.wit deleted file mode 100644 index 178ed5b..0000000 --- a/wit/deps/keyvalue/watch.wit +++ /dev/null @@ -1,15 +0,0 @@ -/// A keyvalue interface that provides watch operations. -/// -/// This interface is used to provide event-driven mechanisms to handle -/// keyvalue changes. -interface watcher { - /// A keyvalue interface that provides handle-watch operations. - - /// Handle the `set` event for the given bucket and key. It includes a reference to the `bucket` - /// that can be used to interact with the store. - on-set: func(bucket: string, key: string, value: list); - - /// Handle the `delete` event for the given bucket and key. It includes a reference to the - /// `bucket` that can be used to interact with the store. - on-delete: func(bucket: string, key: string); -} diff --git a/wit/deps/keyvalue/world.wit b/wit/deps/keyvalue/world.wit deleted file mode 100644 index 3320639..0000000 --- a/wit/deps/keyvalue/world.wit +++ /dev/null @@ -1,26 +0,0 @@ -package wrpc:keyvalue@0.2.0-draft; - -/// The `wrpc:keyvalue/imports` world provides common APIs for interacting with key-value stores. -/// Components targeting this world will be able to do: -/// -/// 1. CRUD (create, read, update, delete) operations on key-value stores. -/// 2. Atomic `increment` and CAS (compare-and-swap) operations. -/// 3. Batch operations that can reduce the number of round trips to the network. -world imports { - /// The `store` capability allows the component to perform eventually consistent operations on - /// the key-value store. - import store; - - /// The `atomic` capability allows the component to perform atomic / `increment` and CAS - /// (compare-and-swap) operations. - import atomics; - - /// The `batch` capability allows the component to perform eventually consistent batch - /// operations that can reduce the number of round trips to the network. - import batch; -} - -world watch-service { - include imports; - export watcher; -} diff --git a/wit/keyvalue/atomic.wit b/wit/keyvalue/atomic.wit deleted file mode 100644 index 2aa8d92..0000000 --- a/wit/keyvalue/atomic.wit +++ /dev/null @@ -1,22 +0,0 @@ -/// A keyvalue interface that provides atomic operations. -/// -/// Atomic operations are single, indivisible operations. When a fault causes an atomic operation to -/// fail, it will appear to the invoker of the atomic operation that the action either completed -/// successfully or did nothing at all. -/// -/// Please note that this interface is bare functions that take a reference to a bucket. This is to -/// get around the current lack of a way to "extend" a resource with additional methods inside of -/// wit. Future version of the interface will instead extend these methods on the base `bucket` -/// resource. -interface atomics { - use store.{error}; - - /// Atomically increment the value associated with the key in the store by the given delta. It - /// returns the new value. - /// - /// If the key does not exist in the store, it creates a new key-value pair with the value set - /// to the given delta. - /// - /// If any other error occurs, it returns an `Err(error)`. - increment: func(bucket: string, key: string, delta: u64) -> result; -} diff --git a/wit/keyvalue/batch.wit b/wit/keyvalue/batch.wit deleted file mode 100644 index 29fb49d..0000000 --- a/wit/keyvalue/batch.wit +++ /dev/null @@ -1,63 +0,0 @@ -/// A keyvalue interface that provides batch operations. -/// -/// A batch operation is an operation that operates on multiple keys at once. -/// -/// Batch operations are useful for reducing network round-trip time. For example, if you want to -/// get the values associated with 100 keys, you can either do 100 get operations or you can do 1 -/// batch get operation. The batch operation is faster because it only needs to make 1 network call -/// instead of 100. -/// -/// A batch operation does not guarantee atomicity, meaning that if the batch operation fails, some -/// of the keys may have been modified and some may not. -/// -/// This interface does has the same consistency guarantees as the `store` interface, meaning that -/// you should be able to "read your writes." -/// -/// Please note that this interface is bare functions that take a reference to a bucket. This is to -/// get around the current lack of a way to "extend" a resource with additional methods inside of -/// wit. Future version of the interface will instead extend these methods on the base `bucket` -/// resource. -interface batch { - use store.{error}; - - /// Get the key-value pairs associated with the keys in the store. It returns a list of - /// key-value pairs. - /// - /// If any of the keys do not exist in the store, it returns a `none` value for that pair in the - /// list. - /// - /// MAY show an out-of-date value if there are concurrent writes to the store. - /// - /// If any other error occurs, it returns an `Err(error)`. - get-many: func(bucket: string, keys: list) -> result>>>, error>; - - /// Set the values associated with the keys in the store. If the key already exists in the - /// store, it overwrites the value. - /// - /// Note that the key-value pairs are not guaranteed to be set in the order they are provided. - /// - /// If any of the keys do not exist in the store, it creates a new key-value pair. - /// - /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it does not - /// rollback the key-value pairs that were already set. Thus, this batch operation does not - /// guarantee atomicity, implying that some key-value pairs could be set while others might - /// fail. - /// - /// Other concurrent operations may also be able to see the partial results. - set-many: func(bucket: string, key-values: list>>) -> result<_, error>; - - /// Delete the key-value pairs associated with the keys in the store. - /// - /// Note that the key-value pairs are not guaranteed to be deleted in the order they are - /// provided. - /// - /// If any of the keys do not exist in the store, it skips the key. - /// - /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it does not - /// rollback the key-value pairs that were already deleted. Thus, this batch operation does not - /// guarantee atomicity, implying that some key-value pairs could be deleted while others might - /// fail. - /// - /// Other concurrent operations may also be able to see the partial results. - delete-many: func(bucket: string, keys: list) -> result<_, error>; -} diff --git a/wit/keyvalue/store.wit b/wit/keyvalue/store.wit deleted file mode 100644 index 2b66a3b..0000000 --- a/wit/keyvalue/store.wit +++ /dev/null @@ -1,114 +0,0 @@ -/// A keyvalue interface that provides eventually consistent key-value operations. -/// -/// Each of these operations acts on a single key-value pair. -/// -/// The value in the key-value pair is defined as a `u8` byte array and the intention is that it is -/// the common denominator for all data types defined by different key-value stores to handle data, -/// ensuring compatibility between different key-value stores. Note: the clients will be expecting -/// serialization/deserialization overhead to be handled by the key-value store. The value could be -/// a serialized object from JSON, HTML or vendor-specific data types like AWS S3 objects. -/// -/// Data consistency in a key value store refers to the guarantee that once a write operation -/// completes, all subsequent read operations will return the value that was written. -/// -/// Any implementation of this interface must have enough consistency to guarantee "reading your -/// writes." In particular, this means that the client should never get a value that is older than -/// the one it wrote, but it MAY get a newer value if one was written around the same time. These -/// guarantees only apply to the same client (which will likely be provided by the host or an -/// external capability of some kind). In this context a "client" is referring to the caller or -/// guest that is consuming this interface. Once a write request is committed by a specific client, -/// all subsequent read requests by the same client will reflect that write or any subsequent -/// writes. Another client running in a different context may or may not immediately see the result -/// due to the replication lag. As an example of all of this, if a value at a given key is A, and -/// the client writes B, then immediately reads, it should get B. If something else writes C in -/// quick succession, then the client may get C. However, a client running in a separate context may -/// still see A or B -interface store { - /// The set of errors which may be raised by functions in this package - variant error { - /// The host does not recognize the store identifier requested. - no-such-store, - - /// The requesting component does not have access to the specified store - /// (which may or may not exist). - access-denied, - - /// Some implementation-specific error has occurred (e.g. I/O) - other(string) - } - - /// A response to a `list-keys` operation. - record key-response { - /// The list of keys returned by the query. - keys: list, - /// The continuation token to use to fetch the next page of keys. If this is `null`, then - /// there are no more keys to fetch. - cursor: option - } - - /// A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the - /// bucket, and the bucket itself acts as a collection of all these entries. - /// - /// It is worth noting that the exact terminology for bucket in key-value stores can very - /// depending on the specific implementation. For example: - /// - /// 1. Amazon DynamoDB calls a collection of key-value pairs a table - /// 2. Redis has hashes, sets, and sorted sets as different types of collections - /// 3. Cassandra calls a collection of key-value pairs a column family - /// 4. MongoDB calls a collection of key-value pairs a collection - /// 5. Riak calls a collection of key-value pairs a bucket - /// 6. Memcached calls a collection of key-value pairs a slab - /// 7. Azure Cosmos DB calls a collection of key-value pairs a container - /// - /// In this interface, we use the term `bucket` to refer to a collection of key-value pairs - - /// Get the value associated with the specified `key` - /// - /// The value is returned as an option. If the key-value pair exists in the - /// store, it returns `Ok(value)`. If the key does not exist in the - /// store, it returns `Ok(none)`. - /// - /// If any other error occurs, it returns an `Err(error)`. - get: func(bucket: string, key: string) -> result>, error>; - - /// Set the value associated with the key in the store. If the key already - /// exists in the store, it overwrites the value. - /// - /// If the key does not exist in the store, it creates a new key-value pair. - /// - /// If any other error occurs, it returns an `Err(error)`. - set: func(bucket: string, key: string, value: list) -> result<_, error>; - - /// Delete the key-value pair associated with the key in the store. - /// - /// If the key does not exist in the store, it does nothing. - /// - /// If any other error occurs, it returns an `Err(error)`. - delete: func(bucket: string, key: string) -> result<_, error>; - - /// Check if the key exists in the store. - /// - /// If the key exists in the store, it returns `Ok(true)`. If the key does - /// not exist in the store, it returns `Ok(false)`. - /// - /// If any other error occurs, it returns an `Err(error)`. - exists: func(bucket: string, key: string) -> result; - - /// Get all the keys in the store with an optional cursor (for use in pagination). It - /// returns a list of keys. Please note that for most KeyValue implementations, this is a - /// can be a very expensive operation and so it should be used judiciously. Implementations - /// can return any number of keys in a single response, but they should never attempt to - /// send more data than is reasonable (i.e. on a small edge device, this may only be a few - /// KB, while on a large machine this could be several MB). Any response should also return - /// a cursor that can be used to fetch the next page of keys. See the `key-response` record - /// for more information. - /// - /// Note that the keys are not guaranteed to be returned in any particular order. - /// - /// If the store is empty, it returns an empty list. - /// - /// MAY show an out-of-date list of keys if there are concurrent writes to the store. - /// - /// If any error occurs, it returns an `Err(error)`. - list-keys: func(bucket: string, cursor: option) -> result; -} diff --git a/wit/keyvalue/watch.wit b/wit/keyvalue/watch.wit deleted file mode 100644 index 178ed5b..0000000 --- a/wit/keyvalue/watch.wit +++ /dev/null @@ -1,15 +0,0 @@ -/// A keyvalue interface that provides watch operations. -/// -/// This interface is used to provide event-driven mechanisms to handle -/// keyvalue changes. -interface watcher { - /// A keyvalue interface that provides handle-watch operations. - - /// Handle the `set` event for the given bucket and key. It includes a reference to the `bucket` - /// that can be used to interact with the store. - on-set: func(bucket: string, key: string, value: list); - - /// Handle the `delete` event for the given bucket and key. It includes a reference to the - /// `bucket` that can be used to interact with the store. - on-delete: func(bucket: string, key: string); -} diff --git a/wit/keyvalue/world.wit b/wit/keyvalue/world.wit deleted file mode 100644 index 3320639..0000000 --- a/wit/keyvalue/world.wit +++ /dev/null @@ -1,26 +0,0 @@ -package wrpc:keyvalue@0.2.0-draft; - -/// The `wrpc:keyvalue/imports` world provides common APIs for interacting with key-value stores. -/// Components targeting this world will be able to do: -/// -/// 1. CRUD (create, read, update, delete) operations on key-value stores. -/// 2. Atomic `increment` and CAS (compare-and-swap) operations. -/// 3. Batch operations that can reduce the number of round trips to the network. -world imports { - /// The `store` capability allows the component to perform eventually consistent operations on - /// the key-value store. - import store; - - /// The `atomic` capability allows the component to perform atomic / `increment` and CAS - /// (compare-and-swap) operations. - import atomics; - - /// The `batch` capability allows the component to perform eventually consistent batch - /// operations that can reduce the number of round trips to the network. - import batch; -} - -world watch-service { - include imports; - export watcher; -}