Class: Couchbase::Protostellar::ResponseConverter::KV Private

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/protostellar/response_converter/kv.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.extract_expiry_time(resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



141
142
143
144
145
146
147
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 141

def self.extract_expiry_time(resp)
  timestamp = resp.expiry

  return nil if timestamp.nil?

  Time.at(timestamp.seconds, timestamp.nanos, :nsec)
end

.extract_mutation_token(resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 129

def self.extract_mutation_token(resp)
  proto_token = resp.mutation_token
  return nil if proto_token.nil?

  Couchbase::MutationToken.new do |token|
    token.bucket_name = proto_token.bucket_name
    token.partition_id = proto_token.vbucket_id
    token.partition_uuid = proto_token.vbucket_uuid
    token.sequence_number = proto_token.seq_no
  end
end

.to_counter_result(resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



121
122
123
124
125
126
127
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 121

def self.to_counter_result(resp)
  Couchbase::BinaryCollection::CounterResult.new do |res|
    res.cas = resp.cas
    res.content = resp.content
    res.mutation_token = extract_mutation_token(resp)
  end
end

.to_exists_result(resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
48
49
50
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 45

def self.to_exists_result(resp)
  Couchbase::Collection::ExistsResult.new do |res|
    res.cas = resp.cas
    res.exists = resp.result
  end
end

.to_get_all_replicas_result(resps, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 93

def self.to_get_all_replicas_result(resps, options)
  resps.map do |entry|
    Couchbase::Collection::GetReplicaResult.new do |res|
      res.transcoder = options.transcoder
      res.cas = entry.cas
      res.flags = entry.content_flags
      res.encoded = entry.content
      res.is_replica = entry.is_replica
    end
  end
end

.to_get_any_replica_result(resps, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 78

def self.to_get_any_replica_result(resps, options)
  begin
    entry = resps.next
  rescue StopIteration
    raise Couchbase::Error::DocumentIrretrievable, "unable to get replica of the document"
  end
  Couchbase::Collection::GetReplicaResult.new do |res|
    res.transcoder = options.transcoder
    res.cas = entry.cas
    res.flags = entry.content_flags
    res.encoded = entry.content
    res.is_replica = entry.is_replica
  end
end

.to_get_result(resp, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 24

def self.to_get_result(resp, options)
  Couchbase::Collection::GetResult.new do |res|
    res.transcoder = options.transcoder
    res.cas = resp.cas
    res.expiry = extract_expiry_time(resp) if options.respond_to?(:with_expiry) && options.with_expiry
    res.encoded = if resp.content_uncompressed == "null" && !options.projections.empty?
                    "{}"
                  else
                    resp.content_uncompressed
                  end
    res.flags = resp.content_flags
  end
end

.to_lookup_in_result(resp, specs, options, request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 52

def self.to_lookup_in_result(resp, specs, options, request)
  Couchbase::Collection::LookupInResult.new do |res|
    res.cas = resp.cas
    res.transcoder = options.transcoder
    res.encoded = resp.specs.each_with_index.map do |s, idx|
      Couchbase::Collection::SubDocumentField.new do |f|
        # TODO: What to do with the status?
        error = s.status.nil? ? nil : ErrorHandling.convert_rpc_status(s.status, request)
        f.error = error unless error.nil?
        f.index = idx
        f.path = specs[idx].path
        if specs[idx].type == :exists
          f.exists = s.content == "true"
          f.value = s.content
        elsif s.content.empty?
          f.value = nil
          f.exists = false
        else
          f.value = s.content
          f.exists = true
        end
      end
    end
  end
end

.to_mutate_in_result(resp, specs, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 105

def self.to_mutate_in_result(resp, specs, options)
  Couchbase::Collection::MutateInResult.new do |res|
    res.cas = resp.cas
    res.transcoder = options.transcoder
    res.deleted = nil # TODO: gRPC response has no deleted field
    res.mutation_token = extract_mutation_token(resp)
    res.encoded = resp.specs.each_with_index.map do |s, idx|
      Couchbase::Collection::SubDocumentField.new do |f|
        f.index = idx
        f.path = specs[idx].path
        f.value = s.content
      end
    end
  end
end

.to_mutation_result(resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
# File 'lib/couchbase/protostellar/response_converter/kv.rb', line 38

def self.to_mutation_result(resp)
  Couchbase::Collection::MutationResult.new do |res|
    res.cas = resp.cas
    res.mutation_token = extract_mutation_token(resp)
  end
end